@font-face {
  font-family: "Noto Sans TC";
  src: url("fonts/NotoSansTC.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #12324a;
  --muted: #3d5870;
  --green: #0c6b52;
  --green-d: #085443;
  --blue: #0d47a1;
  --card: #ffffff;
  --line: #d5e4ea;
  --bg: #d7f3ea;
  --focus: #12324a;
}

* { box-sizing: border-box; }

html { font-size: 18px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang HK", "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
  font-weight: 500;
  line-height: 1.5;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.7), transparent 32%),
    linear-gradient(180deg, #d9f3ea 0%, #d4eef8 100%);
}

.page {
  width: min(1120px, calc(100% - 20px));
  margin: 0 auto;
  padding: 14px 0 8px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-d);
  font-weight: 800;
  font-size: 0.95rem;
}

.goal {
  margin: 0;
  padding: 10px 12px;
  background: #e7f7ef;
  border: 2px solid #b7e0cc;
  border-radius: 16px;
  line-height: 1.55;
}

.goal-label {
  display: inline-block;
  margin-right: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
  font-size: 0.92em;
}

.layout {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.stage-card,
.panel,
.caption-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(18, 50, 74, 0.08);
}

.stage-card { padding: 12px 12px 10px; }

.step-row { margin: 0 0 8px; }

.step-badge {
  display: inline-block;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: #e7f6ef;
  color: var(--green-d);
  font-weight: 800;
}

.atmo-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 8px 12px;
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  text-align: center;
}

.atmo-banner strong {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.atmo-banner span { font-weight: 800; }

.atmo-banner[hidden] { display: none !important; }

.atmo-banner.pop { animation: pop 0.45s ease; }

.svg-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #d7f0fb;
}

#scene {
  display: block;
  width: 100%;
  height: auto;
}

.overlay { position: absolute; inset: 0; pointer-events: none; }

.tag {
  position: absolute;
  margin: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(18, 50, 74, 0.12);
  transform: translate(-50%, -50%);
}

.tag[hidden] { display: none !important; }

