/* Type Hangeul content pages: /keyboard, /typing-test, /how-to-type-korean,
   /topik-typing. Layered on ui.css (tokens, pixel font, .rpg-* components),
   so these pages share the hanji paper and ink frames of the practice page.
   Hangul in running text uses .ko (Noto Sans KR): the pixel font only holds
   the syllables the app UI already uses. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--bg);
  /* Hanji paper, same two noise layers as index.html */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.22' numOctaves='3' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.55 0 0 0 0 0.45 0 0 0 0 0.28 0 0 0 0.9 -0.52'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.33 0 0 0 0 0.2 0 0 0 0.28 -0.1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 320px 320px, 160px 160px;
  color: var(--thi);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.75;
  min-height: 100vh;
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--gold-deep); }
.ko, [lang="ko"] { font-family: var(--korean); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--ink); color: var(--paper); padding: 8px 12px;
}
.skip-link:focus { top: 12px; color: var(--paper); }

.pg-wrap { max-width: 1040px; margin: 0 auto; padding: 24px 24px 48px; }

/* ── Header: brand + one row of links ─────────────────────────────── */
.pg-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-bottom: 14px; margin-bottom: 28px;
  border-bottom: 2px solid var(--ink);
  box-shadow: 0 3px 0 -1px var(--hanji-edge);
}
.pg-brand {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
  text-decoration: none; color: var(--ink);
  font-family: var(--font-display); font-size: 22px; line-height: 1;
}
.pg-brand img { width: 32px; height: 32px; box-shadow: 0 0 0 2px var(--ink); }
.pg-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.pg-nav a {
  display: inline-flex; align-items: center; min-height: 36px;
  padding: 4px 10px;
  font-size: 12px; font-weight: 700; text-decoration: none; color: var(--ink);
  border: 2px solid transparent;
}
.pg-nav a:hover { border-color: var(--ink); background: var(--paper); color: var(--ink); }
.pg-nav a[aria-current="page"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
@media (max-width: 720px) {
  .pg-wrap { padding: 14px 14px 40px; }
  .pg-header { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 20px; }
  .pg-brand { font-size: 18px; }
  .pg-nav {
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto;
    margin: 0 -14px; padding: 0 14px 2px; scrollbar-width: none;
  }
  .pg-nav::-webkit-scrollbar { display: none; }
  .pg-nav a { flex: 0 0 auto; min-height: 40px; }
}

/* ── Page hero and prose ──────────────────────────────────────────── */
.pg-hero { max-width: 720px; margin: 0 0 24px; }
.pg-kicker { margin: 0 0 6px; font-size: 12px; font-weight: 700; color: var(--seal); }
.pg-hero h1 {
  margin: 0 0 12px;
  font-family: var(--font-display); font-weight: 400;
  font-size: 36px; line-height: 1.15; letter-spacing: 0.01em;
}
.pg-lede { margin: 0; font-size: 14px; color: var(--tmd); max-width: 62ch; }
@media (max-width: 720px) {
  .pg-hero h1 { font-size: 26px; }
  .pg-lede { font-size: 13px; }
}

.prose { max-width: 66ch; color: var(--tmd); }
.prose h2, .pg-section > h2 {
  margin: 0 0 10px;
  font-family: var(--font-display); font-weight: 400;
  font-size: 22px; line-height: 1.25; color: var(--ink);
}
.prose h3 { margin: 22px 0 6px; font-size: 14px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 0 0 6px; }
.prose strong { color: var(--ink); }
.prose .ko { font-size: 1.08em; color: var(--ink); }

.pg-section { margin: 40px 0 0; }
.pg-panel { padding: 24px; }
@media (max-width: 720px) { .pg-panel { padding: 16px; } }

.pg-note {
  margin: 16px 0 0; padding: 10px 14px;
  border-left: 4px solid var(--ink); background: var(--l2);
  font-size: 12px; color: var(--tmd);
}

/* Call-to-action row */
.pg-cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }

/* Inline keycap: a drawn key for diagrams and running text */
.keycap {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 30px; min-height: 30px; padding: 2px 6px;
  vertical-align: middle;
  background: #fffdf8; border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.1; color: var(--ink);
}
.keycap .ko { font-size: 15px; line-height: 1.1; }
.keycap small { font-size: 10px; color: var(--tlo); font-family: var(--font-mono); }
.keycap--wide { min-width: 56px; }
.plus { margin: 0 4px; color: var(--tlo); }

/* Menu path: Settings › Time & language › ... */
.path { display: inline-flex; flex-wrap: wrap; gap: 4px 2px; align-items: center; }
.path span {
  padding: 1px 6px; border: 1px solid var(--bdhi); background: var(--paper);
  font-size: 12px; color: var(--ink); white-space: nowrap;
}
.path span + span::before { content: '›'; margin: 0 6px 0 -4px; color: var(--tlo); }
.path span + span { border-left-width: 1px; }

/* Footer: all pages */
.pg-footer {
  margin-top: 56px; padding-top: 16px;
  border-top: 2px solid var(--ink);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px;
  font-size: 12px; color: var(--tlo);
}
.pg-footer nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.pg-footer a { color: var(--tmd); }
.pg-footer a:hover { color: var(--gold-deep); }

