:root {
  --bg: #eef1ee;
  --panel: #fbfcfb;
  --panel-soft: #f4f7f5;
  --ink: #18231d;
  --muted: #66736c;
  --accent: #08756b;
  --accent-soft: #dcefeb;
  --warn: #b86b13;
  --warn-soft: #fff3df;
  --danger: #b64236;
  --danger-soft: #ffe7e2;
  --line: rgba(24, 35, 29, 0.13);
  --shadow: 0 12px 30px rgba(24, 35, 29, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  background: linear-gradient(180deg, #f8faf8 0%, var(--bg) 100%);
}

body {
  color: var(--ink);
  font-family: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", sans-serif;
  min-height: 100vh;
}

code,
input,
.stat strong,
.progress-line {
  font-family: "Iosevka Aile", "JetBrains Mono", "SFMono-Regular", monospace;
}

.app-shell {
  width: min(1280px, calc(100vw - 24px));
  height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}

.topbar,
.panel {
  animation: rise 0.35s ease both;
}

.topbar {
  min-height: 56px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 252, 251, 0.92);
  box-shadow: var(--shadow);
}

.brand {
  min-width: 220px;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.1rem, 1.8vw, 1.55rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  justify-content: flex-end;
}

.control {
  display: grid;
  gap: 4px;
}

.control span {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.control input,
.input-wrap input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.control input {
  width: 128px;
  height: 34px;
  padding: 0 9px;
  font-size: 0.88rem;
}

.control input:focus,
.input-wrap input:focus {
  border-color: rgba(8, 117, 107, 0.62);
  box-shadow: 0 0 0 3px rgba(8, 117, 107, 0.14);
}

.session-button {
  height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius);
  background: #08756b;
  color: #f8fffc;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(8, 117, 107, 0.18);
}

.session-button:hover {
  background: #06665d;
}

.game-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.32fr) minmax(0, 1fr) minmax(160px, 0.32fr) minmax(270px, 0.32fr);
  gap: 10px;
}

.panel {
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 252, 251, 0.94);
  box-shadow: var(--shadow);
}

.stage-panel,
.stats-panel,
.review-panel,
.word-stats-panel {
  display: flex;
  flex-direction: column;
}

.stage-panel {
  transition: background-color 160ms ease, border-color 160ms ease,
    box-shadow 160ms ease;
}

