/* 色票：夜色底、奶油字，珊瑚色只用在「我的勇者」與主要按鈕。 */
:root {
  --night: #1f1226;
  --panel: #2a1a33;
  --card: #372340;
  --button: #4a3052;
  --cream: #fbf1ea;
  --muted: #b9a6bd;
  --ink: #3a2626;
  --outline: #3d0f1e;
  --coral: #ff8280;
  --hp: #f2b84b;
  --dream: #ffd9d4;
  --mp: #8fb8ff;
  --poison: #c9e06a;
  --bad: #e8607a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--night);
  color: var(--cream);
  font: 16px/1.5 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

.page { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0; }
h2 { font-size: 18px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 16px 0 8px; color: var(--muted); font-weight: 500; }

/* ───── 場景 ─────
   場景圖（256px）放大約 2.8 倍置中成正方形；角色圖（128px）佔場景寬的 17.8%，
   兩者像素密度不同，跟 RO 一樣。左右兩側留給名牌、數值、排行榜和廣播。 */
.scene {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  border: 3px solid var(--outline);
  background: #1b1730;
  container-type: inline-size;
  font-size: clamp(9px, 1.5cqw, 16px);
}
.map {
  position: absolute; top: 0; bottom: 0; left: 50%; translate: -50% 0;
  aspect-ratio: 1; height: 100%;
  background: url("/assets/art/scene_garden_night.png") center / 100% 100% no-repeat;
  image-rendering: pixelated;
  container-type: size;
}
.sprite { display: block; width: 100%; image-rendering: pixelated; user-select: none; -webkit-user-drag: none; }
.scene.quake .map { animation: quake 0.18s linear 14; }
@keyframes quake { 25% { transform: translate(-0.4%, 0.3%); } 75% { transform: translate(0.4%, -0.3%); } }

.plate {
  position: absolute;
  background: rgb(42 26 51 / 0.88);
  border: 2px solid var(--outline);
  border-radius: 8px;
  padding: 0.5em 0.8em;
  z-index: 4;
}
.title-plate { top: 2%; left: 1.2%; width: 19.5%; display: grid; }
.title-plate span { color: var(--muted); font-size: 0.85em; }
.beauty-plate { top: 17%; left: 1.2%; width: 19.5%; display: grid; gap: 0.4em; }
.beauty-plate .gauges { width: 100%; }
.board { top: 2%; right: 1.2%; width: 19.5%; }
.board-row { display: flex; justify-content: space-between; gap: 1em; font-size: 0.9em; }
.url-plate { bottom: 2%; right: 1.2%; width: 19.5%; font-size: 0.85em; display: none; }
.display .url-plate { display: block; }

.banner {
  position: absolute; top: 3%; left: 50%; transform: translateX(-50%);
  max-width: 50%; text-align: center; z-index: 6;
  background: var(--cream); color: var(--ink);
  border: 3px solid var(--outline); border-radius: 999px; padding: 0.5em 1.4em; font-weight: 700;
}
/* 廣播：寬螢幕放在場景左側欄的下半部，手機放在場景下方，免得蓋住角色。 */
.stage { position: relative; }
.feed { position: absolute; left: 1.2%; bottom: 2%; width: 19.5%; display: grid; gap: 3px; z-index: 4; font-size: clamp(10px, 0.95vw, 14px); }
.feed-line { background: rgb(31 18 38 / 0.85); border-radius: 6px; padding: 1px 8px; }
/* 手機直式：場景改成滿版正方形，名牌和睡美人數值縮小疊在天空那一條，廣播放到場景下方。 */
@media (max-width: 700px) {
  body:not(.display) .page { padding: 8px; gap: 10px; }
  body:not(.display) .scene { aspect-ratio: 1; font-size: 11px; border-width: 2px; }
  body:not(.display) .map { left: 0; translate: none; width: 100%; height: 100%; }
  body:not(.display) .plate { padding: 0.25em 0.5em; border-width: 1px; background: rgb(31 18 38 / 0.8); }
  body:not(.display) .title-plate { top: 1.5%; left: 1.5%; width: 34%; font-size: 10px; }
  body:not(.display) .beauty-plate { top: 1.5%; left: auto; right: 1.5%; width: 34%; gap: 0.2em; }
  body:not(.display) .beauty-plate .gauge span { width: 2.4em; }
  body:not(.display) .board { display: none; }
  body:not(.display) .banner { top: auto; bottom: 2%; max-width: 92%; font-size: 12px; }
  body:not(.display) .feed { position: static; width: auto; margin-top: 8px; font-size: 13px; }
  body:not(.display) .monster .gauges { width: 8em; bottom: auto; top: 92%; }
  /* 打開手機最常做的是行動，排在自己的勇者資料前面。 */
  body:not(.display) #notice { order: -3; }
  body:not(.display) #install { order: -2; }
  body:not(.display) #actions { order: -1; }
}

.gauges { display: grid; gap: 0.25em; justify-items: center; width: 12em; }
.gauge { display: flex; align-items: center; gap: 0.4em; width: 100%; font-size: 0.8em; }
.gauge span { width: 3em; text-align: right; }
.gauge-track { flex: 1; height: 0.8em; background: var(--night); border: 2px solid var(--outline); border-radius: 999px; overflow: hidden; }
.gauge-fill { height: 100%; background: var(--hp); transition: width 0.6s; }
.gauge.dream .gauge-fill { background: var(--dream); }
.gauge.mp .gauge-fill { background: var(--mp); }
.gauge.poison .gauge-fill { background: var(--poison); }

.tag { background: var(--card); border: 2px solid var(--outline); border-radius: 999px; padding: 0 0.7em; font-size: 0.8em; }
.tag.bad { background: var(--bad); color: var(--ink); font-weight: 700; }
.tag.buff { background: var(--dream); color: var(--ink); }
.aura { display: flex; flex-wrap: wrap; gap: 0.3em; }
.aura:empty { display: none; }

.bubble {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--cream); color: var(--ink); border: 2px solid var(--outline);
  border-radius: 10px; padding: 0.2em 0.7em; white-space: nowrap; font-size: 0.85em; z-index: 3;
}

