/* Base layout + components.
   Visual language: neobrutalist — 2px black border + hard offset shadow.
   Tokens are imported (NOT relied on HTML link order) so bundlers and the
   browser both see the dependency explicitly. */

@import "./tokens.css";

/* Korean web font — self-hosted subset of Seoul Namsan (Seoul's official
   wayfinding typeface). Single Medium master declared across 400–900 so our
   bold (900) elements use it directly with NO synthetic bolding. */
@font-face {
  font-family: "Seoul Namsan";
  src: url("/fonts/seoul-namsan.subset.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--rm-canvas);
  color: var(--rm-black);
  font-family: var(--rm-font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--rm-canvas);
}

.app {
  max-width: 720px;
  min-height: 100vh;
  min-height: 100dvh;   /* so the footer can sit at the bottom on short pages */
  margin: 0 auto;
  padding: 20px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ───── Branding ───── */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.brand__mark {
  font-family: var(--rm-font-ko);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--rm-black);   /* 읽기 inherits black */
}
.brand__mark .t-han { color: var(--rm-flag-red); }      /* 한 — red */
.brand__mark .t-geul { color: var(--rm-secondary-50); } /* 글 — blue */
.brand__dot {
  width: 12px;
  height: 12px;
  background: var(--rm-primary-50);
  border: 2px solid var(--rm-black);
  border-radius: 50%;
  display: inline-block;
}
.brand__tag {
  font-size: 12px;
  font-weight: 500;
  color: var(--rm-black-60);
}
.brand__tag--end { margin-left: auto; }
.brand__link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

/* Language selector (rendered by main.js; shown only when >1 locale is built) */
.lang-switch { margin-left: auto; }
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--rm-black);
  background: var(--rm-white);
  border: 2px solid var(--rm-black);
  border-radius: var(--rm-radius-full);
  padding: 5px 12px;
  cursor: pointer;
  box-shadow: var(--rm-shadow-sm);
}

/* ───── Panels ───── */
.panel {
  background: var(--rm-white);
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius);
  box-shadow: var(--rm-shadow);
  padding: 22px;
}

.panel--canvas {
  /* Lighter, no shadow — used when grouping items inside another shadowed surface. */
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

/* ───── King Sejong e-book card (issue #25) ───── */
.ebook {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}
.ebook__shot {
  display: block;
  width: 100%;
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius-sm);
  box-shadow: var(--rm-shadow-sm);
  overflow: hidden;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.ebook__shot:hover { transform: translate(-1px, -1px); }
.ebook__shot:active { transform: translate(-1px, 2px); box-shadow: var(--rm-shadow-active); }
.ebook__shot:focus-visible { outline: 3px solid var(--rm-primary-50); outline-offset: 2px; }
/* Wide screenshot — scale to the card width, never overflow on mobile. */
.ebook__img {
  display: block;
  width: 100%;
  height: auto;
}
.ebook__desc {
  margin: 0;
  color: var(--rm-black);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 500;
}
.ebook__langs {
  margin: 0;
  color: var(--rm-black-60);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 500;
}
.ebook__langs-label {
  display: block;
  font-weight: 700;
  color: var(--rm-black);
  margin-bottom: 2px;
}

/* ───── Typography ───── */
.title {
  font-size: clamp(26px, 6vw, 32px);
  font-weight: 900;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin: 0 0 12px;
  color: var(--rm-black);
}
.subtitle {
  margin: 0;
  color: var(--rm-black-60);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 500;
}
.subtitle + .subtitle { margin-top: 12px; }
.section-label {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rm-black-60);
  margin: 0 0 10px;
}
.section-hint {
  margin: 0 0 14px;
  color: var(--rm-black-60);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 500;
}

/* ───── Buttons ───── */
.btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  font-size: 16px;
  line-height: 24px;
  color: var(--rm-black);
  background: var(--rm-primary-50);
  border: var(--rm-border-w) solid var(--rm-black);
  padding: 8px 16px;
  border-radius: var(--rm-radius);
  box-shadow: var(--rm-shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { transform: translate(-1px, -1px); }
.btn:active {
  transform: translate(-2px, 4px);
  box-shadow: var(--rm-shadow-active);
}
.btn--primary {
  background: var(--rm-primary-50);
  color: var(--rm-black);
}
.btn--secondary {
  background: var(--rm-secondary-50);
  color: var(--rm-white);
}
.btn--block { width: 100%; }
.btn--ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--rm-black-60);
  font-weight: 700;
}
.btn--ghost:hover { transform: none; color: var(--rm-black); }
.btn--ghost:active { transform: none; box-shadow: none; }
.btn--icon {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 22px;
  font-weight: 900;
  border-radius: 50%;
}

