:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #667385;
  --line: #d8dee8;
  --paper: #f7f4ec;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --red: #d84f4a;
  --red-dark: #a93835;
  --green: #167b63;
  --blue: #2a6fbb;
  --gold: #c5841f;
  --shadow: 0 18px 46px rgba(28, 42, 56, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(216, 79, 74, 0.13), transparent 28%),
    linear-gradient(315deg, rgba(42, 111, 187, 0.12), transparent 34%),
    var(--paper);
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.app-shell {
  width: min(1240px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(300px, 0.8fr);
  gap: 18px;
  align-items: stretch;
}

.arena-panel,
.side-panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid rgba(216, 222, 232, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.arena-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar,
.top-actions,
.brand-lockup,
.score-strip,
.form-actions,
.section-heading,
.select-row,
.toggle-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup {
  gap: 12px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 8px;
  font-weight: 900;
  font-size: 1.55rem;
  box-shadow: 0 10px 22px rgba(216, 79, 74, 0.28);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 3.6rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand-lockup p,
.eyebrow,
.feedback-kicker,
.select-row span,
.toggle-row span {
  color: var(--muted);
}

.top-actions {
  gap: 10px;
}

.icon-button,
.ghost-button,
.primary-button,
.secondary-button,
.segment {
  min-height: 42px;
  border-radius: 8px;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.icon-button {
  width: 42px;
  background: #eef5fb;
  color: var(--blue);
  font-weight: 800;
}

.ghost-button,
.secondary-button {
  padding: 0 14px;
  color: var(--ink);
  background: #f0f3f6;
}

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--red);
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(216, 79, 74, 0.24);
}

.primary-button.full {
  width: 100%;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.score-strip > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  font-size: 0.77rem;
  text-transform: uppercase;
}

.score-strip strong {
  font-size: 1.25rem;
}

.battlefield {
  flex: 1;
  min-height: 520px;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.8)),
    repeating-linear-gradient(0deg, transparent 0 34px, rgba(42, 111, 187, 0.05) 34px 35px);
  display: grid;
  grid-template-rows: auto minmax(170px, auto) auto minmax(120px, auto);
  gap: 18px;
}

.language-rail {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.rail-line {
  height: 2px;
  background: linear-gradient(90deg, var(--blue), var(--red));
}

.prompt-zone {
  padding: 28px;
  border-radius: 8px;
  background: #1e2a34;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 26px;
}

.round-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.round-meta span {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #e6eef6;
  font-size: 0.82rem;
  font-weight: 800;
}

#prompt-text {
  font-size: clamp(1.7rem, 3vw, 2.8rem);
  line-height: 1.15;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.answer-form {
  display: grid;
  gap: 10px;
}

.answer-form label,
.controls-block h2,
.leaderboard h2 {
  font-size: 0.88rem;
  font-weight: 900;
}

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
  font-size: 0.98rem;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(42, 111, 187, 0.13);
}

.form-actions {
  justify-content: flex-end;
  gap: 10px;
}

.feedback-panel {
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.feedback-panel.good {
  border-color: rgba(22, 123, 99, 0.45);
  background: rgba(22, 123, 99, 0.08);
}

.feedback-panel.mid {
  border-color: rgba(197, 132, 31, 0.45);
  background: rgba(197, 132, 31, 0.09);
}

.feedback-panel.bad {
  border-color: rgba(216, 79, 74, 0.45);
  background: rgba(216, 79, 74, 0.08);
}

.feedback-kicker {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 900;
}

#feedback-text {
  font-weight: 800;
}

#answer-text {
  margin-top: 8px;
  color: var(--muted);
}

#coach-text {
  margin-top: 8px;
  color: var(--blue);
  font-weight: 700;
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.mini-map {
  min-height: 76px;
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto 1fr auto 1fr auto;
  align-items: center;
}

.map-node {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  font-size: 0.82rem;
}

.map-node.active {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}

.map-node:hover {
  border-color: var(--red);
  box-shadow: 0 8px 18px rgba(216, 79, 74, 0.18);
}

.map-node:focus-visible {
  outline: 3px solid rgba(42, 111, 187, 0.28);
  outline-offset: 3px;
}

.map-path {
  height: 3px;
  background: var(--line);
}

.controls-block,
.leaderboard,
.wrongbook {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.controls-block {
  display: grid;
  gap: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  border-radius: 8px;
  background: #edf1f5;
}

.segment {
  min-width: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(28, 42, 56, 0.1);
}

.select-row,
.toggle-row {
  justify-content: space-between;
  gap: 12px;
}

.select-row span,
.toggle-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

select,
input[readonly] {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--red);
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-heading span {
  color: var(--blue);
  font-weight: 900;
}

ol {
  margin: 0;
  padding-left: 22px;
}

li {
  padding: 8px 0;
}

li span {
  float: right;
  color: var(--muted);
  font-weight: 800;
}

.wrongbook ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.wrongbook li {
  padding: 10px;
  border-radius: 8px;
  background: #f6f8fb;
  border: 1px solid #e5eaf1;
}

.wrongbook strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.88rem;
}

.wrongbook small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

.wrongbook-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.text-button {
  min-height: 0;
  padding: 0;
  color: var(--red-dark);
  background: transparent;
  font-weight: 900;
}

dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.42);
}

dialog form {
  display: grid;
  gap: 14px;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0;
}

#room-link {
  width: 100%;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px 0;
  }

  .side-panel {
    order: -1;
  }

  h1 {
    font-size: 2.2rem;
  }

  .score-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
  }

  .arena-panel,
  .side-panel,
  .battlefield {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .score-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .score-strip > div:last-child {
    grid-column: 1 / -1;
  }

  .battlefield {
    min-height: 0;
    grid-template-rows: auto auto auto auto;
  }

  .prompt-zone {
    padding: 20px;
  }

  #prompt-text {
    font-size: 1.65rem;
  }

  .select-row {
    align-items: flex-start;
    flex-direction: column;
  }

  select {
    width: 100%;
  }
}
