:root {
  --ink: #1c2430;
  --ink-soft: #5b6573;
  --paper: #eef2f6;
  --paper-2: #fffdfb;
  --line: #d5dde8;
  --blue: #1d4f91;
  --blue-deep: #14386a;
  --gold: #e8b923;
  --gold-soft: #f6e3a1;
  --sky: #3d6ea8;
  --up: #1f7a45;
  --down: #b42318;
  --flat: #9a7209;
  --ok: #2e7d4f;
  --shadow: 0 14px 36px rgba(29, 79, 145, 0.1);
  --radius: 18px;
  --header-h: 4.25rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(29, 79, 145, 0.12), transparent 52%),
    radial-gradient(800px 380px at 100% 0%, rgba(232, 185, 35, 0.16), transparent 46%),
    linear-gradient(180deg, #f7f9fc 0%, var(--paper) 42%, #e4ebf3 100%);
  line-height: 1.65;
  font-size: 1.02rem;
}

#main {
  flex: 1 0 auto;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 200;
  padding: 0.5rem 0.85rem;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
}

.skip-link:focus {
  top: calc(var(--safe-top) + 0.6rem);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: calc(0.55rem + var(--safe-top)) 1rem 0.55rem;
  background: rgba(255, 253, 251, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
}

.brand-text strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 800;
}

.header-tools {
  display: flex;
  align-items: center;
}

.header-note {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
}

.layout {
  width: min(1120px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1.1rem 0 calc(2rem + var(--safe-bottom));
}

.hero {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.2rem;
  margin-bottom: 1rem;
}

.hero h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 900;
}

.hero .lead {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: 14px;
  border: 1px solid #c5d6ea;
  background: #eef4fb;
  color: #24486c;
  font-size: 0.95rem;
}

.banner p {
  margin: 0;
}

.banner-icon {
  font-size: 1.2rem;
  line-height: 1.3;
  font-weight: 900;
}

.panel {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.15rem 1.2rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 0.7rem;
  font-size: 1.12rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.kcard {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-left-width: 6px;
  border-radius: 16px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.kcard h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.kcard p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.kcard:nth-child(1) { border-left-color: var(--blue); }
.kcard:nth-child(2) { border-left-color: var(--gold); }
.kcard:nth-child(3) { border-left-color: var(--up); }

details.cheat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}

details.cheat summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--blue);
  list-style: none;
}

details.cheat summary::-webkit-details-marker {
  display: none;
}

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

.cheat-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
  font-size: 0.88rem;
}

.cheat-table th,
.cheat-table td {
  border: 1px solid var(--line);
  padding: 0.5rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.cheat-table th {
  background: #eef3f8;
}

.motto {
  color: var(--blue);
  font-weight: 800;
}

.tutorial-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.tutor-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.tutor-steps li {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #e4ebf3;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.tutor-steps li.is-on {
  background: var(--sky);
  color: #fff;
}

.tutor-steps li.is-done {
  background: #dceee3;
  color: var(--ok);
}

#tutorial-desc {
  margin: 0.4rem 0 0.8rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.45rem 1.05rem;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 800;
  text-decoration: none;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 6px 0 var(--blue-deep);
}

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

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--blue-deep);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: #e4ebf3;
  color: var(--ink);
  box-shadow: 0 6px 0 #c5d0de;
}

.btn-sky {
  background: var(--sky);
  box-shadow: 0 6px 0 #2a507c;
}

.console-hint {
  margin: -0.2rem 0 0.9rem;
  color: var(--ink-soft);
}

.presets {
  margin: 0 0 1rem;
}

.presets-label {
  margin: 0 0 0.5rem;
  font-weight: 800;
  color: var(--blue);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.55rem;
}

.preset-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  min-height: 64px;
  padding: 0.65rem 0.7rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}

.preset-btn strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--blue);
}

.preset-btn span {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  line-height: 1.35;
}

.preset-btn.is-on {
  border-color: var(--blue);
  background: #eef4fb;
  box-shadow: inset 0 0 0 1px var(--blue);
}

#trend-panel .actions {
  margin-top: 0.7rem;
}

#trend-btns {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#trend-btns .preset-btn {
  text-align: center;
}

#trend-btns .preset-btn strong {
  font-size: 0.82rem;
}

.trend-spark {
  display: block;
  width: 100%;
  height: 2.6rem;
  margin-bottom: 0.3rem;
}

