:root {
  --ink: #17211f;
  --muted: #66706d;
  --line: #d8dedb;
  --paper: #fbfcfb;
  --panel: #eef3f1;
  --teal: #0f766e;
  --teal-soft: #dff3ef;
  --orange: #d95b2b;
  --yellow: #fff1c9;
  --red: #b42318;
  --green: #157347;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

body.modal-open {
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #f5f8f6;
  padding: 26px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: var(--white);
  font-weight: 800;
  font-size: 22px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.brand p,
.eyebrow,
.source-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.tab {
  height: 42px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 14px;
}

.tab.active,
.tab:hover {
  background: var(--white);
  border-color: var(--line);
  color: var(--teal);
  font-weight: 700;
}

.group-panel,
.daily-panel {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 16px;
}

.group-panel label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

#groupSelect {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--white);
  padding: 0 10px;
}

.group-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

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

.daily-panel strong {
  display: block;
  font-size: 24px;
  color: var(--teal);
}

.daily-panel span {
  font-size: 12px;
  color: var(--muted);
}

.workspace {
  padding: 30px 38px;
  min-width: 0;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: 31px;
  line-height: 1.1;
}

.status-message {
  min-height: 20px;
  margin: 6px 0 0;
  color: var(--teal);
  font-size: 14px;
  font-weight: 700;
}

.top-actions,
.quiz-actions,
.memory-actions,
.voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions .hidden {
  display: none;
}

.quiz-actions .hidden {
  display: none;
}

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

.icon-button,
.ghost-button,
.primary-button,
.memory-actions button,
.large-play {
  border: 1px solid var(--line);
  background: var(--white);
  min-height: 44px;
  padding: 0 14px;
}

.icon-button {
  width: 44px;
  padding: 0;
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--white);
  font-weight: 700;
}

.ghost-button:hover,
.memory-actions button:hover,
.icon-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.view {
  display: none;
  padding-top: 28px;
}

.view.active {
  display: block;
}

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

.stat-card,
.progress-block,
.plan-block,
.study-card,
.quiz-card {
  background: var(--white);
  border: 1px solid var(--line);
}

.stat-card {
  padding: 18px 20px;
}

.stat-card span,
.stat-card small {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 34px;
  color: var(--teal);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
  gap: 18px;
  margin-top: 18px;
}

.progress-block,
.plan-block {
  padding: 20px;
}

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

.section-heading h3,
.plan-block h3 {
  margin: 0;
  font-size: 20px;
}

