/* Kanji Duel — components. Depends on tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--paper);
  background-image: var(--grain);
  background-size: 256px;
  background-blend-mode: multiply;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: var(--leading-body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--ink); color: var(--paper); }
:focus-visible { outline: var(--rule) solid var(--shu); outline-offset: 3px; }
a { color: inherit; text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

/* ---------- Page frame ---------- */
.page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr minmax(0, var(--column)) 1fr;
  padding: var(--s-4) var(--s-5) var(--s-5);
}
.screen {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--s-4) - var(--s-5));
}
/* Vertical title in the margin: desktop only. */
.margin-title {
  display: none;
  grid-column: 1;
  justify-self: end;
  align-self: start;
  margin-right: var(--s-8);
  writing-mode: vertical-rl;
  font-family: var(--font-kanji);
  font-weight: 800;
  font-size: var(--step-3);
  letter-spacing: 0.35em;
  color: var(--ink);
}
.margin-title small {
  display: block;
  margin-top: var(--s-5);
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: var(--step--1);
  letter-spacing: var(--track-label);
  color: var(--ink-soft);
}
@media (min-width: 900px) {
  .page { padding-top: var(--s-7); }
  .margin-title { display: block; }
  .screen { min-height: calc(100dvh - var(--s-7) - var(--s-5)); }
  :root { --word: var(--word-desktop); }
}

/* ---------- Text ---------- */
.label {
  font-size: var(--step--1);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-soft);
}
.meta { font-size: var(--step--1); color: var(--ink-soft); }
.title {
  font-family: var(--font-kanji);
  font-weight: 800;
  font-size: var(--step-3);
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}
.rule { border: 0; border-top: var(--hair) solid var(--ink-faint); margin: 0; }

/* ---------- Buttons: ink blocks and underlined text ---------- */
.btn {
  appearance: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  width: 100%;
  padding: var(--s-4) var(--s-5);
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font: 700 var(--step-1)/1.2 var(--font-ui);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn small { font-weight: 400; font-size: var(--step--1); opacity: 0.75; }
.btn:hover { background: #000; }
.btn:active { transform: translateY(1px); }
.btn--line { background: transparent; color: var(--ink); }
.btn--line:hover { background: var(--paper-deep); }
.btn[disabled] { border-color: var(--ink-faint); background: transparent; color: var(--ink-soft); cursor: not-allowed; }
.btn[disabled] small { opacity: 1; }
/* Back, Cancel and every quiet action: small underlined text. The negative margin
   keeps a finger-sized hit area without moving the layout. */
.link-btn {
  appearance: none; border: 0; background: none; padding: var(--s-2) 0; margin: calc(-1 * var(--s-2)) 0;
  font: 400 var(--step--1)/1.4 var(--font-ui); color: var(--ink-soft);
  text-decoration: underline; text-underline-offset: 0.25em; text-decoration-thickness: 1px;
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); text-decoration-thickness: 2px; }

/* ---------- Wordmark seal ---------- */
.seal {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 3rem; height: 3rem;
  padding: 0.28rem;
  border-radius: 3px;
  background: var(--shu);
  color: var(--paper);
  font: 800 1.15rem/1.05 var(--font-kanji);
  text-align: center;
  -webkit-mask: var(--wear) center / 200px;
  mask: var(--wear) center / 200px;
  rotate: -3deg;
}
.seal span { display: grid; place-items: center; }

/* ---------- Duel header: two players ---------- */
.duel-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: var(--s-3);
}
.player { min-width: 0; }
.player--them { text-align: right; }
.player__name { font-weight: 700; font-size: var(--step-0); line-height: 1.3; overflow-wrap: anywhere; }
.player__elo { font-size: var(--step--1); color: var(--ink-soft); }
.player__state { font-size: var(--step--1); color: var(--ink-soft); min-height: 1.4em; }
.player__state::before {
  content: ""; display: inline-block; width: 0.5em; height: 0.5em; margin-right: 0.4em;
  border-radius: 50%; background: var(--ink-faint); vertical-align: 0.05em;
}
.player__state.is-answering::before { background: var(--ink); animation: breathe 1.4s ease-in-out infinite; }
.player__state.is-locked { color: var(--ink-soft); text-decoration: line-through; text-decoration-color: var(--shu); }
.player__state.is-locked::before { background: var(--shu); border-radius: 0; }
.tag-ai {
  display: inline-block; margin-left: 0.35em; padding: 0 0.35em;
  border: var(--hair) solid currentColor; border-radius: var(--radius);
  font-size: 0.6875rem; font-weight: 700; letter-spacing: var(--track-label); vertical-align: 0.15em;
}
@keyframes breathe { 50% { opacity: 0.25; } }

/* Score in the middle: big numerals + seven round ticks. */
.score { text-align: center; }
.score__nums { font: 800 var(--step-2)/1 var(--font-kanji); letter-spacing: 0.04em; }
.score__nums i { font-style: normal; color: var(--ink-faint); padding: 0 0.15em; }
.rounds { display: flex; gap: 4px; justify-content: center; margin-top: var(--s-2); }
.rounds b {
  width: 8px; height: 8px; border: var(--hair) solid var(--ink-faint); border-radius: 1px;
}
.rounds b.me   { background: var(--ink); border-color: var(--ink); }
.rounds b.them { background: transparent; border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 8px var(--ink-faint); }
.rounds b.draw { border-style: dashed; }
.rounds b.now  { border: var(--rule) solid var(--ink); }