/* ── 2-set keyboard (pages-kb.js) ─────────────────────────────────── */
.kb2 {
  --k: 52px; --gap: 6px;
  display: flex; flex-direction: column; align-items: center; gap: var(--gap);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.kb2-row { display: flex; gap: var(--gap); }
.kb2-row:nth-child(2) { margin-left: calc(var(--k) * 0.35); }
.kb2-row:nth-child(3) { margin-left: calc(var(--k) * 0.35); }
.kb2-key {
  position: relative;
  width: var(--k); height: calc(var(--k) * 1.1);
  padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #fffdf8; color: var(--ink);
  border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 0 3px 0 var(--ink);
  font: inherit; cursor: pointer;
  transition: transform 0.05s steps(1), box-shadow 0.05s steps(1);
}
/* Vowel keys (right hand) sit on a darker paper so the two halves read apart */
.kb2-key.is-vowel { background: var(--l3); }
.kb2-key .j { font-family: var(--korean); font-size: calc(var(--k) * 0.46); font-weight: 500; line-height: 1; }
.kb2-key .q { margin-top: 4px; font-family: var(--font-mono); font-size: 12px; line-height: 1; color: var(--tlo); }
.kb2-key .s {
  position: absolute; top: 2px; right: 4px;
  font-family: var(--korean); font-size: calc(var(--k) * 0.22); line-height: 1; color: var(--seal);
}
.kb2-key.is-fn { width: auto; flex: 1 1 auto; min-width: calc(var(--k) * 1.3); font-size: 12px; font-weight: 700; }
.kb2-key.is-space { width: calc(var(--k) * 5.5); font-size: 12px; font-weight: 700; }
.kb2-key.is-down,
.kb2-key:active {
  transform: translateY(2px); box-shadow: 0 1px 0 var(--ink);
  background: var(--ink); color: var(--paper);
}
.kb2-key.is-down .q, .kb2-key.is-down .s,
.kb2-key:active .q, .kb2-key:active .s { color: var(--gold-hi); }
.kb2-key.is-target { background: var(--gold); }
.kb2-key.is-miss { background: var(--seal); color: var(--paper); }
/* Shift layer: keys that change show their shifted jamo in the middle */
.kb2.shift-on .kb2-key.has-shift { background: var(--sakura); }
.kb2-key .j2 { display: none; }
.kb2.shift-on .kb2-key.has-shift .j:not(.j2) { display: none; }
.kb2.shift-on .kb2-key.has-shift .j2 { display: block; }
.kb2.shift-on .kb2-key.has-shift .s { visibility: hidden; }
.kb2.shift-on .kb2-key.is-shift { background: var(--ink); color: var(--paper); }
.kb2.shift-on .kb2-key:not(.has-shift):not(.is-fn):not(.is-space) .j { opacity: 0.45; }
@media (max-width: 720px) {
  /* Phones: keys share the row width instead of a fixed size */
  .kb2 { --gap: 4px; --k: 40px; align-items: stretch; width: 100%; }
  .kb2-row { width: 100%; margin-left: 0 !important; }
  .kb2-row:nth-child(2) { padding: 0 5%; }
  .kb2-key { flex: 1 1 0; width: auto; min-width: 0; height: 46px; box-shadow: 0 2px 0 var(--ink); border-width: 1.5px; }
  .kb2-key .j { font-size: 18px; }
  .kb2-key .s { font-size: 10px; right: 2px; }
  .kb2-key .q { font-size: 10px; margin-top: 2px; }
  .kb2-key.is-fn { flex: 1.4 1 0; min-width: 0; }
  .kb2-key.is-space { flex: 0 0 60%; width: auto; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .kb2-key { transition: none; }
}

/* Hidden capture input for an OS Korean IME (same trick as practice) */
.input-shield {
  position: fixed; top: 0; left: 0; width: 1px; height: 1px;
  opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0;
  caret-color: transparent;
}

/* Segmented choice (radio group) */
.seg { display: inline-flex; flex-wrap: wrap; gap: 0; border: 2px solid var(--ink); background: var(--paper); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 4px 14px;
  font-size: 12px; font-weight: 700; cursor: pointer;
}
.seg label + label span { border-left: 2px solid var(--ink); }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 2px solid var(--seal); outline-offset: -4px; }

/* Stat tiles */
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-tile {
  flex: 1 1 120px; padding: 12px 14px;
  background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow-hard);
}
.stat-tile .lbl { font-size: 12px; color: var(--tlo); line-height: 1.3; }
.stat-tile .val { font-family: var(--font-display); font-size: 36px; line-height: 1.1; color: var(--ink); }
.stat-tile .sub { font-size: 12px; color: var(--tmd); line-height: 1.3; }
.stat-tile.is-hero .val { color: var(--gold-deep); }

/* Print: only the element marked .print-only shows (keyboard cheat sheet) */
.print-only { display: none; }
@media print {
  @page { margin: 12mm; }
  html, body { background: #fff !important; }
  body > *:not(.print-only) { display: none !important; }
  .print-only { display: block !important; }
}
