:root {
  color-scheme: light;
  --green-950: #073e31;
  --green-800: #0b5a43;
  --green-650: #197456;
  --green-100: #dcece5;
  --ink: #17231f;
  --muted: #65716c;
  --canvas: #f1f0e9;
  --surface: #fffdf7;
  --paper: #f4e6c2;
  --line: #d7d9d1;
  --red: #c7443e;
  --red-soft: #f6dfdc;
  --blue: #2f6ed3;
  --blue-soft: #dfe9fb;
  --gold: #a97816;
  --shadow: 0 10px 28px rgba(22, 42, 34, 0.1);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  letter-spacing: 0;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding: 16px 18px;
  background: var(--green-950);
  color: white;
  border-bottom: 3px solid #c7a557;
}

.topbar h1, .section-heading h2, .section-heading h3, .training-dialog h2, .strategy-dialog h2 { margin: 0; }
.topbar h1 { font-size: 1.28rem; line-height: 1.25; }
.eyebrow { margin: 0 0 4px; color: inherit; font-size: 0.68rem; font-weight: 800; text-transform: uppercase; }
.topbar .eyebrow { color: #b9d9ca; }
.topbar-actions, .button-row, .goal-row { display: flex; align-items: center; gap: 8px; }

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}
.status-chip[data-status="offline"] { color: #dae7e1; }
.status-chip[data-status="online"] { color: #b9f2d6; }
.status-chip[data-status="pending"] { color: var(--gold); background: #fff8df; }
.status-chip[data-status="default"] { color: var(--blue); background: var(--blue-soft); }
.status-chip[data-status="exception"] { color: var(--red); background: var(--red-soft); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
  background: transparent;
  color: white;
  font-size: 1.25rem;
}
.icon-button.dark { color: var(--ink); border-color: var(--line); }

.main-content { width: min(100%, 780px); margin: 0 auto; padding: 20px 16px 36px; }
.view { display: none; }
.view.is-active { display: block; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.section-heading h2 { font-size: 1.55rem; }
.section-heading h3 { font-size: 1rem; }
.section-heading .eyebrow { color: var(--green-650); }
.section-heading.compact { margin-bottom: 12px; }
.metric-value { color: var(--green-800); font-size: 1.15rem; }

.progress-panel {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.progress-copy { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.progress-track { height: 9px; overflow: hidden; background: #dfe2dc; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--green-650); transition: width .25s ease; }

.action-grid { display: grid; gap: 10px; margin: 14px 0 24px; }
.primary-action, .secondary-action, .mode-row, .primary-small, .secondary-small, .text-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}
.primary-action, .secondary-action { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 68px; padding: 14px 16px; }
.primary-action { background: var(--green-800); color: white; }
.secondary-action { background: var(--paper); color: var(--ink); border: 1px solid #d2bd88; }
.primary-action small, .secondary-action small, .mode-row small { font-weight: 600; opacity: .78; }
.primary-action.full-width { width: 100%; align-items: center; justify-content: center; margin-top: 14px; }

.plain-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.field-label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.text-input, .number-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #bbc2bc;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
.number-input { width: 84px; margin-left: auto; }
.goal-row { justify-content: space-between; margin-top: 10px; }
.goal-row .field-label { margin: 0; }
.text-button { padding: 7px 9px; background: transparent; color: var(--green-800); }
.primary-small, .secondary-small { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 12px; }
.primary-small { background: var(--green-800); color: white; }
.secondary-small { background: var(--surface); color: var(--green-800); border: 1px solid var(--green-650); }
.primary-small:disabled, .secondary-small:disabled { cursor: default; opacity: .5; }
.file-button { cursor: pointer; }
.inline-message { min-height: 20px; color: var(--muted); font-size: .82rem; }

.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric-box { padding: 12px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.metric-box strong { display: block; font-size: 1.15rem; color: var(--green-800); }
.metric-box span { display: block; margin-top: 3px; color: var(--muted); font-size: .7rem; }

.mode-list, .list-stack, .strategy-list { display: grid; gap: 10px; }
.mode-row { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 15px; text-align: left; background: var(--surface); border: 1px solid var(--line); }
.mode-row span { display: flex; flex-direction: column; gap: 4px; }
.mode-row b { color: var(--green-650); }

.segmented-control { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; background: #dde2dc; border-radius: 8px; }
.segmented-control button { flex: 1 1 88px; min-height: 38px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 800; }
.segmented-control button.is-active { background: var(--surface); color: var(--green-800); box-shadow: 0 2px 8px rgba(18,40,31,.1); }

.list-card, .strategy-card { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.list-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.list-card p, .strategy-card p { margin: 0; }
.list-card small, .strategy-card small { color: var(--muted); }
.mistake-reason { margin-top: 6px !important; color: #8b302c; font-size: .78rem; line-height: 1.5; }
.strategy-card { width: 100%; min-width: 0; text-align: left; }
.strategy-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.strategy-card-title { min-width: 0; font-weight: 900; overflow-wrap: anywhere; }
.strategy-card-line { display: block; color: var(--muted); font-size: .84rem; line-height: 1.55; overflow-wrap: anywhere; }
.strategy-list { margin-top: 16px; }
.strategy-filter-section { margin-top: 16px; padding-top: 14px; }
.environment-strip { display: flex; flex-wrap: wrap; gap: 0; margin-top: -4px; color: var(--muted); font-size: .76rem; font-weight: 800; }
.environment-strip span { padding: 2px 10px; border-left: 1px solid var(--line); }
.environment-strip span:first-child { padding-left: 0; border-left: 0; }
.empty-state { padding: 32px 12px; color: var(--muted); text-align: center; border: 1px dashed #b8c0ba; border-radius: 8px; }

.solver-queue-list { display: grid; }
.solver-queue-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-width: 0; padding: 12px 0; border-bottom: 1px solid var(--line); }
.solver-queue-copy { display: grid; min-width: 0; gap: 4px; }
.solver-queue-copy strong, .solver-queue-copy small { overflow-wrap: anywhere; }
.solver-queue-copy small { color: var(--muted); }
.solver-queue-copy .solver-failure { color: var(--red); }

.status-list { margin: 0; }
.status-list div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; font-weight: 800; }

.primary-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(62px + env(safe-area-inset-bottom));
  padding: 5px 6px env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav-button { min-height: 50px; border: 0; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 800; }
.nav-button.is-active { color: var(--green-800); border-top: 3px solid var(--green-650); }

dialog { border: 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(5, 24, 18, .62); }
.training-dialog, .strategy-dialog { width: min(100% - 24px, 620px); max-height: calc(100vh - 24px); overflow: auto; padding: 18px; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.dialog-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.question-meta { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .78rem; }
.training-dialog h2 { margin: 18px 0; font-size: 1.3rem; line-height: 1.45; }
.answer-options { display: grid; gap: 9px; }
.answer-button { min-height: 50px; padding: 12px; border: 1px solid #c8cec9; border-radius: 7px; background: white; color: var(--ink); text-align: left; font-weight: 800; }
.answer-button.is-correct { border-color: var(--green-650); background: var(--green-100); }
.answer-button.is-wrong { border-color: var(--red); background: var(--red-soft); }
.answer-button:disabled { color: inherit; cursor: default; }
.feedback-panel { margin-top: 12px; padding: 13px; border-left: 4px solid var(--green-650); background: #edf5f1; line-height: 1.6; }
.feedback-panel.is-wrong { border-left-color: var(--red); background: var(--red-soft); }
.feedback-summary { display: block; margin-bottom: 7px; font-size: 1rem; }
.feedback-section { padding: 8px 0; border-top: 1px solid rgba(23, 35, 31, .12); }
.feedback-label { color: var(--green-800); font-size: .72rem; font-weight: 900; }
.feedback-panel.is-wrong .feedback-label { color: #9f332e; }
.feedback-section p { margin: 2px 0 0; line-height: 1.55; }

.strategy-dialog h2 { font-size: 1.28rem; line-height: 1.35; overflow-wrap: anywhere; }
.detail-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; margin-top: 16px; padding: 3px; border-radius: 8px; background: #dde2dc; }
.detail-tabs button { min-width: 0; min-height: 40px; padding: 7px 5px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 900; overflow-wrap: anywhere; }
.detail-tabs button[aria-selected="true"] { background: var(--surface); color: var(--green-800); box-shadow: 0 2px 8px rgba(18,40,31,.1); }
.strategy-detail { margin: 10px 0 0; overflow-wrap: anywhere; }
.strategy-detail div { padding: 13px 0; border-top: 1px solid var(--line); }
.strategy-detail dt { color: var(--green-800); font-size: .76rem; font-weight: 900; }
.strategy-detail dd { margin: 5px 0 0; line-height: 1.65; }
.strategy-detail ul { margin: 0; padding-left: 20px; }
.strategy-detail li + li { margin-top: 5px; }
.strategy-solver-actions { padding-top: 12px; border-top: 1px solid var(--line); }
.strategy-solver-actions .inline-message { margin: 0 0 8px; }
.strategy-solver-actions .button-row { flex-wrap: wrap; }
.solver-generator-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: end; margin-bottom: 12px; }
.solver-generator-field { display: grid; gap: 6px; min-width: 0; color: var(--green-800); font-size: .76rem; font-weight: 900; }
.solver-generator-field select { width: 100%; }
.solver-generator-controls > .inline-message { grid-column: 1 / -1; margin: 0; }
.solver-node-field { display: grid; gap: 6px; margin-bottom: 10px; color: var(--green-800); font-size: .76rem; font-weight: 900; }
.solver-node-field textarea { width: 100%; min-height: 132px; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: 500 .78rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.solver-node-field textarea:focus { outline: 2px solid var(--green-300); outline-offset: 1px; }

.toast { position: fixed; left: 50%; bottom: 84px; z-index: 80; max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 6px; background: var(--ink); color: white; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .app-shell { display: grid; grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; padding-inline: 28px; }
  .primary-nav { position: sticky; top: 87px; grid-column: 1; grid-row: 2; display: flex; flex-direction: column; align-self: start; min-height: calc(100vh - 87px); padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line); }
  .nav-button { min-height: 48px; padding: 0 16px; border-radius: 6px; text-align: left; }
  .nav-button.is-active { border-top: 0; border-left: 4px solid var(--green-650); background: var(--green-100); }
  .main-content { grid-column: 2; grid-row: 2; width: min(100%, 1040px); padding: 34px 34px 60px; }
  .action-grid { grid-template-columns: 1.3fr 1fr; }
  .strategy-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .training-dialog, .strategy-dialog { width: calc(100vw - 24px); padding: 16px; }
  .solver-generator-controls { grid-template-columns: 1fr; align-items: stretch; }
  .solver-generator-controls > .inline-message { grid-column: 1; }
  .detail-tabs button { font-size: .72rem; }
  .segmented-control button { flex-basis: 82px; }
  .solver-queue-item { gap: 8px; }
  .solver-queue-item .status-chip { flex: 0 0 auto; }
}