.section-tip {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

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

.group-cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: var(--paper);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  position: relative;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.group-cell.done {
  background: var(--teal-soft);
  border-color: #8ccfc7;
  color: var(--teal);
  font-weight: 700;
}

.group-cell.current {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
}

.group-cell:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.plan-row {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.plan-row strong {
  display: block;
  margin-bottom: 5px;
}

.plan-row span {
  color: var(--muted);
  font-size: 14px;
}

.study-card,
.quiz-card {
  max-width: 880px;
  min-height: 480px;
  margin: 0 auto;
  padding: 28px;
}

.card-top,
.quiz-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.word-main {
  margin-top: 54px;
  font-size: clamp(44px, 8vw, 76px);
  font-weight: 800;
  line-height: 1.08;
  text-align: center;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
}

.word-pos {
  margin: 14px auto 30px;
  width: fit-content;
  min-width: 72px;
  text-align: center;
  color: var(--orange);
  font-weight: 700;
}

.meaning {
  margin: 22px auto;
  max-width: 650px;
  min-height: 74px;
  background: var(--yellow);
  border: 1px solid #e4c872;
  padding: 18px;
  font-size: 24px;
  text-align: center;
  display: grid;
  place-items: center;
}

.sentence-box {
  max-width: 760px;
  margin: 14px auto 0;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 16px 18px;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.35;
  text-align: center;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
}

.hidden {
  visibility: hidden;
}

.study-card .primary-button {
  display: block;
  margin: 0 auto;
}

.memory-actions {
  justify-content: center;
  margin-top: 28px;
}

.voice-row {
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.memory-actions button {
  min-width: 92px;
}

.prompt {
  min-height: 132px;
  display: grid;
  place-items: center;
  margin: 42px 0 20px;
  padding: 24px;
  background: var(--teal-soft);
  border: 1px solid #8ccfc7;
  font-size: 28px;
  text-align: center;
  line-height: 1.35;
}

.answer-input {
  width: 100%;
  height: 58px;
  border: 1px solid var(--line);
  padding: 0 18px;
  font-size: 24px;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.answer-input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  border-color: var(--teal);
}

.sentence-input {
  width: 100%;
  min-height: 118px;
  border: 1px solid var(--line);
  padding: 16px 18px;
  resize: vertical;
  font-size: 21px;
  line-height: 1.45;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
}

.sentence-input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  border-color: var(--teal);
}

.sentence-cn {
  margin: 18px auto 8px;
  max-width: 760px;
  min-height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid #8ccfc7;
  background: var(--teal-soft);
  padding: 14px 18px;
  font-size: 22px;
  line-height: 1.35;
  text-align: center;
}

.blank-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin: 18px 0 8px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.blank-input {
  width: clamp(92px, 12vw, 154px);
  height: 48px;
  border: 1px solid var(--line);
  background: var(--white);
  padding: 0 10px;
  text-align: center;
  font-size: 20px;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.blank-input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  border-color: var(--teal);
}

.blank-input.ok {
  border-color: var(--green);
  background: #effaf4;
}

.blank-input.bad {
  border-color: var(--red);
  background: #fff1ef;
}

.sentence-target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0;
  color: var(--muted);
}

.sentence-target strong {
  color: var(--teal);
  font-size: 22px;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
}

.sentence-quiz .large-play {
  margin-top: 30px;
}

.feedback {
  min-height: 52px;
  margin: 18px 0;
  font-size: 18px;
  font-weight: 700;
}

.feedback.ok {
  color: var(--green);
}

.feedback.bad {
  color: var(--red);
}

.large-play {
  width: 100%;
  min-height: 96px;
  margin: 44px 0 14px;
  background: var(--teal-soft);
  border-color: #8ccfc7;
  color: var(--teal);
  font-size: 24px;
  font-weight: 800;
}

.dictation-hint {
  min-height: 52px;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.word-list {
  display: grid;
  gap: 10px;
}

.heading-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.heading-actions .primary-button,
.heading-actions .ghost-button {
  height: 42px;
  padding: 0 14px;
}

.wrong-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px));
  gap: 12px;
  margin: 12px 0 18px;
}

.wrong-summary div {
  border: 1px solid var(--line);
  background: var(--white);
  padding: 12px 14px;
}

.wrong-summary strong {
  display: block;
  font-size: 28px;
  color: var(--teal);
}

.wrong-summary span {
  color: var(--muted);
  font-size: 14px;
}

.word-list-heading {
  margin-top: 10px;
  color: var(--ink);
  font-weight: 800;
}

.word-row {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 2fr 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  padding: 12px 14px;
}

.word-row strong {
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
}

.word-row span {
  color: var(--muted);
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(23, 33, 31, 0.42);
}

.modal-backdrop.hidden {
  display: none;
}

