:root {
  color-scheme: light;
  --ink: #18212a;
  --muted: #687689;
  --line: #d8e0ea;
  --paper: #f5f0e7;
  --panel: #fffdf8;
  --teal: #147c72;
  --teal-dark: #0e5d55;
  --red: #d65349;
  --blue: #2f69bd;
  --gold: #b7791f;
  --shadow: 0 20px 48px rgba(31, 43, 55, 0.13);
}

* {
  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(20, 124, 114, 0.14), transparent 30%),
    linear-gradient(315deg, rgba(214, 83, 73, 0.12), transparent 32%),
    var(--paper);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: var(--teal-dark);
  font-weight: 800;
  text-decoration: none;
}

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

.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.8fr) minmax(310px, 0.85fr);
  gap: 18px;
}

.play-panel,
.side-panel {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(216, 224, 234, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

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

.topbar,
.brand-lockup,
.top-actions,
.score-strip,
.challenge-head,
.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(--teal);
  border-radius: 8px;
  font-weight: 900;
  font-size: 1.55rem;
}

h1,
h2,
p {
  margin: 0;
}

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

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

.top-actions {
  gap: 10px;
}

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

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(20, 124, 114, 0.22);
}

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

.icon-button {
  width: 42px;
  background: #eef3f4;
  color: var(--teal-dark);
  font-weight: 900;
}

button:hover,
a.ghost-button:hover {
  transform: translateY(-1px);
}

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

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

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

.eyebrow {
  display: block;
  margin-bottom: 5px;
  font-size: 0.78rem;
  font-weight: 800;
}

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

.challenge-card {
  flex: 1;
  min-height: 540px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.85)),
    repeating-linear-gradient(0deg, transparent 0 34px, rgba(20, 124, 114, 0.055) 34px 35px);
  display: grid;
  grid-template-rows: auto auto minmax(150px, auto) auto minmax(116px, auto);
  gap: 16px;
}

.challenge-head {
  justify-content: space-between;
  gap: 12px;
}

.challenge-head span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin-right: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: #23313b;
  font-size: 0.84rem;
  font-weight: 900;
}

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

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

#prompt-text {
  min-height: 150px;
  padding: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  color: #fff;
  background: #1f2c34;
  font-size: clamp(1.75rem, 3vw, 2.95rem);
  line-height: 1.14;
  font-weight: 900;
  overflow-wrap: anywhere;
}

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

.answer-form label,
.mode-block h2,
.sound-board h2,
.wrongbook h2,
.source-note h2 {
  font-size: 0.9rem;
  font-weight: 900;
}

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

textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(20, 124, 114, 0.13);
}

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

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

.feedback-panel.good {
  border-color: rgba(20, 124, 114, 0.45);
  background: rgba(20, 124, 114, 0.08);
}

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

.feedback-panel.bad {
  border-color: rgba(214, 83, 73, 0.45);
  background: rgba(214, 83, 73, 0.08);
}

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

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

#answer-text,
#coach-text {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

#coach-text {
  color: var(--blue);
  font-weight: 750;
}

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

.mode-block,
.sound-board,
.wrongbook,
.source-note {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

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

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

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

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

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

select {
  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(--teal);
}

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

.sound-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.sound-chip {
  padding: 10px;
  border: 1px solid #e1e8ef;
  border-radius: 8px;
  background: #f7faf9;
}

.sound-chip strong {
  display: block;
  color: var(--teal-dark);
}

.sound-chip small {
  color: var(--muted);
}

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

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

.wrongbook strong,
.wrongbook small {
  display: block;
}

.wrongbook small {
  margin-top: 4px;
  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(--teal-dark);
  background: transparent;
  font-weight: 900;
}

.source-note p {
  line-height: 1.65;
}

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

  .side-panel {
    order: -1;
  }
}

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

  .play-panel,
  .side-panel,
  .challenge-card {
    padding: 14px;
  }

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

  .top-actions {
    width: 100%;
  }

  .top-actions > * {
    flex: 1;
    text-align: center;
  }

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

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

  #prompt-text {
    min-height: 126px;
    padding: 20px;
    font-size: 1.65rem;
  }

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

  select {
    width: 100%;
  }
}