/* 睡美人：躺在床上；醒來時換成站姿圖，站在床前。床是場景圖的一部分。 */
.beauty { position: absolute; left: 41.1%; top: 25%; width: 17.8%; z-index: 2; transition: top 0.6s; }
.beauty .bubble { bottom: auto; top: -1.6em; }
/* 夢話：雲朵感、淡一點，跟醒著說話分開 */
.beauty .bubble.dreaming { background: var(--dream); border-style: dashed; border-radius: 999px; font-style: italic; opacity: 0.92; }
.beauty[data-state="awake"] { top: 24%; }
.beauty[data-state="deep"] .sleeper { filter: brightness(0.55) saturate(0.6); }
.beauty.dizzy .sleeper { animation: sway 2s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes sway { 50% { rotate: 6deg; } }
.zzz { position: absolute; left: 78%; top: 2%; color: var(--cream); font-weight: 700; pointer-events: none; }
.zzz span { position: absolute; animation: drift-up 3.6s ease-in infinite; opacity: 0; }
.zzz span:nth-child(1) { font-size: 0.8em; }
.zzz span:nth-child(2) { font-size: 1em; animation-delay: 1.2s; left: 0.5em; }
.zzz span:nth-child(3) { font-size: 1.25em; animation-delay: 2.4s; left: 1em; }
@keyframes drift-up { 0% { opacity: 0; translate: 0 1em; } 20% { opacity: 1; } 100% { opacity: 0; translate: 0.8em -2.2em; } }
.beauty[data-state="awake"] .zzz { display: none; }
@keyframes drift { 50% { transform: translateY(-0.5em); } }

.monster { position: absolute; left: 70%; top: 36%; width: 17.8%; display: grid; justify-items: center; gap: 0.3em; z-index: 2; }
.monster .gauges { width: 10em; position: absolute; bottom: 100%; }
.blob { animation: drift 2.4s ease-in-out infinite; }

/* 勇者：只站在草地上，左右各留一點給樹叢。初心者站後排，轉職者站前排。 */
.heroes { position: absolute; inset: 0 9%; pointer-events: none; z-index: 3; }
.hero { position: absolute; width: 17.8cqw; translate: -50% 0; display: grid; justify-items: center; transition: left 0.8s, top 0.8s; }
.hero.back { top: 50%; scale: 0.85; }
.hero.front { top: 62%; }
/* 相鄰的勇者前後錯開，名牌才不會疊在一起。 */
.hero.stagger { margin-top: 7cqh; }
.figure { transition: rotate 0.4s; }
.hero.down .figure { rotate: 90deg; translate: 0 25%; filter: grayscale(0.7); }
.hero.shielded .figure { filter: drop-shadow(0 0 0.4em rgb(143 184 255 / 0.9)); }
.hero.gifted .nameplate::after { content: "✿"; margin-left: 0.3em; color: var(--dream); }
.nameplate { margin-top: -0.6em; display: flex; align-items: center; gap: 0.25em; background: rgb(31 18 38 / 0.85); border: 2px solid var(--outline); border-radius: 6px; padding: 0 0.5em; font-size: 0.75em; white-space: nowrap; }
.nameplate span { color: var(--muted); margin-left: 0.25em; }
.nameplate .badge { width: 1.3em; height: 1.3em; margin-left: -0.2em; }
/* 自己的勇者：名牌外加一圈奶油色光暈。訂閱者：依等級換底框（只有外觀，不影響數值）。 */
.hero.mine .nameplate { box-shadow: 0 0 0 2px var(--cream); }
.hero[data-sub="1"] .nameplate { border-color: var(--coral); }
.hero[data-sub="2"] .nameplate { border-color: var(--coral); background: rgb(110 40 62 / 0.92); }
.hero[data-sub="3"] .nameplate { border-color: var(--hp); background: rgb(96 62 22 / 0.92); }

/* 個性：平常的小動作 */
.hero[data-personality="brave_fool"] .figure { animation: swing 1.2s ease-in-out infinite; transform-origin: 50% 90%; }
.hero[data-personality="coward"] .figure { animation: shiver 2.5s steps(2) infinite; }
.hero[data-personality="sleepy"] .figure { animation: nod 3.5s ease-in-out infinite; transform-origin: 50% 90%; }
.hero[data-personality="showoff"] .figure { animation: hop 1.6s ease-in-out infinite; }
.hero[data-personality="worker"] .figure { animation: sigh 5s ease-in-out infinite; transform-origin: 50% 100%; }
.hero.down .figure { animation: none; }
@keyframes swing { 50% { rotate: 6deg; } }
@keyframes shiver { 50% { translate: 0.12em 0; } }
@keyframes nod { 60% { rotate: 8deg; translate: 0 0.2em; } }
@keyframes hop { 50% { translate: 0 -0.5em; } }
@keyframes sigh { 90% { scale: 1; } 95% { scale: 1.06 0.94; } }

/* 個性：地面搖晃時的反應 */
.hero[data-move="front"] { top: 70%; }
.hero[data-move="panic"] { animation: panic 0.9s ease-in-out infinite; }
.hero[data-move="late"] { transition-delay: 2.5s; top: 66%; }
.hero[data-move="tumble"] .figure { animation: tumble 1.2s ease-in-out 2; }
.hero[data-move="trudge"] { transition-duration: 4s; top: 67%; }
@keyframes panic { 25% { translate: calc(-50% - 3em) 0; } 75% { translate: calc(-50% + 3em) 0; } }
@keyframes tumble { 50% { rotate: 360deg; translate: 0 0.6em; } }

/* ───── 操作區 ───── */
.display .panel { display: none; }
.display .page { max-width: none; padding: 0; }
.display .scene { border-radius: 0; border: 0; height: 100vh; width: 100vw; aspect-ratio: auto; }

.panel { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.card { background: var(--panel); border: 2px solid var(--outline); border-radius: 12px; padding: 16px; display: grid; gap: 8px; }
.card .gauge { font-size: 14px; }
.notice { grid-column: 1 / -1; background: var(--cream); color: var(--ink); font-weight: 700; }

label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input:not([type="radio"]), select {
  font: inherit; color: var(--cream); background: var(--card);
  border: 2px solid var(--outline); border-radius: 8px; padding: 8px 10px; min-height: 44px;
}
button {
  font: inherit; color: var(--cream); background: var(--button);
  border: 2px solid var(--outline); border-radius: 10px; padding: 8px 14px; min-height: 44px;
  cursor: pointer; display: grid; text-align: left;
}
button small { color: var(--muted); font-size: 12px; }
button.primary { background: var(--coral); color: var(--ink); font-weight: 700; text-align: center; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:is(button, input, select):focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.buttons { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
form { display: grid; gap: 8px; }
.look { display: flex; gap: 12px; align-items: center; }
.look-preview { width: 112px; flex: none; background: var(--card); border: 2px solid var(--outline); border-radius: 10px; }
.look-fields { display: grid; gap: 8px; flex: 1; }
.twitch-row { display: grid; gap: 6px; }
.install p { margin: 0; }

/* ───── 管理後台 ───── */
.admin-tabs { display: flex; gap: 8px; }
.admin-tabs button { flex: none; text-align: center; }
.admin-tabs button[aria-pressed="true"] { background: var(--coral); color: var(--ink); font-weight: 700; }
/* 管理後台畫面：藏起遊戲場景和玩家的卡片，只留後台 */
.admin-view .stage { display: none !important; }
body:not(.admin-view) #admin { display: none !important; }
.admin-view .page { max-width: 1400px; }
.admin { grid-column: 1 / -1; border-color: var(--coral); }
.admin-col { display: grid; gap: 8px; align-content: start; }
.admin-col h3 { margin: 4px 0 0; }
/* 電腦上兩欄：左邊現況與送藥水、右邊勇者名單；訂單在左下 */
@media (min-width: 900px) {
  .admin-view .admin {
    grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.4fr);
    grid-template-areas: "head head" "status heroes" "orders heroes";
    column-gap: 24px;
  }
  .admin-view .admin > .admin-head { grid-area: head; }
  .admin-view .admin-col-status { grid-area: status; }
  .admin-view .admin-col-heroes { grid-area: heroes; }
  .admin-view .admin-col-orders { grid-area: orders; }
  .admin-view .admin-col-heroes .admin-list { max-height: 70vh; }
  .admin-view .admin-row { grid-template-columns: 1fr auto; align-items: center; }
}
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.admin-head h2 { margin: 0; }
.admin-head-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.button-link { display: grid; place-items: center; min-height: 44px; padding: 8px 14px; border-radius: 10px; background: var(--coral); color: var(--ink); font-weight: 700; text-decoration: none; border: 2px solid var(--outline); }
.admin-message { margin: 0; color: var(--dream); min-height: 1.5em; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.admin-link { flex: 1; min-width: 220px; }
.admin-potions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.admin-potions button { grid-column: 1 / -1; text-align: center; }
.admin-list { display: grid; gap: 6px; max-height: 420px; overflow: auto; }
.admin-row { display: grid; gap: 6px; background: var(--card); border: 2px solid var(--outline); border-radius: 10px; padding: 8px 10px; }
.admin-row small { color: var(--muted); }
.admin-row.frozen { opacity: 0.6; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-actions button { min-height: 36px; padding: 4px 10px; }
.admin-order { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 10px; background: var(--card); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.admin-order small { grid-column: 1 / -1; color: var(--muted); }
.order-paid { color: var(--poison); }
.order-failed, .order-mismatch { color: var(--bad); }
.admin-test summary { cursor: pointer; color: var(--muted); }
.admin-test .buttons { margin-top: 8px; }
.choices { display: grid; gap: 6px; }
.choice { display: flex; align-items: center; gap: 10px; background: var(--card); border: 2px solid var(--outline); border-radius: 10px; padding: 8px 10px; color: var(--cream); cursor: pointer; }
.choice span { display: grid; }
.choice small { color: var(--muted); }
.choice:has(input:checked) { border-color: var(--cream); }

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

/* ───── 找回連結 ───── */
/* 新玩家先看到「加入」；從主畫面打開（大多是已經有勇者的人）時先看到「找回」 */
#restore { order: 1; }
.standalone #restore { order: -2; }
.keep summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.keep[open] summary { margin-bottom: 4px; }
.keep p { margin: 0; }
.keep input { font-size: 13px; }

/* ───── 數據 ───── */
.stats { grid-column: 1 / -1; border-color: var(--coral); }
body:not(.stats-view) #stats { display: none !important; }
.stats-view #admin { display: none !important; }
.admin-view #panel > .card:not(.admin-only) { display: none !important; }
.stats p { margin: 0; }
.stat-tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-tile { display: grid; gap: 2px; background: var(--card); border: 2px solid var(--outline); border-radius: 10px; padding: 10px 12px; }
.stat-tile strong { font-size: 24px; color: var(--cream); font-variant-numeric: tabular-nums; }
.stat-tile small { color: var(--muted); }
.stats-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats-wide { grid-column: 1 / -1; }
.stats-block { display: grid; gap: 8px; align-content: start; }
.stats-block h3 { margin: 0; }
.stats-block-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { min-height: 32px; padding: 2px 10px; font-size: 13px; text-align: center; }
.seg button[aria-pressed="true"] { background: var(--coral); color: var(--ink); font-weight: 700; }
/* 長條圖：只有一個數列，用一個顏色；格線與軸線都很淡 */
.bars {
  display: grid; grid-template-columns: repeat(var(--count), minmax(0, 1fr)); gap: 2px;
  height: 180px; align-items: end; padding-top: 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 40%, transparent);
}
.bars-hours { height: 140px; }
.bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; outline: none; cursor: default; }
.bar-fill { width: min(70%, 28px); background: var(--dream); border-radius: 4px 4px 0 0; min-height: 0; transition: filter 0.15s; }
.bar.now .bar-fill { background: var(--coral); }
.bar:hover .bar-fill, .bar:focus-visible .bar-fill { filter: brightness(1.15); outline: 2px solid var(--cream); outline-offset: 1px; }
.bar-value { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.bar-label { position: absolute; top: 100%; margin-top: 4px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars + details { margin-top: 20px; }
.bars-hours { margin-bottom: 24px; }
.stats-table-wrap { overflow-x: auto; }
.stats-table { border-collapse: collapse; font-size: 13px; width: 100%; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 4px 8px; text-align: right; border-bottom: 1px solid color-mix(in srgb, var(--muted) 25%, transparent); white-space: nowrap; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.stats-dl dt { color: var(--muted); }
.stats-dl dd { margin: 0; }
.stats-dl .stats-note { grid-column: 1 / -1; font-size: 13px; }
@media (max-width: 700px) {
  /* 手機上日期太擠，隔一天標一次（保留今天） */
  .bars:not(.bars-hours) .bar:nth-child(odd) .bar-label { visibility: hidden; }
  .bar-value { font-size: 9px; }
}

/* ───── 購買留言 ───── */
.message-field { display: grid; gap: 4px; }
.message-hint { font-size: 13px; color: var(--muted); }
.message-row strong { color: var(--cream); }