.lesson-modal {
  width: min(860px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(23, 33, 31, 0.22);
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 4px 0 0;
  font-size: 28px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.modal-meta {
  color: var(--muted);
  font-size: 13px;
}

.lesson-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.lesson-action {
  min-height: 112px;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 16px;
  text-align: left;
}

.lesson-action:hover,
.lesson-action:focus {
  border-color: var(--teal);
  outline: 2px solid rgba(15, 118, 110, 0.14);
}

.lesson-action strong {
  display: block;
  margin-bottom: 8px;
  color: var(--teal);
  font-size: 20px;
}

.lesson-action span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

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

.lesson-word {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 10px 12px;
}

.lesson-word strong {
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}

.lesson-word span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
}

body.device-ipad .app-shell {
  grid-template-columns: minmax(220px, 248px) 1fr;
}

body.device-ipad .sidebar {
  padding: 22px 16px;
  gap: 18px;
}

body.device-ipad .workspace {
  padding: 24px 24px max(24px, env(safe-area-inset-bottom));
}

body.device-ipad .topbar {
  height: auto;
  align-items: stretch;
  padding-bottom: 16px;
}

body.device-ipad .top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

body.device-ipad .dashboard-layout {
  grid-template-columns: 1fr;
}

body.device-ipad .group-grid {
  grid-template-columns: repeat(10, minmax(44px, 1fr));
}

body.device-ipad .group-cell {
  min-width: 52px;
  min-height: 52px;
  font-size: 15px;
}

body.device-ipad .icon-button,
body.device-ipad .ghost-button,
body.device-ipad .primary-button,
body.device-ipad .memory-actions button,
body.device-ipad .large-play {
  min-height: 50px;
}

body.device-ipad .icon-button {
  width: 50px;
}

body.device-ipad .study-card,
body.device-ipad .quiz-card {
  max-width: 980px;
  min-height: min(640px, calc(100dvh - 150px));
  padding: 30px;
}

body.device-ipad .answer-input {
  height: 64px;
  font-size: 26px;
}

body.device-ipad .blank-input {
  width: clamp(100px, 15vw, 164px);
  height: 54px;
  font-size: 22px;
}

body.device-computer .app-shell {
  grid-template-columns: 300px 1fr;
}

body.device-computer .workspace {
  padding: 30px 38px;
}

body.device-computer .dashboard-layout {
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
}

body.device-computer .group-grid {
  grid-template-columns: repeat(10, minmax(0, 1fr));
}

body.device-computer .study-card,
body.device-computer .quiz-card {
  max-width: 880px;
}

@media (min-width: 901px) and (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 248px 1fr;
  }

  .sidebar {
    padding: 22px 16px;
    gap: 18px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand h1 {
    font-size: 19px;
  }

  .workspace {
    padding: 24px 24px max(24px, env(safe-area-inset-bottom));
  }

  .topbar {
    height: auto;
    align-items: stretch;
    padding-bottom: 16px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .group-grid {
    grid-template-columns: repeat(10, minmax(44px, 1fr));
  }

  .study-card,
  .quiz-card {
    min-height: min(620px, calc(100dvh - 150px));
  }

  .blank-input {
    width: clamp(96px, 15vw, 156px);
  }
}

@media (max-width: 900px) {
  body.device-ipad .app-shell,
  .app-shell {
    grid-template-columns: 1fr;
  }

  body.device-ipad .sidebar,
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: max(18px, env(safe-area-inset-top)) 16px 18px;
    gap: 16px;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab {
    text-align: center;
    padding: 0 6px;
  }

  .workspace {
    padding: 22px 16px max(22px, env(safe-area-inset-bottom));
  }

  .topbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
    padding-bottom: 16px;
  }

  .top-actions {
    flex-wrap: wrap;
  }

  .dashboard-layout,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .group-grid {
    grid-template-columns: repeat(10, minmax(44px, 1fr));
    gap: 7px;
  }

  .study-card,
  .quiz-card {
    max-width: none;
    min-height: auto;
    padding: 22px;
  }

  .prompt {
    margin-top: 28px;
    font-size: 24px;
  }

  .large-play {
    min-height: 88px;
    margin-top: 30px;
  }

  .word-row {
    grid-template-columns: 1fr;
  }

  .lesson-actions,
  .lesson-word-list,
  .lesson-word {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .brand h1 {
    font-size: 19px;
  }

  .topbar h2 {
    font-size: 26px;
  }

  .section-heading,
  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .quiz-actions,
  .memory-actions,
  .voice-row {
    align-items: stretch;
  }

  .top-actions > *,
  .quiz-actions > *,
  .memory-actions > *,
  .voice-row > * {
    flex: 1 1 auto;
  }

  .group-grid {
    grid-template-columns: repeat(5, minmax(48px, 1fr));
  }

  .blank-grid {
    padding: 12px;
    gap: 8px;
  }

  .blank-input {
    width: clamp(76px, 28vw, 120px);
  }
}

@media (max-width: 900px) {
  body.device-computer .app-shell {
    grid-template-columns: 1fr;
  }

  body.device-computer .dashboard-layout {
    grid-template-columns: 1fr;
  }
}