.note-heading {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

#trend-btns .preset-btn[data-trend="custom"] {
  grid-column: 1 / -1;
}

.story-box {
  background: #eef4fb;
  border: 1px solid #c5d6ea;
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.9rem;
  color: #24486c;
  font-weight: 700;
}

.story-box p {
  margin: 0;
}

.measure-board {
  margin: 0.2rem 0 0.4rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 251, 0.9);
}

.measure-grid .field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.measure-grid .field input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
  min-height: 44px;
}

.range-val {
  font-style: normal;
  font-weight: 800;
  color: var(--blue);
}

.measure-tip {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.stage-box {
  margin-top: 1rem;
  background: #eef3f8;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
}

.stage-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.55rem;
  font-weight: 800;
}

.val-pill {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.65rem;
  font-size: 0.85rem;
  color: var(--blue);
}

.stage-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.stage-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  min-height: 52px;
  min-width: 5.1rem;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
}

.stage-chip em {
  font-style: normal;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.stage-chip span {
  font-size: 0.88rem;
  font-weight: 800;
}

.stage-chip.is-on {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.stage-chip.is-on em {
  color: #d5e4f8;
}

.stage-chip.is-done {
  background: var(--gold-soft);
  border-color: #e0c36a;
}

.stage-caption {
  margin: 0.65rem 0 0;
  color: #3d5674;
  font-size: 0.9rem;
  font-weight: 700;
}

.sim-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: start;
}

.view-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.view-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1;
}

.view-frame {
  background: #f4f7fb;
  color: var(--ink);
  border-radius: 16px;
  min-height: 280px;
  padding: 0.75rem;
  overflow: auto;
}

.view-frame-note {
  background: #fff;
  border: 1px solid var(--line);
  min-height: 0;
  height: auto;
  overflow: visible;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border-radius: 12px;
  touch-action: none;
}

.chart-svg g[data-point]:focus {
  outline: none;
}

.chart-svg g[data-point]:focus [data-role="dot"] {
  stroke: var(--blue);
  stroke-width: 4;
}

.chart-caption {
  margin: 0.65rem 0.15rem 0.1rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.45rem;
  font-size: 0.82rem;
  font-weight: 800;
}

.legend i {
  display: inline-block;
  width: 0.85rem;
  height: 0.35rem;
  border-radius: 99px;
  margin-right: 0.28rem;
  vertical-align: middle;
}

.legend .up { background: var(--up); }
.legend .down { background: var(--down); }
.legend .flat { background: var(--flat); }
.legend .bar { background: var(--blue); height: 0.7rem; width: 0.55rem; }

.note-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.note-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  background: #f8fafc;
}

.note-block.is-focus {
  border-color: var(--blue);
  background: #eef4fb;
  box-shadow: inset 0 0 0 1px var(--blue);
}

.note-block h3 {
  margin: 0 0 0.25rem;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--blue);
}

.note-block p {
  margin: 0;
  font-weight: 700;
}

.seg-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.seg-pick {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  min-height: 40px;
  padding: 0.25rem 0.7rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--ink);
}

.seg-pick.is-on {
  color: #fff;
  border-color: transparent;
}

.seg-pick.is-up.is-on { background: var(--up); }
.seg-pick.is-down.is-on { background: var(--down); }
.seg-pick.is-flat.is-on { background: var(--flat); }
.seg-pick.is-bar.is-on { background: var(--blue); }

.speed-list {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.speed-list li {
  background: #fff;
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  font-size: 0.88rem;
}

.speed-list li.is-on {
  outline: 2px solid var(--blue);
}

.site-footer {
  text-align: center;
  padding: 1.1rem 1rem calc(1.2rem + var(--safe-bottom));
  color: var(--ink-soft);
  font-size: 0.88rem;
  border-top: 1px solid var(--line);
}

.site-footer a {
  color: var(--blue);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  z-index: 80;
  font-weight: 700;
  max-width: min(36rem, calc(100% - 1.5rem));
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .preset-grid,
  .sim-grid,
  .cards {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 720px) {
  .cards,
  .sim-grid,
  .preset-grid {
    grid-template-columns: 1fr;
  }

  #trend-btns {
    grid-template-columns: 1fr 1fr;
  }

  .brand-text strong {
    font-size: 0.86rem;
  }

  .header-note {
    display: none;
  }

  .hero h1 {
    font-size: 1.28rem;
  }

  .stage-chip {
    min-width: 4.6rem;
  }
}
