:root {
  color-scheme: light;
  --ink: #25324d;
  --paper: #fffdf8;
  --sky: #9edcf5;
  --mint: #8ee3bd;
  --coral: #ff7f73;
  --lemon: #ffe066;
  --blue: #46bfcf;
  --violet: #8d78c8;
  --shadow: rgba(37, 50, 77, 0.22);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

img,
svg {
  max-width: 100%;
}

main,
.dashboard,
.activity-frame,
.panel,
.mini-card,
.task-card,
.reading-card,
.writer-card,
.grid-2,
.grid-3,
.char-grid,
.measure-grid,
.tag-grid,
.topic-grid,
.writer-grid,
.mission-nav,
.chip-bank,
.choice-row {
  min-width: 0;
}

body {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(255, 224, 102, 0.22) 1px, transparent 1px),
    linear-gradient(rgba(70, 191, 207, 0.16) 1px, transparent 1px),
    #f5fbff;
  background-size: 34px 34px;
  -webkit-tap-highlight-color: transparent;
}

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

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

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

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

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 72px;
  height: 72px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--ink);
  object-fit: cover;
}

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

.brand strong {
  font-size: 2rem;
  line-height: 1.05;
}

.brand small {
  margin-top: 6px;
  font-size: 0.95rem;
  font-weight: 800;
  color: #50617f;
}

.grade-switch,
.topbar-actions,
.mode-tabs,
.action-row,
.chip-bank,
.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.grade-btn,
.view-mode-btn,
.tab-btn,
.tiny-btn,
.primary-btn,
.secondary-btn,
.choice-btn,
.chip,
.blank-slot {
  min-height: 52px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.grade-btn,
.view-mode-btn,
.tab-btn,
.tiny-btn,
.primary-btn,
.secondary-btn,
.choice-btn {
  padding: 12px 16px;
}

.grade-btn:hover,
.view-mode-btn:hover,
.tab-btn:hover,
.tiny-btn:hover,
.primary-btn:hover,
.secondary-btn:hover,
.choice-btn:hover,
.chip:hover,
.blank-slot:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--ink);
}

.grade-btn.is-active,
.view-mode-btn.is-active,
.tab-btn.is-active,
.mission-btn.is-active {
  background: var(--lemon);
}

main {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  align-items: start;
}

.dashboard,
.activity-frame,
.panel,
.mini-card,
.task-card,
.reading-card,
.writer-card {
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 0 var(--ink);
}

.dashboard {
  position: sticky;
  top: 16px;
  padding: 14px;
}

.score-card {
  min-height: 124px;
  padding: 18px;
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  background: #eafff8;
}

.score-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
  color: #50617f;
}

.score-card strong {
  display: block;
  margin: 6px 0 14px;
  font-size: 2.5rem;
  line-height: 1;
}

.progress-track {
  overflow: hidden;
  height: 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #ffffff;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--coral), var(--lemon), var(--mint));
  transition: width 250ms ease;
}

.mission-nav {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  width: 100%;
}

.mission-btn {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 62px;
  padding: 9px 10px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  font-weight: 950;
  box-shadow: 0 5px 0 var(--ink);
}

.mission-icon {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--mint);
}

.activity-frame {
  min-height: 720px;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(142, 227, 189, 0.28), transparent 38%),
    linear-gradient(315deg, rgba(255, 127, 115, 0.16), transparent 34%),
    var(--paper);
}

.section-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
}

.section-head h1 {
  margin: 0;
  font-size: 2.5rem;
  letter-spacing: 0;
}

.section-head p {
  margin: 8px 0 0;
  max-width: 64ch;
  color: #566783;
  font-weight: 700;
  line-height: 1.7;
}

.section-sticker {
  display: grid;
  place-items: center;
  width: 94px;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--lemon);
  box-shadow: 0 6px 0 var(--ink);
  font-size: 2.4rem;
  font-weight: 950;
}

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

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

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

.panel {
  padding: 16px;
}

.panel h2,
.reading-card h2,
.writer-card h2,
.task-card h2,
.mini-card h3,
.task-card h3,
.reading-card h3,
.writer-card h3 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.mini-card,
.task-card,
.reading-card,
.writer-card {
  padding: 14px;
  box-shadow: 0 5px 0 var(--ink);
}

.char-card {
  min-height: 186px;
  padding: 16px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 5px 0 var(--ink);
  text-align: left;
}

.char-card.is-active {
  background: #fff4be;
}

.char-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 3.4rem;
  line-height: 1;
}

.char-card span {
  display: block;
  color: #566783;
  font-weight: 800;
  line-height: 1.55;
}

.char-card small {
  display: block;
  margin-top: 10px;
  color: #965f00;
  font-weight: 900;
  line-height: 1.5;
}

.field-stack {
  display: grid;
  gap: 10px;
}

.field-stack label {
  display: grid;
  gap: 6px;
  color: #40506d;
  font-weight: 950;
}

