/* 玉兔奔月：整體只有一個夜色主題（刻意單一深色） */
:root {
  color-scheme: dark;
  --ink: #0b1030;          /* 靛藍夜色，頁面底色 */
  --ink-deep: #060918;
  --panel: rgba(15, 20, 50, 0.74);
  --panel-line: rgba(247, 239, 214, 0.15);
  --moon: #f7efd6;         /* 月光象牙白，主要文字 */
  --mist: #aab2d8;         /* 月下霧藍，次要文字 */
  --mist-dim: #7d86b4;
  --gold: #f0b94d;         /* 桂花金，強調色 */
  --gold-soft: #ffd98a;
  --vermilion: #d8483a;    /* 印章朱紅，只用在印章與新紀錄 */
  --on-gold: #2a1c07;
  --glass: rgba(10, 14, 40, 0.5);

  --font-display: "LXGW WenKai TC", "Kaiti TC", "STKaiti", "BiauKai", "DFKai-SB", "KaiTi", serif;
  --font-body: "LXGW WenKai TC", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-latin: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;

  --col-w: 400px;          /* 由 JS 依畫面大小更新 */
  --title-gap: 160px;      /* 首頁底部留給地面和玉兔的高度，由 JS 更新 */
}

[hidden] { display: none !important; }

html { height: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--moon);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

/* UI 疊在遊戲欄位上方；JS 會把 left / width 對齊到遊戲欄位 */
#ui {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

#ui button { pointer-events: auto; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}

/* ---------- 按鈕 ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  line-height: 1.2;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.btn-primary {
  color: var(--on-gold);
  background: linear-gradient(180deg, #ffe6a8 0%, var(--gold) 100%);
  box-shadow: 0 10px 30px rgba(240, 185, 77, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 38px rgba(240, 185, 77, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.btn-primary:active { transform: translateY(1px) scale(0.99); }

.btn-ghost {
  color: var(--moon);
  background: rgba(247, 239, 214, 0.06);
  box-shadow: inset 0 0 0 1px var(--panel-line);
}

.btn-ghost:hover { background: rgba(247, 239, 214, 0.12); }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--panel-line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.icon-btn:hover { background: rgba(30, 38, 84, 0.7); }
.icon-btn:active { transform: scale(0.94); }

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--moon);
}

.icon-btn svg .stroke,
.icon-btn svg.stroke {
  fill: none;
  stroke: var(--moon);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btnSound[aria-pressed="true"] .icon-sound-off,
#btnSound[aria-pressed="false"] .icon-sound-on { display: none; }

/* ---------- 首頁 ---------- */
.toolbar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 16px;
  display: flex;
  gap: 10px;
}

.screen {
  position: absolute;
  inset: 0;
}

.title-screen {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-inline: 18px;
  padding-block: calc(env(safe-area-inset-top, 0px) + 16px) 0;
}

.title-block {
  align-self: flex-end;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 14px;
  justify-items: center;
  margin-top: 4px;
  animation: rise-in 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.title-vertical {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.14em;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(44px, calc(var(--col-w) * 0.14), 70px);
  line-height: 1;
  color: var(--moon);
  text-shadow: 0 0 26px rgba(255, 226, 160, 0.38), 0 2px 0 rgba(6, 9, 24, 0.35);
}

.title-vertical span { display: block; }

.title-sub {
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--font-latin);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--mist);
}

.seal {
  grid-column: 2;
  grid-row: 2;
  display: block;
  text-align: center;
  padding: 7px 6px;
  border-radius: 4px;
  background: var(--vermilion);
  color: #fff1e4;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.15;
  letter-spacing: 0.08em;
  outline: 1.2px solid rgba(255, 235, 220, 0.7);
  outline-offset: -4px;
  transform: rotate(-4deg);
  box-shadow: 0 4px 14px rgba(216, 72, 58, 0.35);
}

.title-bottom {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-bottom: var(--title-gap);
  animation: rise-in 1.2s 0.15s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.festival {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--gold-soft);
  text-shadow: 0 0 18px rgba(240, 185, 77, 0.35);
  text-wrap: balance;
}

.moon-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  text-align: left;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--panel-line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background-color 0.18s ease;
}

.moon-chip:hover { background: rgba(24, 31, 72, 0.62); }

.moon-chip-main {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--moon);
}

.moon-chip-sub {
  font-size: 13px;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}

.records,
.controls-hint {
  text-shadow: 0 1px 6px rgba(6, 9, 24, 0.95), 0 0 2px rgba(6, 9, 24, 0.9);
}

.records {
  margin: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 6px;
  font-size: 14px;
  color: var(--mist);
}

.records b {
  font-family: var(--font-latin);
  font-size: 19px;
  font-weight: 700;
  color: var(--moon);
  font-variant-numeric: tabular-nums;
}

