/* ── Design tokens ───────────────────────────
   Dark = the original theme (navy/blue).
   Light = blush (tone-on-tone pink).
   Default follows the OS; the header slide-toggle overrides it. */
:root {
  --bg: #0d0f13;
  --surface: #232834;
  --surface-hover: #2c333f;
  --border: #3a4150;
  --text: #f2f4f8;
  --text-dim: #aeb4c0;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.18);
  --on-accent: #ffffff;
  --ok: #3ddc84;
  --radius: 12px;
  --radius-card: 6px; /* char cards — deliberately sharp */
}

/* Light (blush) — explicit toggle wins */
:root[data-theme="light"] {
  --bg: #fff4f8;
  --surface: #ffe7f0;
  --surface-hover: #fbd8e6;
  --border: #f4c6d9;
  --text: #3c1222;
  --text-dim: #8a4a63;
  --accent: #d6297a;
  --accent-soft: #fbd8e6;
  --on-accent: #ffffff;
}

/* Follow the OS when the user hasn't forced a theme */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fff4f8;
    --surface: #ffe7f0;
    --surface-hover: #fbd8e6;
    --border: #f4c6d9;
    --text: #3c1222;
    --text-dim: #8a4a63;
    --accent: #d6297a;
    --accent-soft: #fbd8e6;
    --on-accent: #ffffff;
  }
}

@font-face {
  font-family: "Samliphopang";
  src: url("assets/samliphopang-logo.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

* { box-sizing: border-box; }

/* Reserve the scrollbar gutter so the content width stays constant whether
   or not the page scrolls — keeps the card grid the same size across the
   long "전체" view and short filtered views. */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Top bar: logo (+ theme toggle) left, search right ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  margin: 0;
  font-family: "Samliphopang", -apple-system, "Apple SD Gothic Neo", sans-serif;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text);
  white-space: nowrap;
}

/* ── Theme slide toggle (left = dark, right = light) ── */
.theme-switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.theme-switch:hover { border-color: var(--accent); }
.theme-switch__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  border-radius: 999px;
  background: var(--accent);
  transition: transform 0.2s ease;
}
.theme-switch.is-light .theme-switch__knob { transform: translateX(20px); }

/* ── Search: compact, expands on focus (original) ── */
.search-wrap { position: relative; }

.search-box {
  width: 150px;
  padding: 9px 14px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  transition: width 0.25s ease, border-color 0.15s, box-shadow 0.15s;
}
.search-box:focus {
  width: 320px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box::placeholder { color: var(--text-dim); }

@media (max-width: 560px) {
  .search-box { width: 40px; padding: 9px 0; text-align: center; }
  .search-box:focus { width: 200px; padding: 9px 14px; text-align: left; }
}

/* Hint dropdown — only when wrap is focused-within */
.search-hint {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 320px;
  max-width: 80vw;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.search-wrap:focus-within .search-hint {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.hint-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.hint-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.hint-chip {
  padding: 5px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.hint-chip:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ── Category chips: single row, horizontal scroll (pills) ── */
.category-tabs {
  position: sticky;
  top: 60px;
  z-index: 10;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
}
.category-tabs::-webkit-scrollbar { height: 6px; }
.category-tabs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.tab {
  flex: none;
  padding: 6px 13px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { background: var(--surface-hover); color: var(--text); }
.tab.active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* ── Usage caption + pin hint ───────────── */
.copy-hint,
.pin-hint {
  max-width: 1040px;
  margin: 6px auto 0;
  padding: 0 20px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}
.copy-hint b,
.pin-hint b { color: var(--text); font-weight: 600; }

/* ── Content ────────────────────────────── */
main { max-width: 1040px; margin: 0 auto; padding: 4px 20px 80px; }

.recommend-section {
  max-width: 1040px;
  margin: 0 auto;
  padding: 4px 20px 0;
}

/* Section header: pin button + title */
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 10px;
}
.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.recommend-section .section-title { margin: 16px 0 10px; }

/* Pin button (left of a section title) */
.pin-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.pin-btn:hover { opacity: 1; background: var(--accent-soft); }
.pin-btn.active { opacity: 1; color: var(--accent); }
.pin-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* Tighter grid */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}

/* ── Character card (sharp corners, no shadow) ── */
.char-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.1s, border-color 0.15s;
}
.char-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.char-card:active { transform: translateY(0); }

/* Big, bright glyph */
.char-card .glyph {
  font-size: 38px;
  line-height: 1;
  color: var(--text);
  transition: opacity 0.15s, filter 0.15s;
}
.char-card:hover .glyph {
  opacity: 0.18;
  filter: blur(1px);
}

/* Name overlay — hidden until hover (PROTECTED interaction) */
.name-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.char-card:hover .name-overlay { opacity: 1; }
.name-overlay .name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  word-break: keep-all;
}
.name-overlay .code {
  font-size: 10px;
  color: var(--text-dim);
}

/* ── Copy feedback: check overlay ───────── */
.check-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}
.char-card.copied .check-overlay { animation: pop 0.7s ease forwards; }
.check-overlay svg {
  width: 24px;
  height: 24px;
  stroke: var(--ok);
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes pop {
  0%   { opacity: 0; transform: scale(0.6); }
  25%  { opacity: 1; transform: scale(1); }
  70%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

/* ── Empty state ────────────────────────── */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 15px;
}

/* ── Mobile layout ──────────────────────── */
@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .logo { font-size: 20px; }

  .category-tabs { top: 56px; padding: 8px 14px; gap: 6px; }
  main { padding: 4px 14px 64px; }
  .recommend-section { padding: 4px 14px 0; }
  .copy-hint, .pin-hint { font-size: 12px; padding: 0 14px; }

  .char-grid {
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: 6px;
  }
  .char-card .glyph { font-size: 30px; }
  .name-overlay .name { font-size: 11px; }
  .name-overlay .code { font-size: 9px; }
}

@media (max-width: 380px) {
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
  .char-card .glyph { font-size: 26px; }
}
