:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #686f7a;
  --line: #d9dee7;
  --paper: #ffffff;
  --wash: #f5f7fa;
  --mint: #1f9d72;
  --mint-dark: #147857;
  --coral: #e85645;
  --yellow: #f4c430;
  --cyan: #2a9fd6;
  --black: #111111;
  --soft-green: #e8f7ef;
  --soft-red: #ffe9e5;
  --soft-yellow: #fff8d7;
  --shadow: 0 18px 50px rgba(20, 25, 30, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--wash);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(245, 247, 250, 0.96)),
    repeating-linear-gradient(90deg, rgba(23, 23, 23, 0.03) 0 1px, transparent 1px 44px);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.topbar h1,
.session-strip h2,
.dialog-heading h2 {
  margin: 0;
  line-height: 1.05;
}

.topbar h1 {
  font-size: 1.9rem;
}

.topbar__actions,
.speech-main,
.speech-options,
.action-row,
.join-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(420px, 1fr) minmax(260px, 330px);
  gap: 18px;
  margin-top: 18px;
}

.side-panel,
.practice-panel,
.score-panel {
  min-width: 0;
}

.side-panel,
.score-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.practice-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - 120px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.control-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.control-block label,
.writing-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 250px;
  resize: vertical;
  padding: 16px;
  line-height: 1.6;
  font-size: 1.05rem;
}

input:focus,
textarea:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(31, 157, 114, 0.18);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.segment {
  min-height: 38px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segment.is-active {
  color: #fff;
  background: var(--black);
}

.compact-label {
  display: none;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 850;
}

.primary-button {
  color: #fff;
  background: var(--mint);
}

.primary-button:hover {
  background: var(--mint-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--paper);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--ink);
}

.ghost-button {
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  color: #0f5d42;
  background: var(--soft-green);
  font-weight: 800;
}

.level-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.level-heading span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.level-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.level-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
}

.level-tab.is-active {
  border-color: var(--black);
  color: #fff;
  background: var(--black);
}

.dictation-list {
  display: grid;
  gap: 8px;
  max-height: 328px;
  overflow: auto;
  padding-right: 3px;
}

.dictation-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.dictation-item strong {
  font-size: 0.96rem;
}

.dictation-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.dictation-item.is-active {
  border-color: var(--mint);
  background: var(--soft-green);
}

.room-panel {
  display: grid;
  gap: 10px;
}

.room-code {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  border: 1px dashed var(--cyan);
  border-radius: 8px;
  color: var(--black);
  background: #edf8fd;
  font-size: 1.35rem;
  font-weight: 900;
}

.join-row {
  align-items: stretch;
}

.join-row input {
  text-transform: uppercase;
}

.session-strip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.session-strip h2 {
  font-size: 2rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 8px;
  min-width: 300px;
}

.metrics div {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.metrics span {
  display: block;
  font-size: 1.35rem;
  font-weight: 950;
}

.metrics small {
  color: var(--muted);
  font-weight: 750;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--mint), var(--yellow), var(--coral));
  transition: width 160ms ease;
}

.speech-console {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.speech-options input {
  width: 140px;
  accent-color: var(--mint);
}

.sentence-map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.sentence-chip {
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
  text-align: left;
}

.sentence-chip.is-current {
  border-color: var(--cyan);
  color: #064b66;
  background: #edf8fd;
}

.sentence-chip.is-done {
  border-color: var(--mint);
  color: #0f5d42;
  background: var(--soft-green);
}

.feedback-line {
  min-height: 54px;
}

.live-feedback {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-chip {
  max-width: 100%;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.word-chip.good {
  color: #0f5d42;
  background: var(--soft-green);
}

.word-chip.close {
  color: #705d00;
  background: var(--soft-yellow);
}

.word-chip.bad {
  color: #9f2519;
  background: var(--soft-red);
}

.action-row {
  flex-wrap: wrap;
  margin-top: auto;
}

.study-photo {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.study-photo img {
  display: block;
  width: 100%;
  height: 168px;
  object-fit: cover;
}

.leaderboard {
  display: grid;
  gap: 8px;
}

.leader-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.leader-row.is-me {
  border-color: var(--mint);
  background: var(--soft-green);
}

.leader-rank {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #fff;
  background: var(--black);
  font-weight: 900;
}

.leader-name {
  min-width: 0;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-score {
  font-weight: 950;
}

.analysis-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.analysis-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.analysis-list div:last-child {
  border-bottom: 0;
}

.analysis-list dt {
  color: var(--muted);
  font-weight: 750;
}

.analysis-list dd {
  margin: 0;
  font-weight: 900;
}

.rules-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.correction-dialog {
  width: min(920px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.18);
}

.correction-dialog::backdrop {
  background: rgba(17, 17, 17, 0.42);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.correction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.correction-grid section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.correction-grid h3 {
  margin: 0 0 8px;
}

.correction-grid p {
  margin: 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--black);
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .app-grid {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .score-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .study-photo img {
    height: 100%;
    min-height: 190px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .session-strip,
  .speech-console {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar__actions,
  .speech-main,
  .speech-options {
    flex-wrap: wrap;
  }

  .app-grid,
  .score-panel {
    grid-template-columns: 1fr;
  }

  .practice-panel {
    min-height: auto;
    padding: 12px;
  }

  .metrics {
    min-width: 0;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .metrics div {
    min-height: 58px;
    padding: 8px;
  }

  .metrics span {
    font-size: 1.05rem;
  }

  .session-strip h2 {
    font-size: 1.45rem;
  }

  .correction-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .level-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .segment,
  .level-tab {
    font-size: 0.92rem;
  }

  .wide-label {
    display: none;
  }

  .compact-label {
    display: inline;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .join-row {
    flex-direction: column;
  }
}