.records .dot {
  width: 3px;
  height: 3px;
  margin-inline: 6px;
  border-radius: 50%;
  background: var(--mist-dim);
  align-self: center;
}

.controls-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--mist-dim);
  letter-spacing: 0.04em;
}

/* ---------- 遊戲中 HUD ---------- */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding-inline: 16px;
  padding-block: calc(env(safe-area-inset-top, 0px) + 12px) 0;
}

.hud-height {
  font-family: var(--font-latin);
  font-weight: 700;
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums lining-nums;
  text-shadow: 0 2px 12px rgba(6, 9, 24, 0.55);
}

.hud-height small {
  margin-left: 2px;
  font-size: 16px;
  color: var(--mist);
}

.hud-best {
  display: block;
  margin-top: 5px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  color: var(--mist);
}

.hud-phase {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--panel-line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

#hudMoon { width: 28px; height: 28px; display: block; }

.hud-phase-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.1;
  white-space: nowrap;
}

.hud-bar {
  display: block;
  width: 60px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(247, 239, 214, 0.14);
}

.hud-bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
}

.hud-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-stars {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-latin);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-star {
  width: 18px;
  height: 18px;
  fill: var(--gold);
  filter: drop-shadow(0 0 6px rgba(240, 185, 77, 0.6));
}

.hud-stars.bump .icon-star { animation: bump 0.3s ease; }

/* ---------- 提示 ---------- */
.toast {
  position: absolute;
  top: 24%;
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 36px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--gold-soft);
  text-shadow: 0 0 24px rgba(240, 185, 77, 0.5), 0 2px 10px rgba(6, 9, 24, 0.6);
}

.toast-sub {
  max-width: 22em;
  font-size: 15px;
  color: var(--moon);
  text-shadow: 0 1px 8px rgba(6, 9, 24, 0.8);
  text-wrap: balance;
}

/* 點月亮時的詩句 */
.toast.poem .toast-title {
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-indent: 0;
  line-height: 1.6;
  color: var(--moon);
  text-wrap: balance;
}

.toast.poem .toast-sub {
  font-size: 13px;
  color: var(--mist);
}

/* ---------- 視窗 ---------- */
.modal-layer {
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 7, 20, 0.42);
  pointer-events: auto;
  animation: fade-in 0.35s ease both;
}

.panel {
  position: relative;
  width: min(100%, 370px);
  max-height: calc(100% - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 26px 22px 22px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--panel-line), 0 30px 80px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  animation: panel-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 18%;
  right: 18%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(240, 185, 77, 0.7), transparent);
}

.panel-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
}

.panel-text {
  margin: 0 0 16px;
  color: var(--mist);
  text-align: center;
  text-wrap: pretty;
}

.panel-text.small {
  margin-top: 14px;
  font-size: 13px;
  text-align: left;
}

.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.panel-actions .btn {
  flex: 1;
  padding-inline: 12px;
  font-size: 17px;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px 10px;
  border-radius: 14px;
  background: rgba(247, 239, 214, 0.05);
}

.stat dt {
  font-size: 12px;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: var(--mist);
}

.stat dd {
  margin: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 4px;
  font-size: 13px;
  color: var(--mist);
}

.stat dd b {
  font-family: var(--font-latin);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--moon);
  font-variant-numeric: tabular-nums;
}

.stat-phase { align-items: center !important; }
.stat-phase b { font-family: var(--font-display) !important; font-size: 17px !important; }
#overMoon { width: 22px; height: 22px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--vermilion);
  color: #fff1e4;
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.poem {
  margin: 0 0 20px;
  text-align: center;
}

.poem blockquote {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.75;
  color: var(--moon);
  text-wrap: balance;
}

.poem figcaption {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--mist);
}

/* 玩法說明 */
.panel-help { width: min(100%, 390px); }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.legend li {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 10px;
  padding: 3px 8px 3px 4px;
  border-radius: 10px;
  background: rgba(247, 239, 214, 0.04);
}

.legend canvas { width: 40px; height: 40px; display: block; }

.legend b {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--moon);
  margin-right: 8px;
}

.legend span {
  font-size: 13px;
  line-height: 1.4;
  color: var(--mist);
}

.phase-track {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  text-align: center;
}

.phase-track li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: var(--mist);
}

.phase-track canvas { width: 26px; height: 26px; display: block; margin-bottom: 2px; }
.phase-track b { font-family: var(--font-display); font-size: 13px; font-weight: 400; color: var(--moon); }
.phase-track small { font-family: var(--font-latin); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 動畫 ---------- */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@media (max-height: 560px) {
  .title-vertical { font-size: 34px; }
  .seal { display: none; }
  .title-bottom { gap: 8px; }
  .moon-chip, .controls-hint { display: none; }
  .toast { top: 18%; }
}

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