.stage-panel[data-phase="review"] {
  border-color: rgba(184, 107, 19, 0.42);
  background: #fffaf0;
  box-shadow: 0 12px 30px rgba(184, 107, 19, 0.13);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.stage-head {
  min-height: 26px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: var(--radius);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.badge.idle {
  background: rgba(102, 115, 108, 0.13);
  color: var(--muted);
}

.badge.live {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.composing {
  background: var(--warn-soft);
  color: #8f590c;
}

.badge.review {
  background: var(--warn-soft);
  color: #8f590c;
}

.badge.clear {
  background: rgba(54, 124, 73, 0.15);
  color: #2e6a3f;
}

.phase-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.display-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 12px;
  min-width: 0;
}

.display-word {
  font-size: clamp(1.2rem, 3.7vh, 2.67rem);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}

.meta-grid {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
}

.meta-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.meta-row dt {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.meta-row dd {
  min-width: 0;
  margin: 0;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.progress-block {
  margin-top: 11px;
}

.progress-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.progress-line {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  font-size: clamp(0.96rem, 2vh, 1.32rem);
  line-height: 1.38;
  overflow-wrap: anywhere;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.stage-panel[data-phase="review"] .progress-line {
  border-color: rgba(184, 107, 19, 0.24);
  background: #fff4df;
}

.done {
  color: var(--accent);
}

.current {
  color: var(--warn);
  animation: pulse 1.15s ease-in-out infinite;
}

.tail {
  color: rgba(24, 35, 29, 0.42);
}

.wrong {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 6px;
  padding: 0 4px;
  margin-left: 2px;
}

.placeholder {
  color: rgba(24, 35, 29, 0.42);
}

.input-wrap {
  display: grid;
  gap: 4px;
  margin-top: 11px;
}

.input-wrap span {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.input-wrap input {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  font-size: 1rem;
}

.stage-panel[data-phase="review"] .input-wrap input {
  border-color: rgba(184, 107, 19, 0.42);
  background: #fffdf8;
}

.stage-panel[data-phase="review"] .input-wrap input:focus {
  border-color: rgba(184, 107, 19, 0.68);
  box-shadow: 0 0 0 3px rgba(184, 107, 19, 0.16);
}

.input-wrap input:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.hint-text {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.restart-hint {
  margin: auto 0 0;
  padding-top: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.stat {
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 1.06rem;
  font-weight: 700;
}

.settings-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.setting-control {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.setting-control > span:first-child {
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.setting-control input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.setting-control input:focus {
  border-color: rgba(8, 117, 107, 0.62);
  box-shadow: 0 0 0 3px rgba(8, 117, 107, 0.14);
}

.setting-input-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.setting-input-row > span {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.source-status {
  min-height: 1.25em;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.review-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.review-head h2 {
  margin: 0;
  font-size: 0.96rem;
}

.review-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: right;
}

.review-list {
  min-height: 0;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
}

.review-item,
.review-empty {
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.review-item--pending {
  border-color: rgba(184, 107, 19, 0.42);
  background: var(--warn-soft);
}

.review-item {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  gap: 7px;
  align-items: baseline;
  white-space: nowrap;
}

.review-word {
  min-width: 0;
  font-size: 0.84rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-reading {
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-meta,
.review-empty {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.next-word-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.next-word-block[hidden] {
  display: none;
}

.next-word-label {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.next-word-display {
  font-size: clamp(0.9rem, 2.4vh, 1.6rem);
  font-weight: 700;
  color: rgba(24, 35, 29, 0.35);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-stats-panel {
  min-height: 0;
}

.word-stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.word-stats-head h2 {
  margin: 0;
  font-size: 0.86rem;
  letter-spacing: 0.04em;
}

.word-stats-clear {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.word-stats-clear:hover {
  border-color: rgba(182, 66, 54, 0.5);
  background: var(--danger-soft);
  color: var(--danger);
}

.word-stats-list {
  flex: 1;
  min-height: 0;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
}

.stats-item,
.stats-empty {
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.stats-item {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  gap: 7px;
  align-items: baseline;
  white-space: nowrap;
}

.stats-word {
  min-width: 0;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-meta {
  font-family: "Iosevka Aile", "JetBrains Mono", "SFMono-Regular", monospace;
}

.score-block {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.score-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-soft);
  text-align: center;
}

.score-item--main {
  border-color: rgba(8, 117, 107, 0.38);
  background: var(--accent-soft);
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score-value {
  display: block;
  margin-top: 3px;
  font-size: 1.22rem;
  font-weight: 700;
  font-family: "Iosevka Aile", "JetBrains Mono", "SFMono-Regular", monospace;
}

.score-item--main .score-label {
  color: var(--accent);
}

.score-item--main .score-value {
  color: var(--accent);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: translateY(0);
  }
  50% {
    opacity: 0.52;
    transform: translateY(-1px);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --panel: #232323;
    --panel-soft: #1f1f1f;
    --ink: #ddd;
    --muted: #999;
    --accent: #4ec9bc;
    --accent-soft: rgba(78, 201, 188, 0.18);
    --warn: #e0a04a;
    --warn-soft: rgba(224, 160, 74, 0.18);
    --danger: #e07566;
    --danger-soft: rgba(224, 117, 102, 0.2);
    --line: rgba(221, 221, 221, 0.16);
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  }

  html {
    background: linear-gradient(180deg, #1f1f1f 0%, var(--bg) 100%);
  }

  .topbar,
  .panel {
    background: rgba(35, 35, 35, 0.94);
  }

  .control input,
  .input-wrap input,
  .setting-control input,
  .word-stats-clear {
    background: #2a2a2a;
    color: var(--ink);
  }

  .session-button {
    background: var(--accent);
    color: #0e2624;
    box-shadow: 0 8px 18px rgba(78, 201, 188, 0.22);
  }

  .session-button:hover {
    background: #6ddccf;
  }

  .badge.composing,
  .badge.review {
    color: #f0c682;
  }

  .badge.clear {
    background: rgba(78, 201, 188, 0.18);
    color: var(--accent);
  }

  .stage-panel[data-phase="review"] {
    background: rgba(224, 160, 74, 0.08);
  }

  .stage-panel[data-phase="review"] .progress-line {
    background: rgba(224, 160, 74, 0.1);
  }

  .stage-panel[data-phase="review"] .input-wrap input {
    background: rgba(224, 160, 74, 0.08);
  }

  .tail,
  .placeholder,
  .next-word-display {
    color: rgba(221, 221, 221, 0.42);
  }

  .stats-word {
    color: var(--ink);
  }

  .word-stats-clear:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }
}
