:root {
  color-scheme: light;
  --bg: #edf2ef;
  --surface: #fbfdfb;
  --surface-strong: #ffffff;
  --ink: #18211f;
  --muted: #61706b;
  --line: #d8e1dc;
  --green: #2d8768;
  --green-dark: #176049;
  --teal: #237e92;
  --blue: #335d9b;
  --rust: #b95f34;
  --gold: #d49a2f;
  --danger: #c84c43;
  --shadow: 0 18px 40px rgba(32, 47, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(45, 135, 104, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(185, 95, 52, 0.14), transparent 32%),
    var(--bg);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.game-topbar,
.course-strip,
.mission-panel,
.board-wrap,
.review-panel {
  border: 1px solid rgba(216, 225, 220, 0.9);
  background: rgba(251, 253, 251, 0.92);
  box-shadow: var(--shadow);
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px;
  border-radius: 8px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mark {
  position: relative;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #123a33;
  overflow: hidden;
}

.mark span {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.92);
  transform: rotate(45deg);
}

.mark span:nth-child(1) {
  left: -4px;
  top: 12px;
  border-color: #7fc6a4;
}

.mark span:nth-child(2) {
  left: 18px;
  top: -3px;
  border-color: #efd087;
}

.mark span:nth-child(3) {
  left: 24px;
  top: 27px;
  border-color: #eaa171;
}

.eyebrow,
.panel-label {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 10px;
  width: min(420px, 46vw);
}

.stat {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 25px;
  line-height: 1;
}

.course-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
  padding: 8px;
  border-radius: 8px;
}

.subject-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.subject-tab:hover,
.subject-tab:focus-visible {
  border-color: rgba(45, 135, 104, 0.35);
  outline: none;
}

.subject-tab.active {
  color: #ffffff;
  background: var(--green-dark);
}

.tab-icon {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: currentColor;
}

.icon-all {
  clip-path: polygon(0 0, 45% 0, 45% 45%, 100% 45%, 100% 100%, 0 100%);
}

.icon-english {
  clip-path: polygon(50% 0, 100% 82%, 0 82%);
}

.icon-chinese {
  border-radius: 50%;
  clip-path: none;
}

.icon-math {
  clip-path: polygon(0 0, 100% 0, 100% 22%, 58% 22%, 58% 100%, 42% 100%, 42% 22%, 0 22%);
}

.stage {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.mission-panel,
.board-wrap,
.review-panel {
  border-radius: 8px;
}

.mission-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.mission-visual {
  border-radius: 8px;
  background: #e2ebe5;
  overflow: hidden;
}

.mission-visual svg {
  display: block;
  width: 100%;
  height: auto;
}

.land {
  fill: #c7d9c9;
}

.river {
  fill: none;
  stroke: var(--teal);
  stroke-width: 7;
  stroke-linecap: round;
}

.cell {
  fill: none;
  stroke: var(--green);
  stroke-width: 5;
}

.timeline {
  stroke: var(--rust);
  stroke-width: 6;
  stroke-linecap: round;
}

.node {
  fill: var(--gold);
  stroke: #fff7df;
  stroke-width: 3;
}

.mission-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.mission-list {
  display: grid;
  gap: 8px;
}

.mission-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
}

.mission-item strong {
  color: var(--ink);
}

.action-stack {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border-radius: 8px;
  cursor: pointer;
}

.primary-action {
  border: 0;
  color: #ffffff;
  background: var(--green);
}

.primary-action:hover,
.primary-action:focus-visible {
  background: var(--green-dark);
  outline: none;
}

.secondary-action {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

.secondary-action:hover,
.secondary-action:focus-visible {
  border-color: rgba(45, 135, 104, 0.5);
  outline: none;
}

.action-icon {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
}

.plus-icon,
.download-icon,
.upload-icon,
.manage-icon {
  position: relative;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.plus-icon::before,
.plus-icon::after {
  position: absolute;
  content: "";
  background: currentColor;
}

.plus-icon::before {
  left: 2px;
  right: 2px;
  top: 7px;
  height: 2px;
}

.plus-icon::after {
  top: 2px;
  bottom: 2px;
  left: 7px;
  width: 2px;
}

.download-icon,
.upload-icon {
  border: 2px solid currentColor;
  border-top: 0;
}

.download-icon::before,
.upload-icon::before {
  position: absolute;
  left: 5px;
  width: 0;
  height: 0;
  content: "";
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
}

.download-icon::before {
  top: 4px;
  border-top: 6px solid currentColor;
}

.upload-icon::before {
  top: 0;
  border-bottom: 6px solid currentColor;
}

.manage-icon {
  border: 2px solid currentColor;
  border-radius: 3px;
}

.manage-icon::before,
.manage-icon::after {
  position: absolute;
  left: 3px;
  right: 3px;
  height: 2px;
  content: "";
  background: currentColor;
}

.manage-icon::before {
  top: 4px;
}

.manage-icon::after {
  bottom: 4px;
}

.board-wrap {
  min-width: 0;
  padding: 16px;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.round-badge {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 8px;
  color: #12443a;
  background: #dcf1e7;
  font-size: 13px;
  font-weight: 800;
}

.match-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-auto-rows: minmax(118px, auto);
  gap: 12px;
  min-height: 610px;
  padding: 12px;
  border: 1px solid rgba(18, 68, 58, 0.08);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(23, 96, 73, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(23, 96, 73, 0.05) 1px, transparent 1px),
    #f7faf7;
  background-size: 24px 24px;
  align-content: start;
}

.match-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 118px;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface-strong);
  box-shadow: 0 8px 18px rgba(37, 54, 49, 0.1);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    opacity 180ms ease,
    visibility 180ms ease;
}

.match-tile::after {
  content: "";
  position: absolute;
  right: -22px;
  bottom: -24px;
  width: 74px;
  height: 74px;
  border-radius: 999px;
  background: rgba(23, 96, 73, 0.08);
}

.match-tile:hover,
.match-tile:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(35, 126, 146, 0.5);
  outline: none;
}

