:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef6f3;
  --ink: #173130;
  --muted: #667776;
  --line: #d8e3e1;
  --primary: #256c6a;
  --primary-strong: #184f4d;
  --accent: #d9654f;
  --gold: #f3bf4f;
  --blue: #4f7fc8;
  --green: #4f9f6f;
  --shadow: 0 18px 50px rgba(22, 49, 48, 0.12);
  --radius: 8px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(79, 159, 111, 0.12), transparent 360px),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 22px clamp(16px, 4vw, 44px) 36px;
}

.app-shell[data-theme="sunrise"] {
  --primary: #a8533f;
  --primary-strong: #793a2b;
  --surface-strong: #fff4e2;
  --accent: #2f7b83;
}

.app-shell[data-theme="ocean"] {
  --primary: #286b8c;
  --primary-strong: #1d4e66;
  --surface-strong: #ecf7fb;
  --accent: #b35d49;
}

.app-shell[data-theme="graphite"] {
  --primary: #3f5853;
  --primary-strong: #293a37;
  --surface-strong: #eef0ec;
  --accent: #bd693e;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.4rem, 2.3vw, 2.1rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 1.7vw, 1.7rem);
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.top-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-stats span,
.reward-balance,
.metric-row div {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  border-radius: var(--radius);
}

.top-stats span {
  padding: 8px 10px;
  color: var(--muted);
  white-space: nowrap;
}

.top-stats strong {
  color: var(--ink);
}

.icon-button,
.tab-button,
.primary-button,
.secondary-button,
.ghost-button,
.answer-button,
.file-button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ghost-button {
  width: 44px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--line);
}

.tabbar {
  max-width: 1180px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab-button {
  color: var(--muted);
  background: transparent;
  padding: 10px 12px;
}

.tab-button.active {
  color: #fff;
  background: var(--primary);
}

main {
  max-width: 1180px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.study-grid {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.daily-panel,
.card-stage,
.reward-summary,
.reward-layout > section,
.word-table-wrap,
.library-tools,
.import-box,
.curve-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.daily-panel {
  min-height: 520px;
  padding: 20px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.goal-ring {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 4px auto;
  display: grid;
  place-items: center;
}

.goal-ring svg {
  position: absolute;
  inset: 0;
  width: 150px;
  height: 150px;
  transform: rotate(-90deg);
}

.ring-base,
.ring-value {
  fill: none;
  stroke-width: 11;
}

.ring-base {
  stroke: var(--line);
}

.ring-value {
  stroke: var(--primary);
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 240ms ease;
}

.goal-ring div {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.goal-ring strong {
  font-size: 2.1rem;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-row div {
  min-height: 74px;
  padding: 12px 8px;
  text-align: center;
}

.metric-row span {
  display: block;
  font-size: 1.45rem;
  font-weight: 900;
}

.metric-row small {
  color: var(--muted);
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
}

.primary-button:hover,
.tab-button.active:hover {
  background: var(--primary-strong);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  padding: 0 14px;
  color: var(--primary);
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
}

.card-stage {
  position: relative;
  min-height: 520px;
  padding: clamp(16px, 3vw, 28px);
  display: grid;
  grid-template-rows: minmax(340px, 1fr) auto auto;
  gap: 16px;
}

.speak-button {
  position: absolute;
  top: clamp(24px, 3vw, 36px);
  right: clamp(24px, 3vw, 36px);
  z-index: 2;
}

.flash-card {
  position: relative;
  min-height: 340px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(37, 108, 106, 0.12), transparent 45%),
    var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--primary) 16%, var(--line));
  transform-style: preserve-3d;
  transition: transform 280ms ease;
  outline: none;
}

.flash-card:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--gold) 82%, white);
  outline-offset: 3px;
}

.flash-card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  padding: clamp(22px, 5vw, 48px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  text-align: center;
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
}

.card-kicker {
  margin: 0;
  color: var(--primary);
  font-weight: 900;
}

.card-face strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(2.2rem, 7vw, 5rem);
  line-height: 1.02;
}

.card-back strong {
  font-size: clamp(1.9rem, 5vw, 3.5rem);
}

.card-face span {
  max-width: 68ch;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.2rem);
}

.card-face small {
  color: var(--muted);
}

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

.answer-button {
  min-height: 56px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
}

.answer-button.again {
  border-color: rgba(217, 101, 79, 0.42);
}

.answer-button.hard {
  border-color: rgba(243, 191, 79, 0.72);
}

.answer-button.good {
  border-color: rgba(79, 159, 111, 0.48);
}

.answer-button.easy {
  border-color: rgba(79, 127, 200, 0.42);
}

.answer-button:hover {
  transform: translateY(-1px);
}

.empty-state {
  min-height: 190px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  text-align: center;
}

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

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

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

.curve-card {
  min-height: 168px;
  padding: 16px;
  display: grid;
  align-content: end;
  gap: 12px;
}

.curve-card span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

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

.bar-track {
  height: 86px;
  display: flex;
  align-items: end;
  border-radius: 6px;
  background: var(--surface-strong);
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 8px;
  background: var(--primary);
  transition: height 240ms ease;
}

.word-table-wrap {
  overflow: auto;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.word-table th,
.word-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.word-table th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-strong);
}

.word-table tr:last-child td {
  border-bottom: 0;
}

.word-table strong {
  display: block;
}

.word-table small {
  color: var(--muted);
}

.stage-pill {
  display: inline-flex;
  min-width: 68px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--surface-strong);
  font-weight: 900;
  white-space: nowrap;
}

.reward-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.reward-summary {
  grid-column: 1 / -1;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.reward-balance {
  min-height: 100px;
  padding: 16px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.reward-balance span {
  color: var(--muted);
}

.reward-balance strong {
  font-size: 2rem;
}

.reward-layout > section:not(.reward-summary) {
  padding: 18px;
}

.theme-list,
.reward-list {
  display: grid;
  gap: 10px;
}

.theme-option,
.reward-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}

.theme-option {
  min-height: 62px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.theme-option button {
  min-width: 70px;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}

.reward-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.reward-item small {
  color: var(--muted);
  white-space: nowrap;
}

.library-tools {
  margin-bottom: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.search-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
}

.file-button {
  position: relative;
  padding: 0 14px;
  color: var(--primary);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.import-box {
  width: 100%;
  min-height: 120px;
  margin-bottom: 12px;
  padding: 14px;
  resize: vertical;
  border: 1px solid var(--line);
  outline: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translate(-50%, 120px);
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px 12px 92px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .top-stats {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .tabbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 5;
    margin: 0;
    box-shadow: var(--shadow);
  }

  .tab-button {
    min-height: 54px;
    padding: 6px 4px;
    flex-direction: column;
    gap: 3px;
    font-size: 0.78rem;
  }

  .study-grid,
  .reward-layout,
  .library-tools {
    grid-template-columns: 1fr;
  }

  .daily-panel {
    min-height: auto;
  }

  .card-stage {
    min-height: 460px;
    grid-template-rows: minmax(310px, 1fr) auto auto;
  }

  .speak-button {
    top: 24px;
    right: 24px;
  }

  .flash-card {
    min-height: 310px;
  }

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

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

  .reward-summary {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 440px) {
  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .top-stats span {
    flex: 1 1 30%;
    text-align: center;
    padding-inline: 6px;
  }

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

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

  .theme-option {
    grid-template-columns: auto 1fr;
  }

  .theme-option button {
    grid-column: 1 / -1;
  }
}
