:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #5867e8;
  --primary-ink: #ffffff;
  --teal: #0f9f8f;
  --amber: #d58a16;
  --coral: #d95f45;
  --soft-blue: #eef3ff;
  --soft-teal: #e8f7f4;
  --shadow: 0 18px 40px rgba(35, 44, 72, 0.10);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 20px;
  max-width: 1440px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: white;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.brand h1,
.panel-head h2,
.panel-head p,
.practice-top h2,
.practice-top p {
  margin: 0;
}

.brand h1 {
  font-size: 26px;
  line-height: 1.1;
}

.header-meter {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-meter span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
}

.sidebar,
.main-panel,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  align-self: start;
  padding: 18px;
}

.control-section + .control-section {
  margin-top: 22px;
}

.control-section h2 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--muted);
}

.deck-tabs {
  display: grid;
  gap: 8px;
}

.deck-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.deck-tab.active {
  border-color: var(--primary);
  background: var(--soft-blue);
  box-shadow: inset 4px 0 0 var(--primary);
}

.deck-tab strong {
  display: block;
  font-size: 15px;
}

.deck-tab span {
  color: var(--muted);
  font-size: 13px;
}

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

.segmented button,
.ghost-button,
.text-button,
.primary-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.segmented button.active,
.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.ghost-button {
  width: 100%;
  padding: 0 14px;
}

.text-button {
  width: auto;
  min-width: 96px;
  padding: 0 14px;
  background: var(--soft-teal);
  border-color: #c5e8e1;
  color: #0c766b;
  white-space: nowrap;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--ink);
  font-weight: 700;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.main-panel {
  min-height: calc(100vh - 116px);
  padding: 24px;
}

.panel-head,
.practice-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-head h2,
.practice-top h2 {
  font-size: 28px;
  line-height: 1.2;
}

.panel-head p,
.practice-top p {
  color: var(--muted);
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.search-box input {
  width: 180px;
  border: 0;
  outline: 0;
  color: var(--ink);
}

.deck-overview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 110px;
  margin: 22px 0;
  padding: 22px;
  border: 1px solid #cfe2f3;
  border-radius: 8px;
  background: linear-gradient(90deg, #f8fbff, #ecf7f4);
}

.overview-copy strong {
  display: block;
  font-size: 20px;
  margin-bottom: 6px;
}

.overview-copy span {
  color: var(--muted);
  font-weight: 800;
}

.book-shelf {
  display: flex;
  align-items: end;
  gap: 8px;
  height: 68px;
  padding: 8px 12px;
}

.book-shelf span {
  width: 22px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px 4px 2px 2px;
  background: #d9e4ff;
}

.book-shelf span:nth-child(1) {
  height: 44px;
  background: #cceee7;
  transform: rotate(10deg);
}

.book-shelf span:nth-child(2) {
  height: 58px;
  background: #ffe5b8;
}

.book-shelf span:nth-child(3) {
  height: 50px;
  background: #d9d7ff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.level-card {
  position: relative;
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  overflow: hidden;
}

.level-card:hover,
.level-card:focus-visible {
  border-color: var(--primary);
  outline: 0;
}

.level-card.done {
  background: linear-gradient(180deg, #fff, #f0fbf8);
}

.level-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 18px;
}

.level-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.level-card .score-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-top: 12px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--soft-blue);
  color: var(--primary);
  font-weight: 900;
}

.practice-view {
  display: grid;
  gap: 20px;
}

.practice-top {
  align-items: center;
}

.practice-top > div {
  flex: 1 1 auto;
  min-width: 180px;
}

.practice-top .ghost-button {
  width: auto;
  min-width: 112px;
  padding: 0 16px;
  white-space: nowrap;
}

.typing-stage {
  min-height: 360px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 36px 18px;
}

.word-ref {
  display: none;
}

.word-display {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 100%;
  min-height: 82px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 56px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
}

.word-display span {
  min-width: 0.55em;
  border-bottom: 3px solid transparent;
}

.word-display .space-char {
  min-width: 0.7em;
}

.word-display .correct {
  color: var(--teal);
}

.word-display .wrong {
  color: var(--coral);
  border-color: var(--coral);
}

.word-display .pending {
  color: #a7afbd;
}

.ipa-display,
.meaning-display {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.ipa-display {
  min-height: 28px;
  font-size: 20px;
}

.meaning-display {
  min-height: 26px;
  max-width: 720px;
  line-height: 1.6;
}

.typing-input {
  width: min(680px, 100%);
  min-height: 54px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  outline: 0;
  text-align: center;
}

.typing-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(88, 103, 232, 0.12);
}

.typing-input.has-error {
  border-color: var(--coral);
  box-shadow: 0 0 0 4px rgba(217, 95, 69, 0.12);
}

.input-actions,
.summary-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.input-actions .ghost-button,
.input-actions .primary-button,
.summary-actions .ghost-button,
.summary-actions .primary-button {
  width: auto;
  min-width: 112px;
  padding: 0 18px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stats-row div,
.summary-grid div {
  display: grid;
  place-items: center;
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stats-row strong,
.summary-grid strong {
  font-size: 26px;
}

.stats-row span,
.summary-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.queue-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.queue-strip span {
  flex: 0 0 auto;
  max-width: 160px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 51, 0.32);
  z-index: 10;
}

.summary-card {
  width: min(640px, 100%);
  padding: 24px;
}

.summary-card h2 {
  margin: 0 0 18px;
}

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

.wrong-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 150px;
  overflow: auto;
  margin: 18px 0;
}

.wrong-list span {
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff2ee;
  color: var(--coral);
  font-weight: 800;
}

[hidden] {
  display: none !important;
}

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

  .app-header,
  .panel-head,
  .practice-top {
    align-items: stretch;
    flex-direction: column;
  }

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

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }

  .control-section + .control-section {
    margin-top: 0;
  }

  .word-display {
    font-size: 42px;
  }
}

@media (max-width: 640px) {
  .sidebar,
  .stats-row,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .main-panel {
    padding: 16px;
  }

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

  .search-box,
  .search-box input {
    width: 100%;
  }

  .word-display {
    font-size: 34px;
  }
}