.match-tile.selected {
  border-color: var(--blue);
  background: #edf4ff;
  box-shadow: 0 12px 26px rgba(35, 126, 146, 0.18);
}

.match-tile.matched {
  opacity: 0;
  transform: scale(0.72);
  cursor: default;
}

.match-tile.cleared {
  visibility: hidden;
  pointer-events: none;
}

.match-tile.wrong {
  animation: tile-shake 360ms ease;
  border-color: var(--danger);
  background: #fff0ef;
}

.subject-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 34px;
  border-radius: 8px;
  background: var(--green);
}

.match-tile .subject-dot {
  position: absolute;
  left: 12px;
  top: 12px;
}

.match-tile[data-subject="comprehensive"] .subject-dot {
  background: var(--teal);
}

.match-tile[data-subject="english"] .subject-dot {
  background: var(--green);
}

.match-tile[data-subject="chinese"] .subject-dot {
  background: var(--rust);
}

.match-tile[data-subject="math"] .subject-dot {
  background: var(--blue);
}

.match-tile[data-strand="biology"] .subject-dot {
  background: var(--green);
}

.match-tile[data-strand="history"] .subject-dot {
  background: var(--rust);
}

.match-tile[data-strand="calculation"] .subject-dot {
  background: var(--gold);
}

.empty-board {
  grid-column: 1 / -1;
  display: grid;
  min-height: 72px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.tile-role {
  align-self: flex-end;
  position: relative;
  z-index: 1;
  padding: 4px 8px;
  border-radius: 999px;
  color: #12443a;
  background: #dcf1e7;
  font-size: 11px;
  font-weight: 900;
}

.tile-text {
  position: relative;
  z-index: 1;
  display: block;
  min-width: 0;
  padding-left: 22px;
  font-size: 16px;
  font-weight: 750;
  line-height: 1.35;
  word-break: break-word;
}

.tile-meta {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

@keyframes tile-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  50% {
    transform: translateX(5px);
  }

  75% {
    transform: translateX(-3px);
  }
}

.review-panel {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
  padding: 16px;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.review-card {
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.review-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.review-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  transform: translateX(-50%) translateY(18px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #162521;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mistake-dialog {
  width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mistake-dialog::backdrop {
  background: rgba(15, 29, 25, 0.38);
}

.mistake-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-actions {
  justify-content: flex-end;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-strong);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--ink);
  border-color: rgba(45, 135, 104, 0.5);
  outline: none;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface-strong);
  font: inherit;
}

.field textarea {
  resize: vertical;
}

.manager-dialog {
  width: min(860px, calc(100vw - 24px));
}

.manager-shell {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.manager-summary {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 13px;
}

.manager-summary strong {
  color: var(--green-dark);
}

.manager-list {
  display: grid;
  gap: 10px;
  max-height: min(58vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.manager-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.manager-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.manager-card-meta strong {
  color: var(--green-dark);
}

.manager-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.manager-pair p {
  min-height: 58px;
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  color: var(--ink);
  background: #f5faf7;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.manager-pair span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.danger-action {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(194, 87, 51, 0.35);
  border-radius: 8px;
  color: var(--danger);
  background: #fff4f1;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.danger-action:hover,
.danger-action:focus-visible {
  border-color: var(--danger);
  outline: none;
}

.empty-manager {
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 14px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  outline: none;
}

@media (max-width: 980px) {
  .game-topbar,
  .stage,
  .review-panel {
    grid-template-columns: 1fr;
  }

  .game-topbar {
    display: grid;
  }

  .stats-grid {
    width: 100%;
  }

  .mission-panel {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    align-items: start;
  }

  .mission-list,
  .action-stack {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 18px, 520px);
    padding: 12px 0 24px;
  }

  .course-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    min-height: 58px;
    padding: 9px 8px;
  }

  .stat strong {
    font-size: 20px;
  }

  .mission-panel {
    grid-template-columns: 1fr;
  }

  .mission-visual {
    display: none;
  }

  .board-head {
    align-items: start;
  }

  .match-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(108px, auto);
    gap: 10px;
    min-height: auto;
    padding: 10px;
  }

  .match-tile {
    min-height: 108px;
    padding: 10px;
  }

  .subject-dot {
    width: 8px;
    height: 32px;
  }

  .match-tile .subject-dot {
    left: 10px;
    top: 10px;
  }

  .tile-text {
    font-size: 13px;
    padding-left: 18px;
  }

  .manager-card {
    grid-template-columns: 1fr;
  }

  .manager-pair {
    grid-template-columns: 1fr;
  }

  .danger-action {
    width: 100%;
  }

  .review-grid {
    grid-template-columns: 1fr;
  }
}