.text-input,
.text-area {
  width: 100%;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  outline: none;
}

.text-input {
  min-height: 56px;
  padding: 12px 14px;
}

.text-area {
  min-height: 118px;
  padding: 12px;
  resize: vertical;
  line-height: 1.7;
}

.primary-btn {
  background: var(--coral);
  color: #ffffff;
}

.secondary-btn {
  background: var(--mint);
}

.tiny-btn {
  min-height: 38px;
  padding: 8px 10px;
  box-shadow: 0 3px 0 var(--ink);
}

.challenge-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #eaf7ff;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.7);
}

.big-prompt {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 16px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--lemon);
  font-size: 2.35rem;
  font-weight: 950;
  text-align: center;
}

.typo-prompt {
  font-size: 1.6rem;
  line-height: 1.55;
}

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.letter-tile,
.answer-tile {
  display: grid;
  place-items: center;
  min-width: 54px;
  height: 58px;
  padding: 0 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 4px 0 var(--ink);
  font-size: 1.35rem;
  font-weight: 950;
}

.letter-tile:disabled {
  opacity: 0.28;
  transform: translateY(4px);
  box-shadow: none;
}

.answer-strip {
  display: flex;
  gap: 8px;
  min-height: 62px;
  padding: 8px;
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.answer-tile {
  background: #fff4be;
}

.chip-bank {
  padding: 12px;
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  background: #f1fff9;
}

.chip {
  padding: 10px 14px;
  min-height: 50px;
}

.chip.is-selected {
  background: var(--lemon);
  transform: translateY(-2px);
}

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

.measure-item {
  display: grid;
  gap: 8px;
  min-height: 110px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
}

.measure-item strong {
  font-size: 1.05rem;
  line-height: 1.35;
}

.blank-slot {
  width: 100%;
  background: #f6f8ff;
}

.blank-slot.has-value {
  background: #fff4be;
}

.reading-visual {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--ink);
}

.passage {
  max-height: 310px;
  overflow: auto;
  padding: 14px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  line-height: 1.85;
  font-weight: 700;
}

.choice-row {
  margin: 10px 0 16px;
}

.choice-btn {
  flex: 1 1 210px;
  background: #ffffff;
  text-align: left;
}

.choice-btn.is-correct {
  background: var(--mint);
}

.choice-btn.is-wrong {
  background: #ffd2cf;
}

.sequence-pool,
.sequence-answer {
  display: grid;
  gap: 10px;
}

.sequence-card {
  width: 100%;
  min-height: 60px;
  padding: 12px 14px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 4px 0 var(--ink);
  text-align: left;
  font-weight: 900;
}

.sequence-answer {
  min-height: 160px;
  padding: 12px;
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  background: #f7fff8;
}

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

.drop-zone {
  min-height: 230px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
}

.drop-zone h3 {
  margin: 0 0 10px;
}

.claim-card {
  width: 100%;
  min-height: 64px;
  margin-bottom: 10px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #f6f8ff;
  box-shadow: 0 3px 0 var(--ink);
  text-align: left;
  font-weight: 850;
  line-height: 1.45;
}

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

.topic-btn {
  min-height: 96px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 5px 0 var(--ink);
  color: var(--ink);
  font-weight: 950;
  line-height: 1.35;
}

.topic-btn.is-active {
  background: var(--lemon);
}

.writer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.prompt-list {
  display: grid;
  gap: 12px;
}

.preview-paper {
  min-height: 520px;
  padding: 18px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(#fff 0 34px, #e7f0ff 35px 36px),
    #ffffff;
  line-height: 36px;
  font-weight: 800;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(360px, calc(100vw - 36px));
  padding: 14px 16px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--lemon);
  box-shadow: 0 6px 0 var(--ink);
  font-weight: 950;
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

body.is-view-mode {
  background-size: 42px 42px;
}

body.is-view-mode .topbar,
body.is-view-mode main {
  max-width: 1560px;
}

body.is-view-mode main {
  grid-template-columns: 1fr;
}

body.is-view-mode .dashboard {
  position: static;
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  align-items: stretch;
  gap: 14px;
}

body.is-view-mode .mission-nav {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 0;
}

body.is-view-mode .mission-btn {
  min-height: 78px;
}

body.is-view-mode .activity-frame {
  min-height: calc(100vh - 250px);
}

body.is-view-mode .passage {
  max-height: none;
}

body.is-view-mode .grid-2 {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.7fr);
}

@media (pointer: coarse) {
  .grade-btn,
  .view-mode-btn,
  .tab-btn,
  .tiny-btn,
  .primary-btn,
  .secondary-btn,
  .choice-btn,
  .chip,
  .blank-slot {
    min-height: 58px;
  }

  .mission-btn {
    min-height: 72px;
  }

  .mission-icon {
    width: 48px;
  }

  .letter-tile,
  .answer-tile {
    min-width: 62px;
    height: 62px;
  }
}

