:root {
  --bg: #f5f2eb;
  --paper: #fffdf8;
  --ink: #24211d;
  --muted: #6f675d;
  --line: #ded6c8;
  --accent: #176b61;
  --accent-dark: #104f48;
  --blue: #2f5f9f;
  --gold: #b87a29;
  --rose: #a73f52;
  --green-soft: #edf7f4;
  --blue-soft: #eef4ff;
  --shadow: 0 18px 42px rgba(43, 36, 26, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(23, 107, 97, 0.08), transparent 32%),
    linear-gradient(45deg, transparent 62%, rgba(47, 95, 159, 0.1)),
    var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

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

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto 18px;
}

.topbar > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
}

.session-panel,
.detail-actions,
.modal-actions,
.admin-head,
.combo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.session-panel,
.detail-actions,
.modal-actions {
  justify-content: flex-end;
}

.session-panel {
  max-width: 760px;
}

#sessionLabel,
.small-muted {
  color: var(--muted);
  font-size: 13px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.choice-btn,
.tab-btn {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--accent);
  color: white;
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.ghost-btn {
  background: rgba(255, 253, 248, 0.76);
  color: var(--ink);
  border-color: var(--line);
}

.danger-btn {
  background: #fff4f4;
  border-color: #e0b9b9;
  color: #8b1f2b;
}

.workspace {
  display: grid;
  grid-template-columns: 188px minmax(280px, 400px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

.sidebar,
.catalog-column,
.detail-column {
  min-height: calc(100vh - 122px);
}

.section-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.section-title.spaced {
  margin-top: 16px;
}

.module-tabs,
.group-tabs,
.child-tabs,
.item-list {
  display: grid;
  gap: 8px;
}

.module-tab,
.group-tab,
.child-tab,
.item-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  color: var(--ink);
  text-align: left;
}

.module-tab,
.group-tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
}

.child-tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  background: rgba(239, 244, 255, 0.82);
}

.module-tab.active,
.group-tab.active {
  border-color: rgba(23, 107, 97, 0.35);
  background: var(--accent);
  color: white;
}

.stats-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
}

.stats-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stats-box strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
}

.catalog-column,
.study-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.catalog-column {
  overflow: hidden;
}

.column-head {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

#searchInput {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.item-list {
  max-height: calc(100vh - 236px);
  overflow: auto;
  padding: 12px;
}

.item-card {
  padding: 13px;
}

.item-card.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.item-card h3 {
  margin-bottom: 4px;
  font-size: 17px;
}

.card-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-topline span {
  flex: 0 0 auto;
  color: var(--accent-dark);
  font-weight: 700;
}

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

.progress-bar {
  height: 7px;
  margin: 10px 0 7px;
  border-radius: 999px;
  background: #ebe4d8;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

.study-panel {
  min-height: calc(100vh - 122px);
  padding: 20px;
}

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

.detail-title h2 {
  font-size: 28px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--green-soft);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.mode-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  background: white;
  border-color: var(--line);
  flex: 0 0 auto;
}

.tab-btn.active {
  border-color: var(--accent);
  background: rgba(23, 107, 97, 0.1);
  color: var(--accent-dark);
  font-weight: 700;
}

.challenge-card,
.word-stage,
.empty-state,
.note-item,
.flip-card,
.review-block,
.word-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}

