/* 間 Ma concepts — shared mechanics only (layout plumbing, accessibility, welcome and greeting behaviour, the phone
   study bar, motion). Each concept's look (colour, type, spacing, tatami) is in c/<concept>.css. */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
main { width: 100%; outline: none; flex: 1 0 auto; }
img, svg { display: block; }
[hidden] { display: none !important; }
[lang="ko"] { word-break: keep-all; }
ruby { ruby-align: center; }
.skip { position: absolute; left: -999px; top: 0; padding: 8px 12px; z-index: 60; }
.skip:focus { left: 8px; top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
nav a { white-space: nowrap; }

/* Prototype concept switcher: a slim strip above the header */
.concepts { display: flex; align-items: center; justify-content: center; gap: 2px 4px; flex-wrap: wrap; position: relative; z-index: 6; }
.concepts a { white-space: nowrap; }
.concepts a[aria-current="page"] { pointer-events: none; }
@media (max-width: 520px) { .concepts-label { display: none; } }

/* Header */
.bar { position: sticky; top: 0; z-index: 5; }
.bar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; text-decoration: none; }
.bar-right { display: flex; align-items: center; }
nav[aria-label] { display: flex; }
.lang-switch { display: inline-flex; }
.lang-switch button { appearance: none; border: 0; cursor: pointer; }
.pill { display: inline-block; text-align: center; }

/* Level picker */
.levels { display: grid; grid-auto-rows: 1fr; }
.level { appearance: none; text-align: left; cursor: pointer; color: inherit; font: inherit; position: relative; }
.level[disabled] { cursor: not-allowed; }
.level-soon { cursor: default; }
.level-card, .level-name, .level-sub, .level-meter, .level-stats { display: block; }
.level-soon-tag { display: inline-block; }
.level-meter { overflow: hidden; }
.level-meter span { display: block; height: 100%; }

/* Study card */
.study-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.progress { margin: 0; }
.progress-track { overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; transition: width .3s ease; }
.card { position: relative; perspective: 1400px; }
.card-inner { display: flex; flex-direction: column; transform-origin: center; }
.card-inner.turn-out { animation: turnOut .16s ease-in forwards; }
.card-inner.turn-in { animation: turnIn .2s ease-out; }
@keyframes turnOut { to { transform: rotateY(88deg); opacity: .4; } }
@keyframes turnIn { from { transform: rotateY(-88deg); opacity: .4; } to { transform: none; opacity: 1; } }
.face-label { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tag { display: inline-flex; gap: 6px; align-items: center; }
.tag .dot { display: inline-block; flex: none; }
.target-word { text-align: center; }
.sentence { text-align: center; }
.helper { appearance: none; background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; }
.helper-hint { text-align: center; }
.recall { margin: auto 0 0; }
.recall input { display: block; width: 100%; margin: 0 auto; }
.answer { text-align: center; }
.text-btn { appearance: none; background: none; border: 0; font: inherit; cursor: pointer; }
.actions { display: flex; justify-content: center; flex-wrap: wrap; }
.btn { appearance: none; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
#flip-back svg { margin: 0 auto; }
.done { text-align: center; }

/* Helper popover */
.popover { position: absolute; z-index: 20; min-width: 180px; max-width: min(320px, calc(100vw - 24px)); }

/* Learned */
.tabs { display: flex; flex-wrap: wrap; }
.tab { appearance: none; font: inherit; cursor: pointer; }
.learned-list { list-style: none; padding: 0; margin: 0; display: grid; }
.learned-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.li-meta { min-width: 0; }
.li-actions { display: flex; gap: 2px; }
.learned-tools { display: flex; flex-wrap: wrap; }

/* About */
.stats-table { border-collapse: collapse; width: 100%; }
.stats-table th, .stats-table td { text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.table-wrap { overflow-x: auto; }

/* Footer */
.foot { flex: 0 0 auto; }

/* Phone: the study actions are a fixed bar within thumb reach */
@media (max-width: 640px) {
  #view-study .actions {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 6; flex-wrap: nowrap;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
  #view-study .actions .btn { flex: 1 1 0; white-space: nowrap; }
  #view-study .actions .btn.primary { flex-grow: 1.6; }
  #view-study .actions #flip-back { flex: 0 0 auto; }
  .kbd-hint { display: none; }
  .learned-item { grid-template-columns: auto 1fr; }
  .li-actions { grid-column: 1 / -1; justify-content: flex-end; }
  body[data-view="study"] .foot { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* Welcome: language first, then a short introduction. Centred in the viewport when it fits, otherwise from the top
   and scrollable (never clipped). */
.welcome-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center;
  padding: 20px 16px; overflow-y: auto; overscroll-behavior: contain; animation: welcomeIn .3s ease-out;
}
body.gated { overflow: hidden; }
.welcome-card { position: relative; width: min(480px, 100%); margin: auto; text-align: left; }
.welcome-close { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; display: grid; place-items: center; appearance: none; border: 0; cursor: pointer; }
.welcome-brand { margin: 0 48px 6px 0; }
.greeting { margin: 0 0 18px; }
.greeting-box { position: relative; display: grid; justify-items: start; height: 1.3em; line-height: 1.3em; }
.greeting-word { grid-area: 1 / 1; white-space: nowrap; visibility: hidden; }
.greeting-word.on { visibility: visible; }
.greeting .g { opacity: 0; transition: opacity .12s linear; }
.greeting .g.v { opacity: 1; }
.greeting-caret { position: absolute; left: 0; top: .2em; width: 2px; height: .92em; border-radius: 1px; margin-left: 2px; transition: transform .09s ease-out; }
.greeting-caret.blink { animation: caretBlink 1.1s steps(1) infinite; }
.greeting-box.still { height: auto; display: flex; flex-wrap: wrap; gap: 0 .4em; font-size: .64em; line-height: 1.45; }
@keyframes caretBlink { 55% { opacity: 0; } }
@keyframes welcomeIn { from { opacity: 0; } }
@keyframes stepIn { from { opacity: 0; transform: translateY(4px); } }
.welcome-step { animation: stepIn .22s ease-out; }
.welcome-ask { margin: 0 0 16px; display: grid; gap: 1px; }
.welcome-langs { display: flex; gap: 10px; }
.welcome-langs .btn { flex: 1 1 0; min-height: 52px; }
.welcome-steps { list-style: none; margin: 0; padding: 0; display: grid; }
.welcome-steps li { display: flex; align-items: flex-start; }
.welcome-steps strong, .welcome-steps span:not(.welcome-num) { display: block; }
.welcome-num { display: grid; place-items: center; flex: none; }
.welcome-start { width: 100%; }
.welcome-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-top: 12px; }
.welcome-hide { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 40px; }
.welcome-hide input { width: 17px; height: 17px; margin: 0; }
html[lang="ko"] .welcome-card { word-break: keep-all; }
html[lang="ko"] .intro p, html[lang="ko"] .prose p, html[lang="ko"] .prose li, html[lang="ko"] .helper-hint { word-break: keep-all; }

@media (prefers-reduced-motion: reduce) {
  .card-inner.turn-out, .card-inner.turn-in, .welcome-backdrop, .welcome-step { animation: none; }
  .greeting .g, .greeting-caret, .progress-track span { transition: none; }
  *, *::before, *::after { scroll-behavior: auto !important; }
}