/* ───── Category grid ───── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.cat {
  background: var(--rm-white);
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius);
  box-shadow: var(--rm-shadow);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: var(--rm-black);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}
.cat:hover { transform: translate(-1px, -1px); background: var(--rm-primary-10); }
.cat:active {
  transform: translate(-2px, 4px);
  box-shadow: var(--rm-shadow-active);
}
.cat[aria-selected="true"] {
  background: var(--rm-primary-50);
}
.cat__icon {
  display: grid;
  place-items: center;
  font-size: 30px;       /* emoji fallback if icon name is unknown */
  line-height: 1;
  margin-bottom: 6px;
  color: var(--rm-black);
}
.cat__icon .icon {
  width: 28px;
  height: 28px;
  stroke-width: 2.25;
}
.cat__label {
  font-weight: 900;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.cat__count {
  font-size: 12px;
  font-weight: 500;
  color: var(--rm-black-60);
  margin-top: 2px;
}

/* ───── Word list (tag) page ───── */
/* Every word in a category as a tappable tag. Hangul-only by design (the list
   is a reading-practice index, not translated); page chrome around it is
   localized. Each tag deep-links into the deck at that word. */
/* Column of tag-grid chunks with inline ad slots interleaved between them. */
.tag-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}
.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag {
  display: inline-flex;
  align-items: center;
  font-family: var(--rm-font-ko);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: var(--rm-black);
  text-decoration: none;
  background: var(--rm-white);
  border: 2px solid var(--rm-black);
  border-radius: var(--rm-radius-full);
  box-shadow: var(--rm-shadow-sm);
  padding: 6px 14px;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}
.tag:hover { transform: translate(-1px, -1px); background: var(--rm-primary-10); }
.tag:active { transform: translate(-1px, 2px); box-shadow: var(--rm-shadow-active); }
.tag:focus-visible { outline: 3px solid var(--rm-primary-50); outline-offset: 2px; }

/* ───── Flashcard deck ───── */
.deck {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.deck__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}
/* The progress counter doubles as the link into the list (tag) view. Styled as
   a soft chip with a grid icon so it reads as tappable even without hover. */
.deck__progress {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--rm-black-60);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  cursor: pointer;
  padding: 4px 12px;
  background: var(--rm-primary-10);
  border-radius: var(--rm-radius-full);
  transition: transform 0.08s ease, background 0.08s ease;
}
.deck__progress:hover { background: var(--rm-primary-50); color: var(--rm-black); transform: translate(-1px, -1px); }
.deck__progress:active { transform: translate(-1px, 2px); }
.deck__progress:focus-visible { outline: 3px solid var(--rm-primary-50); outline-offset: 3px; }
.deck__progress .icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.25;
  color: var(--rm-primary-90);
}
.deck__progress strong {
  color: var(--rm-black);
  font-weight: 900;
}

.card {
  background: var(--rm-white);
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius);
  box-shadow: var(--rm-shadow);
  padding: 22px;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.card:active {
  transform: translate(-2px, 4px);
  box-shadow: var(--rm-shadow-active);
}

/* Top bar (category chip + image-search): hidden on the FRONT so the category
   can't prime the reader; shown on the back once the answer is revealed. */
.card__topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card.is-flipped .card__topbar { display: flex; }

.card__cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  background: var(--rm-primary-10);
  color: var(--rm-primary-90);
  border-radius: var(--rm-radius-full);
}
.card__cat .icon {
  width: 14px;
  height: 14px;
  stroke-width: 2.25;
}

/* Image-search button (top-right of the back) — opens Google Images in a new
   tab for the Korean "<category> <sign>" query. */
.card__imgsearch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  color: var(--rm-black);
  background: var(--rm-white);
  border: 2px solid var(--rm-black);
  border-radius: var(--rm-radius-full);
  box-shadow: var(--rm-shadow-sm);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.card__imgsearch:hover { transform: translate(-1px, -1px); }
.card__imgsearch:active { transform: translate(-1px, 2px); box-shadow: var(--rm-shadow-active); }
.card__imgsearch .icon { width: 14px; height: 14px; stroke-width: 2.25; }

.card__sign-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px 0;
  /* Container for the sign's length-aware font scaling (see .sign in
     signs.css; --sign-len is set per item in flashcard.js). */
  container-type: inline-size;
}

.card__hint {
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--rm-black-60);
}

/* Flip: hide the sign (its blocks now live in the pronunciation boxes) and
   the prompt; show the answer, vertically centered in the freed space. */
.card__back { display: none; flex-direction: column; }
/* Flip layout: description pinned to the bottom; pronunciation boxes fill the
   space above and center within it. */
.card.is-flipped .card__back { display: flex; flex: 1; }
.card.is-flipped .pairs { flex: 1; align-items: center; }
.card.is-flipped .card__hint { display: none; }
.card.is-flipped .card__sign-wrap { display: none; }

