/* ── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #f8f9fa;
  color: #222;
  -webkit-font-smoothing: antialiased;
}

ul {
  list-style: none;
}

button {
  font-family: inherit;
}

/* ── Layout ──────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  background: #f8f9fa;
  font-family: 'Inter', system-ui, sans-serif;
}

#sidebar {
  width: 260px;
  min-width: 220px;
  background: #ffffff;
  border-right: 1px solid #e0e0e0;
  padding: 24px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 32px;
}

/* ── Logo ────────────────────────────────────────────────── */
.logo-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

/* ── Typography ──────────────────────────────────────────── */
#sidebar h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: #111;
}

#sidebar h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 8px;
}

/* ── Preset Buttons ──────────────────────────────────────── */
#preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1.5px solid #d0d0d0;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  border-color: #aaa;
  background: #fafafa;
}

.preset-btn.active {
  border-color: var(--btn-color);
  background: var(--btn-color);
  color: #fff;
}

.preset-btn.active:hover {
  opacity: 0.9;
}

/* ── Custom Input ────────────────────────────────────────── */
.input-row {
  display: flex;
  gap: 6px;
}

#custom-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1.5px solid #d0d0d0;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

#custom-input:focus {
  border-color: #4C72B0;
}

#add-custom-btn {
  padding: 6px 14px;
  border: 1.5px solid #4C72B0;
  border-radius: 6px;
  background: #4C72B0;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

#add-custom-btn:hover {
  opacity: 0.85;
}

/* ── Disabled Section ────────────────────────────────────── */
.disabled-section {
  opacity: 0.4;
  pointer-events: none;
}

/* ── Fit Mode Toggle ─────────────────────────────────────── */
.toggle-group {
  display: flex;
  gap: 0;
  border: 1.5px solid #d0d0d0;
  border-radius: 6px;
  overflow: hidden;
}

.toggle-btn {
  flex: 1;
  padding: 6px 12px;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  transition: all 0.15s ease;
}

.toggle-btn:not(:last-child) {
  border-right: 1.5px solid #d0d0d0;
}

.toggle-btn.active {
  background: #4C72B0;
  color: #fff;
}

.toggle-btn:hover:not(.active) {
  background: #fafafa;
}

/* ── Active Ratio List ───────────────────────────────────── */
#active-list {
  display: flex;
  flex-direction: column;
}

#active-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}

.color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.ratio-label {
  flex: 1;
  min-width: 0;
}

.main-btn {
  background: none;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  cursor: pointer;
  color: #aaa;
  font-size: 11px;
  font-family: inherit;
  padding: 2px 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.main-btn:hover {
  border-color: #888;
  color: #555;
}

.main-btn.active {
  background: #4C72B0;
  border-color: #4C72B0;
  color: #fff;
}

#active-list li.main-ratio {
  background: #f0f4fa;
  border-radius: 4px;
  padding: 6px 6px;
  margin: 0 -6px;
}

.remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s ease;
  flex-shrink: 0;
}

.remove-btn:hover {
  color: #e04040;
}

/* ── Share Button ────────────────────────────────────────── */
#share-btn {
  margin-top: auto;
  padding: 10px 16px;
  border: 1.5px solid #d0d0d0;
  border-radius: 6px;
  background: #fff;
  color: #333;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

#share-btn:hover {
  border-color: #aaa;
  background: #fafafa;
}

/* ── Canvas ──────────────────────────────────────────────── */
#ratio-canvas {
  max-width: 100%;
  max-height: 100%;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}

/* ── Tooltip ─────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 100;
  max-width: 200px;
  white-space: nowrap;
}

#tooltip.hidden {
  display: none;
}

/* ── Mobile Responsive ───────────────────────────────────── */
@media (max-width: 640px) {
  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
    padding: 16px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    overflow-x: auto;
  }

  #sidebar h1 {
    width: 100%;
    font-size: 18px;
  }

  #sidebar h2 {
    width: 100%;
    margin-bottom: 4px;
  }

  .preset-section,
  .custom-section,
  .grid-section,
  .fitmode-section,
  .active-section {
    width: 100%;
  }

  #main {
    flex: 1;
    padding: 16px;
    min-height: 50vh;
  }

  #share-btn {
    margin-top: 0;
  }
}