/* ---------- The word, on kanji practice paper ---------- */
.word-stage { flex: 1; display: grid; place-content: center; justify-items: center; gap: var(--s-4); padding: var(--s-6) 0; }
.word {
  display: flex;
  font-family: var(--font-kanji);
  font-weight: 800;
  font-size: var(--word);
  line-height: 1;
  /* a soft ink spread on the strokes */
  text-shadow: 0 0 1px rgb(27 23 18 / 0.35);
}
.cell {
  position: relative;
  display: grid; place-items: center;
  width: 1.12em; height: 1.12em;
  border: var(--hair) solid var(--paper-edge);
  margin-left: calc(var(--hair) * -1);
  background:
    linear-gradient(var(--paper-edge), var(--paper-edge)) center / 100% 1px no-repeat,
    linear-gradient(var(--paper-edge), var(--paper-edge)) center / 1px 100% no-repeat;
}
.cell--ghost { color: var(--ink-ghost); text-shadow: none; }
/* Marked kanji: a red bōten dot at the top of the cell, like Japanese emphasis marks. */
.cell--marked::before {
  content: ""; position: absolute; top: -0.13em; left: 50%;
  width: 0.085em; height: 0.085em; translate: -50% 0;
  border-radius: 50%; background: var(--shu);
}
/* Whole-word special reading: a red bracket under all the cells. */
.word--whole { position: relative; }
.word--whole::after {
  content: ""; position: absolute; left: 0.06em; right: 0.06em; bottom: -0.18em; height: 0.07em;
  border: 0.035em solid var(--shu); border-top: 0;
}
.word-hint { font-size: var(--step--1); color: var(--ink-soft); letter-spacing: 0.02em; text-align: center; }
.word-hint b { color: var(--ink); font-family: var(--font-kanji); font-size: 1.15em; }

/* ---------- Timer: a hairline that drains, seconds at the end ---------- */
.timer { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s-3); }
.timer__track { height: 3px; background: var(--paper-edge); overflow: hidden; }
.timer__fill { height: 100%; background: var(--ink); transform-origin: left; transform: scaleX(var(--left, 1)); }
.timer__secs { font: 800 var(--step-1)/1 var(--font-kanji); min-width: 2ch; text-align: right; }
.timer.is-late .timer__fill { background: var(--shu); }
.timer.is-late .timer__secs { color: var(--shu); }

/* ---------- Answer input: written on a line ---------- */
.answer { display: grid; gap: var(--s-2); padding-bottom: var(--s-2); }
.answer__field {
  width: 100%;
  padding: var(--s-3) var(--s-2) var(--s-2);
  border: 0; border-bottom: var(--rule) solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 500 var(--step-2)/1.2 var(--font-kanji);
  text-align: center;
  caret-color: var(--shu);
}
.answer__field::placeholder { color: var(--ink-faint); font-family: var(--font-ui); font-size: var(--step-0); }
.answer__field:focus { outline: none; background: rgb(231 220 198 / 0.5); }
.answer__row { display: flex; justify-content: space-between; align-items: baseline; }
.answer__raw { font-size: var(--step--1); color: var(--ink-soft); }
.answer__field[disabled] { color: var(--ink-faint); border-bottom-color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--shu); }

/* ---------- Hanko stamp: the one authored moment ---------- */
.stamp {
  display: grid; place-items: center;
  width: 7.5rem; height: 7.5rem;
  border: 0.32rem solid var(--shu);
  border-radius: 0.6rem;
  color: var(--shu);
  font: 800 4.6rem/1 var(--font-kanji);
  -webkit-mask: var(--wear) center / 240px;
  mask: var(--wear) center / 240px;
  rotate: -7deg;
  mix-blend-mode: multiply;
}
.stamp--solid { background: var(--shu); color: var(--paper); mix-blend-mode: normal; }
.stamp--ink { border-color: var(--ink); color: var(--ink); }
.stamp.is-pressing { animation: press var(--dur-stamp) var(--ease-stamp) both; }
@keyframes press {
  0%   { opacity: 0; scale: 1.9; filter: blur(3px); }
  55%  { opacity: 1; scale: 0.94; filter: blur(0); }
  100% { opacity: 1; scale: 1; }
}
@media (prefers-reduced-motion: reduce) { .stamp.is-pressing { animation: none; } }

/* ---------- Forms ---------- */
.field { display: grid; gap: var(--s-1); }
.field label { font-size: var(--step--1); color: var(--ink-soft); }
.field input, .field textarea {
  width: 100%; padding: var(--s-3) var(--s-3);
  border: var(--hair) solid var(--ink); border-radius: var(--radius);
  background: rgb(255 252 245 / 0.55);
  color: var(--ink); font: 400 var(--step-1)/1.3 var(--font-ui);
  caret-color: var(--shu);
}
.field textarea { resize: vertical; min-height: 7rem; font-size: var(--step-0); line-height: 1.45; }
.field input:focus, .field textarea:focus { outline: var(--rule) solid var(--ink); outline-offset: 0; }
.field .meta { margin: 0; }

/* ---------- Utilities ---------- */
.stack { display: flex; flex-direction: column; }
.gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); } .gap-5 { gap: var(--s-5); } .gap-6 { gap: var(--s-6); }
.push { margin-top: auto; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
