/*
 * Kanji Wars — styles.css
 * Arena styles. Phone first. One giant kanji.
 *
 * Built & maintained by T.S.T Technology
 * https://tsttechnology.com
 *
 * Created: 2026-09-04
 * Updated: 2026-09-18
 * Version: 7
 */

:root {
  --bg: #12100e;
  --fg: #f3eee4;
  --muted: #c4bdb0;
  --accent: #e8c36a;
  --accent-ink: #1a160e;
  --focus: #ffffff;
  --panel: #1c1915;
  --hit: #e8c36a;
  --cpu: #8ec5ff;
  --miss: #ffb4a8;
  --pip: #3a342c;
  --glyph-font: "UD Digi Kyokasho NK-R", "UDデジタル教科書体 NK-R", "Yu Kyokasho",
    "游教科書体", "Klee One", "Hiragino Maru Gothic ProN", "Yu Mincho",
    "Noto Serif CJK JP", "Noto Serif JP", serif;

  /* Fluid scale — grows with the viewport, no snap at 769px. */
  --text: clamp(1.25rem, 1.15rem + 0.4vw, 1.375rem);
  --text-sm: clamp(0.8125rem, 0.72rem + 0.4vw, 1rem);
  --h1: clamp(2.5rem, 1.8rem + 2.5vw, 3.5rem);
  --lead: clamp(1.5rem, 1.35rem + 0.8vw, 1.75rem);
  --mark: clamp(4.5rem, 3.8rem + 2vw, 5.5rem);
  --pad-y: clamp(1.5rem, 1rem + 2vw, 2.5rem);
  --pad-x: clamp(1.25rem, 0.9rem + 1.5vw, 2rem);
  --gap: clamp(0.4rem, 0.3rem + 0.4vw, 0.65rem);
  --switch-h: clamp(2.75rem, 2.5rem + 0.8vw, 3.15rem);
  --switch-h-hud: clamp(2.25rem, 2rem + 0.7vw, 2.75rem);
  --switch-pad-x: clamp(0.75rem, 0.55rem + 0.6vw, 1.15rem);
  --switch-fs: clamp(0.8125rem, 0.72rem + 0.4vw, 1rem);
  --switch-fs-hud: clamp(0.75rem, 0.66rem + 0.35vw, 0.9375rem);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--fg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: system-ui, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP",
    sans-serif;
  font-size: var(--text);
  line-height: 1.45;
  background: var(--bg);
  color: var(--fg);
}

[hidden] {
  display: none !important;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* —— Home —— */

#screen-home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(var(--pad-y), env(safe-area-inset-top))
    max(var(--pad-x), env(safe-area-inset-right))
    max(var(--pad-y), env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
}

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  max-width: 28rem;
  margin: 0 auto;
  width: 100%;
}

.mark {
  display: block;
  width: var(--mark);
  height: var(--mark);
  margin: 0 0 28px;
  object-fit: contain;
}

h1 {
  margin: 0 0 12px;
  font-size: var(--h1);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.lead {
  margin: 0 0 20px;
  font-size: var(--lead);
  font-weight: 600;
  color: var(--accent);
}

.status {
  margin: 0 0 32px;
  color: var(--muted);
  max-width: 22rem;
}

#enter,
.primary,
.ghost,
.textish {
  appearance: none;
  font: inherit;
  cursor: pointer;
}

#enter,
.primary {
  display: block;
  width: 100%;
  max-width: 22rem;
  margin: 0;
  padding: 18px 24px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
}

#enter:hover,
.primary:hover {
  filter: brightness(1.06);
}

#enter:focus-visible,
.primary:focus-visible,
.ghost:focus-visible,
.textish:focus-visible,
.card:focus-visible,
.lang-switch:focus-visible,
.seat-switch:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.home-langs,
.home-seats,
.hud-langs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.home-langs,
.home-seats {
  width: 100%;
  max-width: 22rem;
  margin: 0 0 var(--pad-x);
}

.hud-langs {
  margin-left: auto;
}

.lang-switch,
.seat-switch {
  appearance: none;
  display: block;
  flex: 1 1 0;
  box-sizing: border-box;
  min-height: var(--switch-h);
  min-width: 0;
  margin: 0;
  padding: 0 var(--switch-pad-x);
  border: 2px solid var(--muted);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: var(--switch-fs);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  text-align: center;
  cursor: pointer;
}

.lang-switch.is-on,
.seat-switch.is-on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.hud .lang-switch {
  flex: 0 1 auto;
  min-height: var(--switch-h-hud);
  font-size: var(--switch-fs-hud);
}

footer {
  max-width: 28rem;
  margin: 40px auto 0;
  width: 100%;
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--muted);
}

footer p {
  margin: 0 0 6px;
}

footer a {
  color: var(--fg);
  text-underline-offset: 3px;
}

footer a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.copy {
  margin: 0;
}

