:root {
  --bg: #151311;
  --panel: #211f1b;
  --panel-strong: #2b2822;
  --panel-soft: #342f27;
  --line: rgba(255, 255, 255, 0.11);
  --text: #fbf7ee;
  --muted: #b9b0a2;
  --faint: #847a6d;
  --accent: #8ed39f;
  --accent-strong: #54b86c;
  --gold: #e7c46c;
  --coral: #ff8c74;
  --bad: #ff6f6f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(21, 19, 17, 0.94), rgba(25, 23, 20, 0.9)),
    url("./assets/math-pattern.svg") center top / min(1000px, 150vw) auto no-repeat,
    var(--bg);
  font-family: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

body.is-study-mode,
body.is-sheet-open {
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 0 calc(40px + var(--safe-bottom));
}

.is-study-mode .page-shell {
  width: 100%;
  height: 100svh;
  padding: calc(8px + var(--safe-top)) 12px calc(10px + var(--safe-bottom));
}

.content,
.view-section {
  display: grid;
  gap: 18px;
}

.view-section[hidden],
.answer-sheet[hidden],
.toast[hidden],
.answer-panel[hidden] {
  display: none !important;
}

.is-study-mode .content,
.is-study-mode .study-view {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.is-study-mode .study-view {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.app-topbar,
.study-topbar,
.overview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.app-topbar {
  padding: 8px 2px 4px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.home-hero,
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 17px 18px;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(142, 211, 159, 0.11), rgba(255, 140, 116, 0.07)),
    rgba(255, 255, 255, 0.045);
  box-shadow: var(--shadow);
}

.home-hero strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: clamp(1.2rem, 2.6vw, 1.85rem);
}

.hero-kicker,
.summary-label,
.search-label,
.panel-kicker {
  color: var(--muted);
  font-size: 0.9rem;
}

.hero-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-stats span,
.day-card span,
.day-pill,
.section-pill,
.order-pill,
.result-pill,
.overview-chip,
.question-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.075);
}

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

.day-card {
  min-height: 144px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  text-align: left;
  background: linear-gradient(150deg, #29251f, #1d1a17);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.day-card:hover {
  border-color: rgba(142, 211, 159, 0.46);
  transform: translateY(-2px);
}

.day-card strong {
  display: block;
  margin-top: 24px;
  color: var(--text);
  font-size: 1.7rem;
}

.day-card em {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-style: normal;
}

.day-card.is-complete {
  border-color: rgba(142, 211, 159, 0.52);
  background: linear-gradient(150deg, rgba(56, 107, 66, 0.65), #1d1a17);
}

.icon-button,
.icon-text-button,
.primary-button,
.ghost-button,
.overview-chip,
.answer-number-button,
.inline-link-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.065);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  font-size: 1.55rem;
  line-height: 1;
}

.icon-text-button,
.primary-button,
.ghost-button,
.inline-link-button {
  min-height: 42px;
  border-radius: 999px;
  padding: 10px 14px;
}

.primary-button {
  border-color: rgba(142, 211, 159, 0.55);
  color: #102015;
  font-weight: 700;
  background: linear-gradient(135deg, #9ce2a9, #e7c46c);
}

.ghost-button {
  color: var(--muted);
}

.inline-link-button {
  color: var(--accent);
}

.icon-button:hover,
.icon-text-button:hover,
.primary-button:hover,
.ghost-button:hover,
.overview-chip:hover,
.answer-number-button:hover,
.inline-link-button:hover {
  transform: translateY(-1px);
  border-color: rgba(142, 211, 159, 0.45);
}

.study-topbar {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 2px 2px;
}

.study-heading,
.overview-heading {
  display: grid;
  gap: 2px;
  min-width: 84px;
  text-align: center;
}

.overview-heading {
  text-align: right;
}

.study-heading span,
.overview-heading span {
  color: var(--muted);
  font-size: 0.88rem;
}

.study-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.study-stage {
  display: grid;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.question-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #25221d, #1d1a17);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.question-card--study {
  align-self: stretch;
  justify-self: center;
  width: min(100%, 960px);
  min-height: 0;
}

.question-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 20px 0;
}

.question-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.day-pill {
  color: var(--accent);
  background: rgba(142, 211, 159, 0.12);
}

.section-pill {
  color: var(--gold);
  background: rgba(231, 196, 108, 0.12);
}

.result-pill.is-correct {
  color: #d8ffe0;
  background: rgba(84, 184, 108, 0.18);
}

.result-pill.is-wrong {
  color: #ffe0dc;
  background: rgba(255, 111, 111, 0.16);
}

.question-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-content: center;
  gap: 18px;
  padding: clamp(24px, 5vw, 58px) 20px;
}

.question-title {
  margin: 0;
  color: #fffaf0;
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 1.18;
  letter-spacing: 0;
  text-align: center;
  overflow-wrap: anywhere;
}

.answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  width: min(100%, 640px);
  justify-self: center;
}

.answer-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.answer-field input,
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.answer-field input {
  min-height: 52px;
  padding: 12px 14px;
  font-size: 1.35rem;
  text-align: center;
}

.search-box {
  display: grid;
  gap: 8px;
}

.search-box input {
  min-height: 48px;
  padding: 12px 14px;
}

.answer-field input:focus,
.search-box input:focus {
  border-color: rgba(142, 211, 159, 0.65);
  box-shadow: 0 0 0 3px rgba(142, 211, 159, 0.12);
}

.check-status {
  min-height: 28px;
  margin: 0;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.check-status.is-correct {
  color: #bdf1c7;
}

.check-status.is-wrong {
  color: #ffb8b0;
}

.answer-panel {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(231, 196, 108, 0.28);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--muted);
  background: rgba(231, 196, 108, 0.09);
}

.answer-panel strong {
  color: var(--gold);
  font-size: 1.35rem;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 20px 20px;
}

.ghost-button:disabled,
.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.day-filter-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 8px;
  scrollbar-width: thin;
}

.overview-chip {
  flex: 0 0 auto;
  min-height: 38px;
}

.overview-chip.is-active {
  border-color: rgba(142, 211, 159, 0.58);
  color: #102015;
  background: var(--accent);
}

.summary-bar strong {
  color: var(--text);
}

.question-grid {
  display: grid;
  gap: 12px;
}

.question-grid--overview {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.overview-card {
  display: grid;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.045);
}

.overview-card.is-correct {
  border-color: rgba(142, 211, 159, 0.42);
}

.overview-card.is-wrong {
  border-color: rgba(255, 111, 111, 0.38);
}

.overview-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.question-chip {
  min-height: 28px;
  padding: 5px 9px;
  font-size: 0.86rem;
}

.overview-question {
  margin: 0;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1.55;
}

.overview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.overview-answer {
  margin: 0;
  color: var(--gold);
  line-height: 1.6;
}

.empty-state,
.no-script {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
}

.empty-state p {
  color: var(--muted);
}

.answer-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.58);
}

.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  width: min(760px, calc(100% - 20px));
  max-height: min(74svh, 640px);
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  background: #1d1a17;
  box-shadow: 0 -30px 80px rgba(0, 0, 0, 0.48);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.sheet-header h2,
.sheet-header p {
  margin: 0;
}

.sheet-header p {
  color: var(--muted);
  line-height: 1.6;
}

.answer-number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 2px 4px;
}

.answer-number-button {
  position: relative;
  min-height: 48px;
  border-radius: 8px;
}

.answer-number-button.is-current {
  border-color: rgba(231, 196, 108, 0.68);
  color: var(--bg);
  background: var(--gold);
}

.answer-number-button.is-correct::after,
.answer-number-button.is-wrong::after,
.answer-number-button.is-answered::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
}

.answer-number-button.is-correct::after {
  background: var(--accent);
}

.answer-number-button.is-wrong::after {
  background: var(--bad);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  z-index: 30;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  color: white;
  background: rgba(29, 26, 23, 0.94);
  box-shadow: var(--shadow);
}

@media (min-width: 900px) {
  .is-study-mode .page-shell {
    padding-left: 28px;
    padding-right: 28px;
  }

  .question-card--study {
    width: min(86vw, 1080px);
  }
}

@media (max-width: 760px) {
  .app-topbar,
  .home-hero,
  .overview-topbar,
  .summary-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .overview-heading {
    text-align: left;
  }

  .day-grid {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  }

  .study-actions {
    gap: 5px;
  }

  .study-actions .icon-text-button {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .question-toolbar-row {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px 16px 0;
  }

  .question-body {
    padding: 22px 16px;
  }

  .question-title {
    font-size: 2.2rem;
    text-align: left;
  }

  .answer-form {
    grid-template-columns: 1fr;
  }

  .card-footer {
    padding: 0 16px 16px;
  }
}

@media (max-width: 520px) {
  .page-shell {
    width: min(100% - 18px, 1180px);
    padding-top: calc(16px + var(--safe-top));
  }

  .is-study-mode .page-shell {
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }

  .study-topbar {
    gap: 8px;
  }

  .study-heading {
    min-width: 66px;
  }

  .study-heading strong {
    font-size: 0.96rem;
  }

  .study-heading span {
    font-size: 0.76rem;
  }

  .card-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #revealAnswerButton {
    grid-column: 1 / -1;
    order: -1;
  }

  .sheet-panel {
    width: min(100% - 14px, 760px);
    padding: 18px 14px calc(18px + var(--safe-bottom));
  }

  .answer-number-grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 8px;
  }

  .answer-number-button {
    min-height: 44px;
  }
}