.challenge-status {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.challenge-status strong {
  color: var(--accent-dark);
}

.answer-input {
  width: 100%;
  min-height: 86px;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}

.answer-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #f2f7f6;
  border: 1px solid #cfe3df;
  line-height: 1.7;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.text-block {
  padding: 14px;
  border-radius: 8px;
  background: #fbf6eb;
  border: 1px solid #eadfce;
  line-height: 1.9;
  white-space: pre-wrap;
}

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

.notes-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.note-term {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-weight: 700;
}

.word-stage {
  background:
    linear-gradient(160deg, rgba(47, 95, 159, 0.08), transparent 46%),
    white;
}

.combo-row {
  justify-content: space-between;
  margin-bottom: 12px;
}

.combo-row span {
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.scene-card {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 132px;
  margin-bottom: 12px;
  border: 1px solid #d7e2f6;
  border-radius: 8px;
  padding: 14px;
  background:
    linear-gradient(135deg, rgba(47, 95, 159, 0.12), transparent 58%),
    #f8fbff;
}

.scene-card h3 {
  margin-bottom: 0;
  line-height: 1.5;
}

.scene-mark {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-size: 42px;
  font-weight: 800;
}

.scene-card.has-image {
  display: block;
  padding: 0;
  overflow: hidden;
  background: white;
}

.scene-card.has-image img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.scene-card.has-image figcaption {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.word-card {
  display: grid;
  place-items: center;
  min-height: 150px;
  margin-bottom: 14px;
  border-radius: 8px;
  border: 1px solid #d7e2f6;
  background: #f8fbff;
}

.big-word {
  font-size: clamp(44px, 8vw, 86px);
  font-weight: 800;
  color: var(--blue);
  letter-spacing: 0;
}

.big-word.small {
  font-size: 34px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.choice-btn {
  min-height: 58px;
  background: white;
  border-color: #cad7ef;
  color: var(--ink);
  font-weight: 700;
}

.choice-btn:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.word-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  align-items: center;
}

.word-row p {
  grid-column: 1 / -1;
  margin: 0;
}

.admin-tools {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed rgba(23, 107, 97, 0.45);
  border-radius: 8px;
  background: rgba(23, 107, 97, 0.06);
}

.admin-tools .ghost-btn {
  margin-top: 8px;
}

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

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

.span-2 {
  grid-column: 1 / -1;
}

.modal {
  width: min(430px, calc(100vw - 32px));
  max-height: calc(100dvh - 28px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.wide-modal {
  width: min(980px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(28, 25, 20, 0.42);
}

.modal form {
  display: grid;
  gap: 14px;
  padding: 22px;
  max-height: calc(100dvh - 28px);
  overflow: auto;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

label input,
label textarea,
label select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: white;
  font-weight: 400;
}

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

.admin-section {
  display: grid;
  gap: 12px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-head {
  justify-content: space-between;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--rose);
  font-size: 14px;
}

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

.speech-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 30;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .catalog-column,
  .detail-column,
  .study-panel {
    min-height: auto;
  }

  .module-tabs,
  .group-tabs {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .child-tabs {
    grid-template-columns: 1fr;
  }

  .item-list {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 12px 12px calc(80px + env(safe-area-inset-bottom));
  }

  .topbar,
  .detail-head,
  .admin-head,
  .review-grid {
    display: grid;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  .eyebrow {
    font-size: 12px;
  }

  .session-panel,
  .detail-actions,
  .modal-actions {
    justify-content: stretch;
  }

  .session-panel button,
  .detail-actions button,
  .modal-actions button {
    width: 100%;
  }

  .session-panel {
    width: 100%;
    max-width: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #activeChildLabel {
    grid-column: 1 / -1;
    font-size: 13px;
  }

  .workspace {
    gap: 12px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -12px;
    padding: 10px 12px;
    background: rgba(245, 242, 235, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }

  .stats-box {
    display: none;
  }

  .module-tabs,
  .group-tabs,
  .child-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .module-tab,
  .group-tab,
  .child-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 132px;
    white-space: nowrap;
  }

  .section-title {
    margin: 9px 0 7px;
  }

  .module-tabs,
  .group-tabs,
  .form-grid,
  .option-grid,
  .word-row {
    grid-template-columns: 1fr;
  }

  .catalog-column,
  .study-panel {
    box-shadow: none;
  }

  .column-head,
  .study-panel {
    padding: 14px;
  }

  .item-list {
    padding: 10px;
  }

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

  .scene-card {
    grid-template-columns: 64px 1fr;
    min-height: 104px;
    padding: 12px;
  }

  .scene-mark {
    width: 58px;
    height: 58px;
    font-size: 32px;
  }

  .scene-card.has-image img {
    height: 170px;
  }

  .word-card {
    min-height: 126px;
  }

  .challenge-status,
  .card-topline,
  .combo-row,
  .manager-row {
    display: grid;
  }

  h1 {
    font-size: 25px;
  }

  .detail-title h2 {
    font-size: 24px;
  }

  .big-word {
    font-size: 44px;
  }

  .big-word.small {
    font-size: 28px;
  }

  .modal {
    width: calc(100vw - 20px);
    border-radius: 8px;
  }

  .modal form {
    padding: 18px;
  }

  .speech-fab {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 420px) {
  .session-panel {
    grid-template-columns: 1fr;
  }

  .module-tab,
  .group-tab,
  .child-tab {
    min-width: 116px;
  }

  .primary-btn,
  .ghost-btn,
  .danger-btn,
  .choice-btn,
  .tab-btn {
    padding: 0 11px;
  }
}