.noscript {
  max-width: 28rem;
  margin: 0 auto;
  padding: 20px;
  color: var(--muted);
}

/* —— Arena —— */

.game {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

#game-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 40rem;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

.hud {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 8px;
}

.mode {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

html[lang="ja"] .mode,
html[lang="ja"] .card .badge {
  text-transform: none;
  letter-spacing: 0.04em;
}

.mode:focus {
  outline: none;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.hp {
  display: flex;
  gap: 6px;
}

.pip {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--pip);
}

.pip.is-on {
  background: var(--accent);
}

.timer {
  flex: 0 0 auto;
  height: 14px;
  margin: 4px 0 10px;
  border-radius: 999px;
  background: var(--pip);
  overflow: hidden;
}

.timer-bar {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.glyph {
  margin: 0;
  font-family: var(--glyph-font);
  font-size: clamp(6.5rem, 38vmin, 12rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.glyph.is-drop {
  animation: drop 0.35s ease-out;
}

@keyframes drop {
  from {
    transform: translateY(-10%);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.scout-stage .glyph {
  margin-top: 12px;
}

.reading {
  margin: 8px 0 0;
  text-align: center;
  font-family: var(--glyph-font);
  font-size: clamp(2rem, 8vw, 2.75rem);
  font-weight: 600;
  letter-spacing: 0.12em;
}

.meaning-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 16px 0 8px;
}

.meaning {
  margin: 0;
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  font-weight: 700;
}

.picture {
  width: 72px;
  height: 72px;
  color: var(--accent);
  flex-shrink: 0;
}

.picture svg,
.pic svg {
  display: block;
  width: 100%;
  height: 100%;
}

.parts {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.parts li {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  font-size: 18px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
}

.ghost {
  display: block;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto;
  padding: 16px 24px;
  border: 2px solid var(--muted);
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  font-size: 20px;
  font-weight: 650;
  text-align: center;
}

.primary {
  margin-left: auto;
  margin-right: auto;
}

.textish {
  display: block;
  width: 100%;
  max-width: 22rem;
  margin: 8px auto 0;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.glyph-hitbox {
  appearance: none;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.glyph-hitbox:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.war-stage .glyph {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.hand {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.card {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 7.25rem;
  padding: 14px 10px 12px;
  border: 2px solid #3a342c;
  border-radius: 14px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.card .pic {
  width: 56px;
  height: 56px;
  color: var(--accent);
}

.card .word {
  font-family: var(--glyph-font);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  letter-spacing: 0.06em;
}

.card .gloss {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  color: var(--muted);
}

.card .badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--accent-ink);
}

.card.is-hit {
  border-color: var(--hit);
  box-shadow: 0 0 0 3px var(--hit);
}

.card.is-cpu {
  border-color: var(--cpu);
  box-shadow: 0 0 0 3px var(--cpu);
}

.card.is-cpu .badge {
  background: var(--cpu);
  color: #0b1520;
}

.card.is-miss {
  border-color: var(--miss);
  opacity: 0.45;
}

.hand.is-resolved .card:not(.is-hit):not(.is-cpu) {
  opacity: 0.4;
}

.result-title {
  margin: 24px 0 20px;
  font-size: clamp(2rem, 7vw, 2.75rem);
  font-weight: 700;
  line-height: 1.15;
}

.score {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
}

.score li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid #2a261f;
  font-size: 20px;
}

.score strong {
  font-size: 24px;
  color: var(--accent);
}

.owned-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 16px;
}

.owned-row {
  margin: 0 0 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  font-family: var(--glyph-font);
  font-size: 2.25rem;
  line-height: 1;
}

.note {
  margin: 0 0 8px;
  color: var(--muted);
  max-width: 28rem;
}

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media screen and (min-width: 769px) {
  #enter,
  .primary {
    width: auto;
    min-width: 12rem;
  }

  .ghost {
    width: auto;
    min-width: 12rem;
  }

  .actions {
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
  }

  .game {
    padding: 28px 32px;
  }

  .card {
    min-height: 8rem;
  }

  .card .pic {
    width: 64px;
    height: 64px;
  }

  .card .word {
    font-size: 26px;
  }

  .home-langs,
  .lang-switch {
    width: auto;
  }

  .lang-switch {
    flex: 0 1 auto;
    min-width: 7rem;
  }
}

@media (max-height: 560px) {
  :root {
    --switch-h-hud: 2.125rem;
    --switch-fs-hud: 0.75rem;
  }

  .glyph {
    font-size: clamp(4.5rem, 28vmin, 8rem);
  }

  .card {
    min-height: 5.5rem;
    padding: 8px;
    flex-direction: row;
    gap: 12px;
  }

  .card .pic {
    width: 40px;
    height: 40px;
  }

  .picture {
    width: 48px;
    height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #enter:hover,
  .primary:hover {
    filter: none;
  }

  .glyph.is-drop {
    animation: none;
  }
}
