:root {
  --bg: #eef4f3;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --text: #172321;
  --muted: #61706d;
  --line: #d9e3e1;
  --brand: #0f766e;
  --brand-dark: #0a5c56;
  --safe: #138a5b;
  --safe-soft: #e6f6ee;
  --warning: #d97706;
  --warning-soft: #fff4dc;
  --danger: #c62828;
  --danger-soft: #fdeaea;
  --blue: #2867a8;
  --shadow: 0 8px 28px rgba(28, 57, 52, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 18px 14px;
  color: #fff;
  background: linear-gradient(135deg, #0b5f59, #12857b);
}

.app-header h1 {
  margin: 3px 0 0;
  font-size: clamp(21px, 5.8vw, 28px);
  line-height: 1.2;
}

.eyebrow, .section-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
}

.eyebrow { color: rgba(255,255,255,.78); }
.section-kicker { color: var(--brand); }

.offline-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  color: #fff;
  background: rgba(255,255,255,.12);
  font-size: 11px;
  font-weight: 700;
}

main { padding: 16px 14px 0; }

.page { display: none; }
.page.active { display: block; animation: page-in .2s ease; }

@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-heading, .action-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading { margin: 2px 2px 14px; }
.section-heading h2, .action-title h3 { margin: 3px 0 0; }
.section-heading h2 { font-size: 25px; }
.action-title h3 { font-size: 21px; }
.action-title > span { color: var(--muted); font-size: 12px; font-weight: 700; }

.notice-card, .form-card, .detail-card, .action-section, .history-card, .rules-card, .trip-hint-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.notice-card { padding: 15px 16px; }
.notice-card strong { display: block; margin-bottom: 4px; }
.notice-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.info-card { border-left: 5px solid var(--brand); }

.rules-card { margin-top: 14px; padding: 16px; }
.rules-card h3 { margin: 3px 0 12px; font-size: 19px; }
.rule-groups { display: grid; gap: 12px; }
.rule-groups strong { display: block; margin-bottom: 6px; color: var(--brand-dark); }
.rule-groups ul { margin: 0; padding-left: 18px; color: #344541; font-size: 13px; line-height: 1.6; }
.rule-groups li { margin: 2px 0; }

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}