/* Pronunciation playback (issue #23) — back only, sits between the syllable
   boxes and the meaning panel. A yellow RetroMorphism button + a muted one-line
   note describing the clip (normal → slow → normal). `hidden` when a card has
   no generated audio yet (set in flashcard.js). */
.card__audio {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}
.card__audio[hidden] { display: none; }
.card__audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  color: var(--rm-black);
  background: var(--rm-primary-50);
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius-full);
  box-shadow: var(--rm-shadow-sm);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.card__audio-btn:hover { transform: translate(-1px, -1px); }
.card__audio-btn:active {
  transform: translate(-1px, 2px);
  box-shadow: var(--rm-shadow-active);
}
.card__audio-btn .icon { width: 15px; height: 15px; stroke-width: 2.25; }
/* Pulse the speaker icon while the clip plays. */
.card__audio-btn.is-playing .icon { animation: audio-pulse 0.7s ease-in-out infinite; }
@keyframes audio-pulse { 50% { opacity: 0.4; } }
.card__audio-hint {
  font-size: 12px;
  font-weight: 600;
  color: var(--rm-black-60);
  white-space: nowrap;
}

/* Description region — a pale-yellow panel that separates "what it means"
   from the white pronunciation boxes above it. */
.card__desc {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--rm-primary-10);
  border-radius: var(--rm-radius);
}

/* Pronunciation boxes — always one line. Each box shares the row equally and
   shrinks with the syllable count (--n, set in flashcard.js); fonts scale via
   container-query units so more syllables → smaller boxes, never wrapping. */
.pairs {
  container-type: inline-size;
  display: flex;
  flex-wrap: nowrap;
  gap: 2cqw;
  justify-content: center;
  width: 100%;
}
/* One block, one syllable: Hangul on top, English pronunciation beneath. */
.pair {
  flex: 1 1 0;
  min-width: 0;
  max-width: 84px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 6px;
  background: var(--rm-white);
  border: var(--rm-border-w) solid var(--rm-black);
  border-radius: var(--rm-radius-sm);
  box-shadow: var(--rm-shadow-sm);
}
.pair__han {
  font-family: var(--rm-font-ko);
  font-size: clamp(15px, calc(46cqw / var(--n, 3)), 24px);
  font-weight: 900;
  line-height: 1;
  color: var(--rm-black);
}
.pair__rom {
  font-size: clamp(10px, calc(30cqw / var(--n, 3)), 13px);
  font-weight: 700;
  line-height: 1.1;
  color: var(--rm-secondary-50);
  white-space: nowrap;
}

.meaning {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.015em;
  text-align: center;
  margin: 0;
  color: var(--rm-black);
}
.context {
  font-size: 14px;
  font-weight: 500;
  color: var(--rm-black-60);
  text-align: center;
  margin: 0;
  line-height: 1.5;
}

.deck__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ───── Prose (privacy / static text pages) ───── */
.prose { color: var(--rm-black); }
.prose .title { margin-bottom: 4px; }
.prose__meta {
  margin: 0 0 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--rm-black-60);
}
.prose h2 {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.01em;
  margin: 22px 0 6px;
}
.prose p {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--rm-black);
}
.prose a { color: var(--rm-secondary-50); text-underline-offset: 2px; }

/* ───── Ad slot ───── */
/* One reserved slot per page, below the content (outside the card / nav).
   Loaded once per page view — never refreshed per card (AdSense policy).
   The slot reserves its height to prevent layout shift but renders NO visible
   placeholder UI (no border/label) — it stays empty until the AdSense unit is
   dropped in. */
.ad-slot {
  width: 100%;
  max-width: 728px;
  margin: 4px auto 0;
  min-height: 100px;            /* mobile: ~320x100 banner */
}
/* Ad slots interleaved within the word list — full width of the list column,
   no extra top margin (the .tag-list gap already spaces them). */
.ad-slot--inline { margin: 0 auto; }

/* ───── Footer ───── */
.site-footer {
  margin-top: auto;            /* push to the bottom of .app */
  padding-top: 16px;
  border-top: 1px solid var(--rm-black-10);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--rm-black-60);
}
.site-footer a {
  color: var(--rm-black-60);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer a:hover { color: var(--rm-black); }
.site-footer__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ───── Breakpoints — single layout, gentle scale ───── */
@media (min-width: 640px) {
  .app { padding: 32px 24px 100px; gap: 26px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
  .card { min-height: 420px; padding: 28px; }
  .ad-slot { min-height: 90px; }   /* desktop: ~728x90 leaderboard */
}
@media (min-width: 960px) {
  .app { max-width: 820px; }
  .card { min-height: 460px; }
}

/* Focus ring */
.btn:focus-visible,
.cat:focus-visible,
.card:focus-visible {
  outline: 3px solid var(--rm-primary-50);
  outline-offset: 3px;
}
