:root {
  color: #17201c;
  background: #e8edf0;
  font-family: 'BIZ UDPGothic', sans-serif;
  font-weight: 700;
  font-synthesis: none;
  --display-font: 'Klee One', cursive;
  --ink: #17201c;
  --paper: #f8faf9;
  --line: #b9c3c1;
  --akane: #e94d3d;
  --akane-soft: #ffd7ce;
  --sora: #126e82;
  --sora-soft: #bceaf0;
  --yellow: #f2c94c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(23, 32, 28, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 28, .055) 1px, transparent 1px),
    #e8edf0;
  background-size: 32px 32px;
}

button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; background: var(--paper); border-inline: 1px solid var(--ink); }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(20px, 4vw, 64px); border-bottom: 1px solid var(--ink); }
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 34px; aspect-ratio: 1; color: white; background: var(--ink); font-family: var(--display-font); font-size: 22px; transform: rotate(-5deg); }
.api-badge { display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 700; }
.status-dot { width: 9px; aspect-ratio: 1; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 4px rgba(242, 201, 76, .2); }
.api-badge.is-ready .status-dot { background: #319667; box-shadow: 0 0 0 4px rgba(49, 150, 103, .18); }
.api-badge.is-unavailable .status-dot { background: var(--akane); box-shadow: 0 0 0 4px rgba(233, 77, 61, .16); }

.arena { padding: clamp(36px, 6vw, 86px) clamp(20px, 5vw, 80px) 48px; overflow: hidden; }
.arena-heading, .section-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.eyebrow { margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .16em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: var(--display-font); font-size: clamp(38px, 5.5vw, 78px); font-weight: 600; line-height: 1.06; letter-spacing: 0; }
.match-stats { display: flex; border: 1px solid var(--ink); background: white; }
.match-stats div { min-width: 112px; padding: 15px 20px; display: grid; gap: 3px; }
.match-stats div + div { border-left: 1px solid var(--ink); }
.match-stats strong { font-size: 23px; font-variant-numeric: tabular-nums; }
.match-stats span { font-size: 10px; }

.court { position: relative; display: grid; grid-template-columns: minmax(170px, 1fr) minmax(320px, 1.65fr) minmax(170px, 1fr); align-items: center; gap: 24px; min-height: 440px; margin-top: 36px; border-block: 1px solid var(--ink); }
.court::before { content: ''; position: absolute; inset: 50% 0 auto; border-top: 1px dashed var(--line); }
.player { position: relative; z-index: 1; display: flex; align-items: center; gap: 16px; padding: 18px; background: var(--paper); border: 1px solid transparent; transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease; }
.player.is-active { transform: translateY(-8px); border-color: var(--ink); box-shadow: 7px 7px 0 var(--ink); }
.player h2 { margin-bottom: 4px; font-family: var(--display-font); font-size: 32px; font-weight: 600; }
.player p { margin-bottom: 0; font-size: 11px; }
.player-number { font-weight: 700; letter-spacing: .12em; }
.portrait { position: relative; flex: 0 0 76px; display: grid; place-items: center; aspect-ratio: 1; border: 1px solid var(--ink); border-radius: 50%; font-family: var(--display-font); font-size: 38px; }
.portrait::after { content: ''; position: absolute; width: 18px; height: 8px; right: -7px; bottom: 9px; border: 1px solid var(--ink); background: var(--yellow); transform: rotate(-22deg); }
.portrait-akane { background: var(--akane-soft); }
.portrait-sora { background: var(--sora-soft); }

.play-zone { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; min-height: 330px; }
.next-kana { position: relative; z-index: 2; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; font-size: 12px; }
.next-kana strong { display: grid; place-items: center; width: 44px; aspect-ratio: 1; background: var(--yellow); border: 1px solid var(--ink); border-radius: 50%; font-family: var(--display-font); font-size: 27px; }
.current-word { position: relative; display: grid; justify-items: center; width: min(100%, 420px); padding: 34px 28px 30px; background: white; border: 1px solid var(--ink); box-shadow: 10px 10px 0 var(--yellow); text-align: center; }
.current-word::before, .current-word::after { content: ''; position: absolute; top: 50%; width: 35px; border-top: 2px solid var(--ink); }
.current-word::before { right: 100%; }
.current-word::after { left: 100%; }
.word-reading { min-height: 19px; font-size: 12px; color: #5d6964; }
.current-word strong { max-width: 100%; overflow-wrap: anywhere; font-family: var(--display-font); font-size: clamp(46px, 5.4vw, 72px); font-weight: 600; line-height: 1.15; letter-spacing: 0; }
.current-word p { margin: 8px 0 0; font-size: 12px; }
.word-pop { animation: word-pop .45s cubic-bezier(.2, .85, .35, 1.2); }
@keyframes word-pop { from { opacity: 0; transform: scale(.82) rotate(-2deg); } to { opacity: 1; transform: scale(1); } }

.control-deck { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding-top: 28px; }
.match-status { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 13px; min-width: 0; }
.match-status strong { display: block; margin-bottom: 4px; font-size: 14px; }
.match-status p { margin: 0; color: #5d6964; font-size: 11px; }
.status-icon { color: #87918d; font-size: 13px; }
.status-akane { color: var(--akane); animation: pulse 1s infinite alternate; }
.status-sora { color: var(--sora); animation: pulse 1s infinite alternate; }
.status-loading { color: var(--yellow); animation: pulse .7s infinite alternate; }
.status-error { color: var(--akane); }
@keyframes pulse { to { opacity: .35; } }
.download-meter { position: absolute; top: calc(100% + 10px); left: 26px; width: min(320px, 70vw); height: 4px; background: #d7ddda; }
.download-meter span { display: block; height: 100%; width: 0; background: var(--yellow); transition: width .2s ease; }
.controls { display: flex; align-items: center; gap: 10px; }
.speed-control { display: grid; gap: 4px; margin-right: 8px; font-size: 9px; font-weight: 700; }
select { min-width: 100px; padding: 8px 28px 8px 9px; color: var(--ink); background: white; border: 1px solid var(--ink); border-radius: 0; }
.button { min-height: 45px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 17px; border: 1px solid var(--ink); border-radius: 0; font-weight: 700; }
.button-secondary { background: white; }
.button-primary { min-width: 126px; color: white; background: var(--ink); }
.button:not(:disabled):hover { transform: translateY(-2px); box-shadow: 3px 3px 0 var(--yellow); }

.history-section { padding: 58px clamp(20px, 5vw, 80px) 80px; background: #dce8e6; border-top: 1px solid var(--ink); }
.section-heading { padding-bottom: 24px; border-bottom: 1px solid var(--ink); }
.section-heading h2 { margin: 0; font-family: var(--display-font); font-size: 38px; font-weight: 600; }
.section-heading > p { margin: 0; font-size: 10px; }
.word-history { max-height: 440px; margin: 0; padding: 0; list-style: none; overflow-y: auto; }
.history-placeholder { padding: 52px 0; color: #66736e; font-size: 13px; text-align: center; }
.history-item { display: grid; grid-template-columns: 46px 72px minmax(120px, 1fr) minmax(100px, 1fr) 55px; align-items: center; gap: 16px; min-height: 67px; border-bottom: 1px solid #94a5a0; animation: slide-in .3s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-12px); } }
.history-number, .history-player, .history-reading, .history-arrow { font-size: 11px; }
.history-player { font-weight: 700; }
.history-item.player-0 .history-player { color: #b82d20; }
.history-item.player-1 .history-player { color: var(--sora); }
.history-item strong { font-family: var(--display-font); font-size: 25px; font-weight: 600; }
.history-arrow { justify-self: end; }

footer { display: flex; justify-content: space-between; gap: 24px; padding: 22px clamp(20px, 5vw, 80px); color: white; background: var(--ink); font-size: 10px; }
footer p { margin: 0; }

@media (max-width: 900px) {
  .court { grid-template-columns: 1fr 1fr; padding: 28px 0; }
  .play-zone { grid-column: 1 / -1; grid-row: 1; min-height: 300px; }
  .player { grid-row: 2; justify-content: center; }
  .control-deck { align-items: stretch; flex-direction: column; }
  .controls { justify-content: flex-end; }
}

@media (max-width: 620px) {
  .topbar { height: 62px; }
  .api-badge { max-width: 130px; justify-content: flex-end; text-align: right; }
  .arena { padding-top: 32px; }
  .arena-heading { align-items: stretch; flex-direction: column; }
  h1 { font-size: 44px; }
  .match-stats div { flex: 1; min-width: 0; }
  .court { gap: 7px; min-height: 500px; margin-top: 28px; }
  .play-zone { min-height: 280px; }
  .current-word { width: calc(100% - 20px); padding-inline: 18px; box-shadow: 7px 7px 0 var(--yellow); }
  .current-word::before, .current-word::after { display: none; }
  .player { align-items: center; flex-direction: column; gap: 9px; padding: 12px 5px; text-align: center; }
  .player.is-active { transform: translateY(-4px); box-shadow: 4px 4px 0 var(--ink); }
  .portrait { flex-basis: 58px; width: 58px; font-size: 29px; }
  .player h2 { font-size: 25px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
  .speed-control { grid-column: 1 / -1; margin: 0 0 5px; }
  select { width: 100%; }
  .button { min-width: 0; padding-inline: 10px; }
  .section-heading > p { display: none; }
  .history-item { grid-template-columns: 34px 52px 1fr 42px; gap: 8px; }
  .history-reading { display: none; }
  footer { flex-direction: column; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}