.template-card {
  min-height: 112px;
  padding: 13px;
  border: 2px solid transparent;
  border-radius: 16px;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.template-card:active, .template-card.selected { border-color: var(--brand); background: #edf9f7; }
.template-card span, .template-card strong, .template-card small { display: block; }
.template-card span { color: var(--brand); font-size: 12px; font-weight: 800; }
.template-card strong { margin: 5px 0; font-size: 16px; }
.template-card small { color: var(--muted); line-height: 1.4; }

.form-card { margin-bottom: 12px; padding: 16px; }
.form-card h3 { margin: 0 0 13px; font-size: 18px; }

.field { display: block; margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.field > span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 700;
}
.field em { color: var(--muted); font-size: 11px; font-style: normal; letter-spacing: .05em; }

.field input {
  width: 100%;
  min-height: 50px;
  padding: 10px 13px;
  border: 1.5px solid #cbd8d5;
  border-radius: 12px;
  color: var(--text);
  background: #fbfdfc;
  font-size: 19px;
  font-weight: 750;
  outline: none;
}

.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.field input.invalid { border-color: var(--danger); }
.form-hint, .field-error { min-height: 18px; margin: 2px 0 0; font-size: 12px; }
.form-hint { color: var(--muted); }
.form-hint.error, .field-error { color: var(--danger); font-weight: 700; }

.button {
  min-height: 52px;
  padding: 11px 15px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}

.button:active { transform: translateY(1px); }
.button:disabled { opacity: .42; cursor: not-allowed; filter: grayscale(.35); transform: none; }
.button-wide { width: 100%; }
.button-small { min-height: 36px; padding: 7px 10px; border-radius: 10px; font-size: 12px; }
.button-primary { color: #fff; background: var(--brand); }
.button-primary:active { background: var(--brand-dark); }
.button-secondary { color: #263b37; background: #dfe9e7; }
.button-ghost { color: var(--brand); border: 1px solid #a9cbc6; background: transparent; }
.button-outline { color: var(--text); border: 1.5px solid #b7c7c4; background: var(--surface); }
.button-invest { color: #fff; background: var(--blue); }
.button-recover { color: #fff; background: var(--safe); }
.button-lock { color: #4b3500; background: #f5c451; }
.button-danger { color: #fff; background: var(--danger); }

.status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 17px 18px;
  border-radius: var(--radius);
  color: #fff;
  box-shadow: var(--shadow);
}
.status-card.safe { background: linear-gradient(135deg, #0f8458, #22a06b); }
.status-card.warning { background: linear-gradient(135deg, #c56605, #e69022); }
.status-card.stop { background: linear-gradient(135deg, #a91f1f, #d33939); }
.status-card p, .timer-block span { display: block; margin: 0 0 3px; color: rgba(255,255,255,.8); font-size: 12px; font-weight: 700; }
.status-card strong { font-size: clamp(18px, 5vw, 27px); line-height: 1.2; }
.timer-block { text-align: right; }
.timer-block strong { font-variant-numeric: tabular-nums; font-size: 23px; }

.cooldown-panel {
  margin-top: 10px;
  padding: 14px 15px;
  border: 2px solid var(--danger);
  border-radius: 15px;
  color: #7f1515;
  background: var(--danger-soft);
}
.cooldown-panel strong { font-size: 17px; }
.cooldown-panel p { margin: 4px 0 0; font-size: 13px; line-height: 1.45; }

.money-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.money-card {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.money-card span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.money-card strong { display: block; overflow: hidden; font-size: clamp(18px, 5vw, 24px); text-overflow: ellipsis; white-space: nowrap; }
.primary-metric { border-color: #8bcbbb; background: var(--safe-soft); }
.primary-metric.negative { border-color: #f0b6b6; background: var(--danger-soft); }
.primary-metric.negative strong { color: var(--danger); }
.primary-metric.positive strong, .locked-metric strong { color: var(--safe); }
.locked-metric { background: #fff8e8; }

.trip-hint-card {
  margin-top: 10px;
  padding: 13px 15px;
  border-left: 5px solid var(--brand);
}
.trip-hint-card span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 800; }
.trip-hint-card strong { display: block; font-size: 14px; line-height: 1.55; }

.detail-card { margin-top: 10px; padding: 7px 15px; }
.detail-card > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.detail-card > div:last-child { border-bottom: 0; }
.detail-card span { color: var(--muted); font-size: 13px; }
.detail-card strong { font-size: 15px; }

.action-section { margin-top: 12px; padding: 15px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.action-grid .button:last-child { grid-column: 1 / -1; }

.discipline-actions { margin-top: 12px; }
.discipline-actions .button { margin-bottom: 9px; }
.locked-copy { margin: -1px 5px 12px; color: #786019; font-size: 12px; line-height: 1.5; text-align: center; }
.text-button {
  display: block;
  margin: 4px auto 0;
  padding: 11px 15px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  text-decoration: underline;
}

.empty-state { padding: 54px 24px; text-align: center; }
.empty-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 15px;
  border-radius: 50%;
  place-items: center;
  color: var(--brand);
  background: #dcefeb;
  font-size: 28px;
  font-weight: 900;
}
.empty-state h2 { margin: 0 0 7px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); }

.history-list { display: grid; gap: 10px; }
.history-card { padding: 15px; }
.history-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.history-date { font-weight: 800; }
.history-result { font-size: 18px; font-weight: 900; }
.history-result.win { color: var(--safe); }
.history-result.loss { color: var(--danger); }
.history-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.history-details div { min-width: 0; }
.history-details span { display: block; color: var(--muted); font-size: 11px; }
.history-details strong { display: block; margin-top: 2px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.history-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 13px;
  background: var(--surface-soft);
}
.history-score span { color: var(--muted); font-size: 12px; font-weight: 800; }
.history-score strong { color: var(--brand); font-size: 20px; }
.history-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag { padding: 4px 8px; border-radius: 999px; color: #42524f; background: #e8efed; font-size: 11px; font-weight: 800; }
.tag.good { color: #086441; background: var(--safe-soft); }
.tag.bad { color: #941b1b; background: var(--danger-soft); }
.history-review { margin: 10px 0 0; color: #41514e; font-size: 13px; line-height: 1.55; }

.core-reminder {
  margin: 18px 14px 0;
  padding: 15px 16px calc(104px + env(safe-area-inset-bottom));
  color: #42534f;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
  text-align: center;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 560px);
  margin: auto;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  box-shadow: 0 -7px 24px rgba(30,57,53,.08);
  backdrop-filter: blur(12px);
}
.nav-button {
  min-height: 55px;
  border: 0;
  border-radius: 13px;
  color: #687773;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}
.nav-button span { display: block; margin-bottom: 2px; font-size: 20px; }
.nav-button.active { color: var(--brand); background: #e9f5f2; }

.app-dialog {
  width: min(calc(100% - 28px), 460px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
}
.app-dialog::backdrop { background: rgba(7, 22, 20, .62); backdrop-filter: blur(2px); }
.dialog-tone { height: 8px; background: var(--warning); }
.dialog-tone.danger { background: var(--danger); }
.dialog-tone.success { background: var(--safe); }
.dialog-content { padding: 22px; }
.dialog-content h2 { margin: 0 0 10px; font-size: 23px; }
.dialog-content > p { margin: 0 0 19px; color: #41514e; font-size: 16px; font-weight: 650; line-height: 1.6; }
.dialog-content .dialog-help { color: var(--muted); font-size: 13px; font-weight: 500; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 370px) {
  main { padding-right: 10px; padding-left: 10px; }
  .template-grid { grid-template-columns: 1fr; }
  .template-card { min-height: 94px; }
  .money-card { padding: 12px; }
  .button { padding-right: 9px; padding-left: 9px; }
}

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-shell { overflow: hidden; border-radius: 24px; box-shadow: 0 18px 60px rgba(28,57,52,.16); }
  .bottom-nav { bottom: 18px; border-radius: 0 0 24px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
