:root {
  --bg: #faf6f0;
  --bg-tint: #f3ece2;
  --panel: #fffdfa;
  --card: #ffffff;

  --ink: #2b2621;
  --ink-soft: #574f47;
  --muted: #7d7368;
  --faint: #a2968a;

  --line: #e8ded1;
  --line-soft: #f0e8dd;

  --accent: #b0512f;
  --accent-tint: #fbf0ea;
  --accent-edge: #e6c4b6;

  --up: #2f7d5a;
  --up-tint: #eaf4ee;
  --down: #b0452e;
  --down-tint: #fbeeea;

  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: #f2ddd2;
  color: var(--ink);
}

/* ---------- 侧栏 ---------- */

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 30px 26px 26px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--faint);
  text-transform: none;
}

.day {
  margin: 20px 0 0;
  font-family: var(--mono);
  font-size: 62px;
  line-height: 0.9;
  font-weight: 500;
  letter-spacing: -0.05em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.day-label {
  display: inline-block;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.phase {
  margin: 18px 0 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.situation {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.cash {
  margin: 22px 0 0;
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 500;
  letter-spacing: -0.04em;
  color: var(--up);
  font-variant-numeric: tabular-nums;
}

.cash.down { color: var(--down); }

.debt {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--down);
  background: var(--down-tint);
  display: inline-block;
  padding: 3px 8px;
  border-radius: 5px;
}

.debt[hidden] { display: none; }

/* ---------- 精力 / 心情 ---------- */

.meters {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

.meters label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.meters label + .meter { margin-bottom: 14px; }

.meters label:last-of-type + .meter { margin-bottom: 0; }

.meters b {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-tint);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #d9a05a, #c4813a);
  transition: width 0.45s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.meter.mood span {
  background: linear-gradient(90deg, #8fb4a4, #5f8f7c);
}

/* ---------- 侧栏数据 ---------- */

.facts {
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
}

.facts li {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.4;
}

.facts li:first-child { border-top: 0; }

.facts span {
  color: var(--faint);
  font-size: 12px;
}

/* ---------- 各家店 ---------- */

.stores {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.stores[hidden] { display: none; }

.stores h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.16em;
  font-weight: 500;
  color: var(--faint);
}

.stores ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.store {
  padding: 9px 10px 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  background: var(--bg);
  border-left: 3px solid var(--line);
}

.store.focused {
  border-color: var(--accent-edge);
  border-left-color: var(--accent);
  background: var(--accent-tint);
}

.store-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
}

.store-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-net {
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.store-net.up { color: var(--up); }
.store-net.down { color: var(--down); }

.store-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* ---------- 按钮 ---------- */

.restart {
  margin-top: 26px;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.restart:hover {
  background: var(--accent-tint);
  border-color: var(--accent-edge);
  color: var(--accent);
}

.restart.armed {
  color: #fff;
  background: var(--down);
  border-color: var(--down);
}

.fine {
  margin: 12px 0 0;
  font-size: 11px;
  color: var(--faint);
  line-height: 1.55;
}

.version {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.version-log { display: none; }

/* 顶部新版本提示 */
.update-note {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  border: 1px solid var(--accent-edge);
  border-radius: 11px;
  background: var(--accent-tint);
  font-size: 13px;
  color: var(--ink-soft);
}

.update-note[hidden] { display: none; }

.update-note p { margin: 0; }

.update-note b {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--accent);
}

.update-note button {
  flex: 0 0 auto;
  padding: 7px 15px;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 7px;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.update-note button:hover { filter: brightness(1.08); }

/* ---------- 主区域 ---------- */

main {
  padding: 44px 3vw 72px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas: "card log";
  align-items: start;
  gap: 26px;
  max-width: 1220px;
  margin: 0 auto;
  width: 100%;
}

.card {
  grid-area: card;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 40px 44px 32px;
  box-shadow:
    0 1px 2px rgba(90, 70, 50, 0.04),
    0 18px 40px -24px rgba(90, 70, 50, 0.22);
}

.card.final {
  background: #fffbf5;
  border-color: var(--accent-edge);
}

.tag {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--accent);
}

h1 {
  margin: 12px 0 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.22;
  color: var(--ink);
}

.prose p {
  margin: 15px 0 0;
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 1.78;
  color: var(--ink-soft);
}

/* ---------- 选项 ---------- */

.options {
  margin-top: 26px;
  display: grid;
  gap: 9px;
}

.option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 15px 17px;
  font-family: inherit;
  color: inherit;
  background: #fffefd;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.option:hover:not(:disabled) {
  background: var(--accent-tint);
  border-color: var(--accent-edge);
  box-shadow: 0 2px 10px -4px rgba(176, 81, 47, 0.28);
  transform: translateY(-1px);
}

.option:active:not(:disabled) {
  transform: translateY(0);
}

.option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.option:disabled {
  cursor: not-allowed;
  background: #fbf8f4;
  border-color: var(--line-soft);
}

.option:disabled .label { color: var(--faint); }
.option:disabled .detail { color: var(--faint); }

.option .row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.option .n {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-tint);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.option:hover:not(:disabled) .n {
  background: #f3ded3;
  color: var(--accent);
}

.option .label {
  flex: 1 1 auto;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink);
}

.option .detail,
.option .reason {
  margin: 6px 0 0 36px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.option .reason {
  color: var(--down);
  font-weight: 500;
}

.final-note {
  margin: 18px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.final-note[hidden] { display: none; }

.error {
  margin: 12px 0 0;
  min-height: 1.2em;
  font-size: 13px;
  color: var(--down);
}

.error[hidden] { display: none; }

/* ---------- 历史 ---------- */

  .log {
    grid-area: log;
    position: sticky;
    top: 44px;  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px 16px;
  box-shadow:
    0 1px 2px rgba(90, 70, 50, 0.04),
    0 14px 30px -26px rgba(90, 70, 50, 0.2);
}

.log h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 500;
  color: var(--faint);
}

.log ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.log li {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.log li:first-child { border-top: 0; }

.log .when {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  padding-top: 1px;
  font-variant-numeric: tabular-nums;
}

.log .what {
  color: var(--ink-soft);
  word-break: break-word;
}

.restart-log {
  display: none;
  margin-top: 14px;
}

.log-empty {
  display: block !important;
  border-top: 0 !important;
  padding: 6px 0 2px !important;
  font-size: 12.5px;
  color: var(--faint);
}

/* ---------- 窄屏 ---------- */

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  /* 手机端把侧栏压成一条紧凑状态条：天数/阶段/现金一行，
     精力心情一行，其余数据折成小标签，尽量把首屏留给选项。 */
  .rail {
    position: static;
    height: auto;
    padding: 12px 14px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 12px;
    row-gap: 0;
    align-items: center;
  }

  .brand,
  .day-label,
  .fine {
    display: none;
  }

  .day {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    font-size: 34px;
    line-height: 1;
    letter-spacing: -0.06em;
  }

  .phase {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    font-size: 15px;
    line-height: 1.25;
  }

  .situation {
    grid-column: 2;
    grid-row: 1;
    margin: 17px 0 0;
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cash {
    grid-column: 3;
    grid-row: 1;
    margin: 0;
    font-size: 18px;
    text-align: right;
  }

  .debt {
    grid-column: 3;
    grid-row: 1;
    margin: 18px 0 0;
    font-size: 10px;
    padding: 2px 6px;
    justify-self: end;
    white-space: nowrap;
  }

  .meters {
    grid-column: 1 / -1;
    grid-row: 2;
    margin: 10px 0 0;
    padding: 0;
    border-top: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
    column-gap: 7px;
    align-items: center;
  }

  .meters label {
    margin: 0;
    font-size: 10px;
    gap: 3px;
    white-space: nowrap;
  }

  .meters b {
    font-size: 10px;
  }

  .meter {
    height: 4px;
  }

  .meters label + .meter,
  .meters label:last-of-type + .meter {
    margin: 0;
  }

  /* 数据折成可横向滑动的一排小标签。 */
  .facts {
    grid-column: 1 / -1;
    grid-row: 3;
    margin: 8px 0 0;
    padding: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .facts::-webkit-scrollbar {
    display: none;
  }

  .facts li {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid var(--line-soft);
    border-radius: 999px;
    background: var(--bg);
    font-size: 11px;
    line-height: 1.5;
    white-space: nowrap;
  }

  .facts span {
    font-size: 10px;
  }

  .stores {
    grid-column: 1 / -1;
    grid-row: 4;
    margin: 8px 0 0;
    padding: 0;
    border-top: 0;
  }

  .stores h2 {
    display: none;
  }

  .stores ul {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stores ul::-webkit-scrollbar {
    display: none;
  }

  .store {
    flex: 0 0 auto;
    padding: 5px 9px;
    border-radius: 8px;
    border-left-width: 3px;
  }

  .store-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    font-size: 11px;
  }

  .store-net {
    font-size: 11px;
  }

  .store-note {
    display: none;
  }

  .restart {
    grid-column: 1 / -1;
    grid-row: 5;
    margin: 10px 0 0;
    padding: 7px 10px;
    font-size: 12px;
  }

  /* 手机上重开一局很少用，挪到历史区末尾，把首屏让给选项。 */
  .rail .restart {
    display: none;
  }

  .log .restart-log {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 8px 10px;
    font-size: 12px;
  }

  main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "update" "card" "log";
    gap: 10px;
    padding: 12px 12px 44px;
  }

  .update-note {
    grid-area: update;
    padding: 9px 12px;
    font-size: 12px;
    gap: 10px;
  }

  .update-note button {
    padding: 6px 12px;
    font-size: 12px;
  }

  .rail .version { display: none; }

  .log .version-log {
    display: block;
    margin-top: 10px;
    text-align: center;
  }

  .card {
    padding: 16px 15px 14px;
    border-radius: 13px;
  }

  .tag {
    font-size: 10px;
  }

  h1 {
    margin-top: 6px;
    font-size: 21px;
    line-height: 1.28;
  }

  .prose p {
    margin-top: 9px;
    font-size: 14.5px;
    line-height: 1.62;
  }

  .options {
    margin-top: 14px;
    gap: 7px;
  }

  .option {
    padding: 10px 12px;
    border-radius: 10px;
  }

  .option .row {
    gap: 9px;
  }

  .option .n {
    flex-basis: 20px;
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .option .label {
    font-size: 15px;
    line-height: 1.42;
  }

  /* 说明文字在手机上压到最紧凑：小字号、紧行距，不做截断，避免丢信息。 */
  .option .detail,
  .option .reason {
    margin: 2px 0 0;
    font-size: 11px;
    line-height: 1.4;
  }

  .log {
    position: static;
    max-height: none;
    padding: 14px 14px 10px;
    border-radius: 13px;
  }

  .log h2 {
    margin-bottom: 6px;
    font-size: 10px;
  }

  .log li {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 0;
    font-size: 12px;
    line-height: 1.45;
  }

  .log .when {
    font-size: 10.5px;
  }
}

@media (max-width: 420px) {
  h1 { font-size: 23px; }

  .facts li { font-size: 11.5px; }

  .stores ul { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