@media (min-width: 1280px) {
  .topbar,
  main {
    max-width: 1320px;
  }

  .brand strong {
    font-size: 2.25rem;
  }

  .section-head h1 {
    font-size: 2.85rem;
  }

  .passage,
  .choice-btn,
  .sequence-card,
  .claim-card,
  .field-stack label {
    font-size: 1.08rem;
  }
}

@media (min-width: 1500px) {
  body {
    font-size: 18px;
  }

  .topbar,
  main {
    max-width: 1540px;
  }

  main {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 24px;
  }

  .app-shell {
    padding: 24px;
  }

  .activity-frame {
    min-height: 820px;
    padding: 34px;
  }

  .brand img {
    width: 86px;
    height: 86px;
  }

  .section-head h1 {
    font-size: 3.2rem;
  }

  .section-head p {
    font-size: 1.18rem;
  }

  .section-sticker {
    width: 112px;
    font-size: 3rem;
  }

  .grade-btn,
  .view-mode-btn,
  .tab-btn,
  .primary-btn,
  .secondary-btn,
  .choice-btn {
    min-height: 64px;
    padding: 14px 20px;
  }

  .mission-btn {
    min-height: 82px;
    grid-template-columns: 54px 1fr;
    font-size: 1.08rem;
  }

  .mission-icon {
    width: 54px;
  }

  .char-card {
    min-height: 214px;
  }

  .char-card strong {
    font-size: 4rem;
  }

  .big-prompt {
    min-height: 150px;
    font-size: 3rem;
  }

  .typo-prompt {
    font-size: 2rem;
  }

  .letter-tile,
  .answer-tile {
    min-width: 72px;
    height: 72px;
    font-size: 1.75rem;
  }

  .passage {
    max-height: 420px;
  }
}

@media (min-width: 1500px) and (pointer: coarse) {
  body {
    font-size: 20px;
  }

  .topbar,
  main,
  body.is-view-mode .topbar,
  body.is-view-mode main {
    max-width: 1760px;
  }

  .activity-frame {
    min-height: 900px;
  }

  .mission-btn {
    min-height: 94px;
  }

  .grade-btn,
  .view-mode-btn,
  .tab-btn,
  .primary-btn,
  .secondary-btn,
  .choice-btn,
  .chip,
  .blank-slot {
    min-height: 72px;
  }
}

@media (max-width: 1100px) {
  .topbar,
  main,
  .section-head,
  .grid-2,
  .grid-3,
  .writer-grid,
  body.is-view-mode .grid-2 {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: start;
  }

  .dashboard,
  body.is-view-mode .dashboard {
    position: static;
    display: block;
  }

  .mission-nav,
  body.is-view-mode .mission-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 16px;
  }

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

@media (max-width: 700px) {
  .app-shell {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .topbar {
    gap: 12px;
  }

  .brand img {
    width: 58px;
    height: 58px;
    box-shadow: 0 4px 0 var(--ink);
  }

  .brand strong {
    font-size: 1.55rem;
  }

  .brand small {
    font-size: 0.86rem;
  }

  .topbar-actions,
  .grade-switch {
    width: 100%;
  }

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

  .view-mode-btn {
    width: 100%;
  }

  .dashboard,
  .activity-frame,
  .panel,
  .mini-card,
  .task-card,
  .reading-card,
  .writer-card {
    box-shadow: 0 5px 0 var(--ink);
  }

  .score-card {
    min-height: 92px;
    padding: 12px;
  }

  .score-card strong {
    font-size: 2rem;
  }

  .mission-nav,
  body.is-view-mode .mission-nav {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 0 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .mission-btn {
    flex: 0 0 168px;
    grid-template-columns: 42px 1fr;
    scroll-snap-align: start;
  }

  .activity-frame {
    min-height: 0;
    padding: 16px;
  }

  .section-head {
    gap: 12px;
  }

  .section-head h1 {
    font-size: 2rem;
  }

  .section-head p {
    font-size: 1rem;
  }

  .section-sticker {
    width: 74px;
    font-size: 2rem;
  }

  .mode-tabs,
  .action-row,
  .choice-row,
  .chip-bank {
    gap: 8px;
  }

  .tab-btn,
  .primary-btn,
  .secondary-btn,
  .choice-btn,
  .chip,
  .blank-slot {
    width: 100%;
  }

  .char-grid,
  .measure-grid,
  .tag-grid,
  .topic-grid {
    grid-template-columns: 1fr;
  }

  .char-card {
    min-height: 152px;
  }

  .char-card strong {
    font-size: 3rem;
  }

  .big-prompt {
    min-height: 96px;
    font-size: 1.8rem;
  }

  .typo-prompt {
    font-size: 1.2rem;
  }

  .letter-tile,
  .answer-tile {
    min-width: 52px;
    height: 54px;
    font-size: 1.2rem;
  }

  .passage {
    max-height: none;
  }

  .preview-paper {
    min-height: 360px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }
}