.tag.in { border: 2px solid var(--green); color: var(--green-d); }
.tag.out { border: 2px solid var(--blue); color: var(--blue); }
.tag.mol { border: 2px solid #1d6ea5; color: #1d4e89; }
.tag.dir-out { border: 2px solid var(--green); color: var(--green-d); background: #f3fbf7; }
.tag.dir-in { border: 2px solid var(--blue); color: var(--blue); background: #f3f7ff; }
.tag.same { border: 2px solid #0c6b52; background: #e7f6ef; }
.tag.dent { border: 2px solid #c2410c; color: #9a3412; background: #fff4e8; }
.tag.gap { border: 2px solid #1565c0; color: #0d47a1; background: #e8f3ff; }

.side { display: grid; gap: 12px; align-content: start; }

.panel { padding: 12px 14px 14px; }

.panel-title {
  margin: 0;
  font-weight: 800;
  font-size: 1.05rem;
}

.count {
  margin: 2px 0 8px;
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.count.pop { animation: pop 0.35s ease; }

.dotbank {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.mini {
  width: 14px;
  height: 14px;
  justify-self: center;
  border-radius: 50%;
  background: transparent;
  border: 2px solid #b7c9d6;
}

.mini.on { background: #1d6ea5; border-color: #1d6ea5; }
.mini.leaving { background: #ffb703; border-color: #e09a00; }
.mini.entering { background: #34a853; border-color: #1e7a3a; }
.mini.off { background: transparent; }

.meter-row {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.vmeter {
  display: grid;
  grid-template-columns: minmax(5.2rem, auto) 1fr auto;
  gap: 8px;
  align-items: center;
}

.meter-name,
.meter-value {
  margin: 0;
  font-weight: 800;
}

.meter-name { font-size: 1rem; }
.meter-value { font-size: 1.15rem; min-width: 1.5rem; text-align: right; }
.meter-value.in { color: var(--green-d); }
.meter-value.out { color: var(--blue); }
.meter-name.pop { animation: pop 0.45s ease; }

.meter-track {
  height: 26px;
  padding: 3px;
  border-radius: 999px;
  background: #e5eef3;
  border: 2px solid #c5d6e0;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: var(--level, 100%);
  border-radius: 999px;
}

.meter-fill.in { background: var(--green); }
.meter-fill.in.is-low { background: #e07a14; }
.meter-fill.out { background: #1565c0; }

.meter-note {
  margin: 10px 0 0;
  font-weight: 800;
}

.caption-card {
  margin-top: 12px;
  padding: 12px 14px 14px;
  min-height: 7.5rem;
}

.caption-card h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.3;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
  margin: 0 0 6px;
  color: var(--ink);
  font-weight: 800;
}

.key-item { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}

.swatch.in { background: #087a4e; }
.swatch.out { background: #1565c0; }

.same-note {
  padding: 0 8px;
  border-radius: 999px;
  background: #e7f6ef;
  color: var(--green-d);
}

#caption-body {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.55;
}

.recap { margin-top: 10px; }
.recap[hidden] { display: none !important; }

.chain {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}

.chain li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #e8f6ef;
  font-weight: 800;
}

.chain li span {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  flex: none;
}

.chain li + li::before {
  content: "→";
  margin-right: 2px;
  color: var(--green-d);
  font-weight: 800;
}

.note {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff6dc;
  border: 2px solid #e6c56e;
  color: #5c4108;
  font-weight: 800;
}

.note-icon { width: 48px; height: 48px; flex: none; }

.dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 4px;
}

.dots span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #c5d8e2;
}

.dots span.done { background: #7fbfa8; }
.dots span.now { width: 28px; background: var(--green); }

.controls {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -4px 16px rgba(18, 50, 74, 0.08);
}

#next { order: -1; grid-column: 1 / -1; }

.btn {
  min-height: 56px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary {
  min-height: 64px;
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-size: 1.35rem;
}

.btn-primary:hover { background: var(--green-d); border-color: var(--green-d); }

.btn-ghost {
  background: #fff;
  color: var(--green-d);
  border-color: #9fcec0;
  font-size: 1.1rem;
}

.btn-ghost:hover { background: #f3fbf7; }

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

.btn:active:not(:disabled) { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.floater {
  position: absolute;
  z-index: 3;
  transform: translate(-30%, -130%);
  color: var(--blue);
  font-weight: 800;
  font-size: 1.25rem;
  white-space: nowrap;
  text-shadow: 0 0 6px #fff, 0 1px 0 #fff;
  animation: floatUp 1s ease forwards;
  pointer-events: none;
}

.floater.in { color: var(--green-d); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.noscript {
  margin: 12px;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  font-weight: 800;
}

.drift { animation: drift 4.8s ease-in-out infinite; }

.shake { animation: shake 0.45s linear; }

@keyframes pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes floatUp {
  to { transform: translate(-30%, -230%); opacity: 0; }
}

@keyframes drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(7px, -8px); }
}

@keyframes shake {
  20% { transform: translateX(-2px); }
  40% { transform: translateX(2px); }
  60% { transform: translateX(-1px); }
  100% { transform: none; }
}

@media (min-width: 900px) {
  html { font-size: 18px; }

  .page { width: min(1120px, calc(100% - 32px)); padding-top: 18px; }

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

  .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }

  .tag { font-size: 1.05rem; padding: 3px 10px; }

  .vmeter {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 6px;
  }

  .meter-row {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .meter-track {
    width: 64px;
    height: 168px;
    margin: 0 auto;
    border-radius: 18px;
    display: flex;
    align-items: flex-end;
    padding: 4px;
  }

  .meter-fill {
    width: 100%;
    height: var(--level, 100%);
  }

  .meter-value { text-align: center; font-size: 1.25rem; }

  .controls {
    grid-template-columns: auto auto 1fr;
    border-radius: 18px;
  }

  #next {
    order: 0;
    grid-column: auto;
    justify-self: end;
    min-width: 240px;
  }
}

@media (max-width: 899px) {
  .tag.same,
  .tag.dir-out { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .drift,
  .shake,
  .pop,
  .floater,
  .atmo-banner.pop,
  .count.pop {
    animation: none !important;
  }
}
