[hidden] { display: none !important; }

:root { color-scheme: dark; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  overflow: hidden;
  font-family: "Noto Sans TC", "PingFang TC", sans-serif;
  /* 手機：不捲動、不回彈、不雙擊縮放、不長按選取或跳出選單 */
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
.panel, .panel * { touch-action: manipulation; }
input { -webkit-user-select: text; user-select: text; }
#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}
.controls {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 12px;
}
.controls button {
  font: 900 var(--text-sm) "Noto Serif TC", serif;
  color: var(--ink);
  background: var(--ochre);
  border: 4px solid var(--ink);
  border-radius: 6px;
  padding: 10px 22px;
  box-shadow: 5px 6px 0 var(--ink);
  cursor: pointer;
}
.controls .button-link {
  font: 900 var(--text-sm) "Noto Serif TC", serif;
  color: var(--ink);
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 6px;
  padding: 10px 22px;
  box-shadow: 5px 6px 0 var(--ink);
  text-decoration: none;
}
.controls button, .mute { touch-action: none; }
/* 觸控裝置：按鈕列抬高，讓出畫面底部的關卡與倒數字 */
html.touch .controls { bottom: calc(40px + env(safe-area-inset-bottom, 0px)); right: calc(16px + env(safe-area-inset-right, 0px)); align-items: flex-end; }
/* 橫放：按鈕直排，收進戰場右側的空白（main.js 的 TOUCH_GUTTER = 128px） */
@media (orientation: landscape) {
  html.touch .controls { flex-direction: column; align-items: center; right: calc(16px + (96px - 84px) / 2); }
  html.touch .controls .ab[data-hint]:not([data-hint=""])::after { left: auto; right: calc(100% + 8px); top: 50%; transform: translateY(-50%); }
}
.controls button:disabled { background: var(--disabled); cursor: not-allowed; }
.controls button:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
#dash { background: var(--cream); width: 84px; height: 84px; padding: 0; border-radius: 50%; }
.panel .lead { margin: 0; line-height: 1.6; }
/* --kb：虛擬鍵盤蓋住的高度（main.js 由 visualViewport 算出），讓立碑框浮在鍵盤上方 */
#memorial { top: auto; bottom: calc(24px + env(safe-area-inset-bottom, 0px) + var(--kb, 0px)); transform: translateX(-50%); }
.controls .ab { background: var(--cream); width: 84px; height: 84px; padding: 0; border-radius: 50%; position: relative; font-size: var(--text-xs); }
#ab-block { width: 96px; height: 96px; background: var(--ochre); }
.controls .ab.low, #ab-block.low { background: var(--disabled); color: var(--cream); box-shadow: 2px 3px 0 var(--ink); }
.controls .ab[data-hint]:not([data-hint=""])::after {
  content: attr(data-hint);
  position: absolute; left: 50%; top: -28px; transform: translateX(-50%);
  white-space: nowrap; font: 700 var(--text-xs) "Noto Sans TC", sans-serif;
  background: var(--ink); color: var(--cream); padding: 2px 8px; border-radius: 4px;
}
.controls button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 2px 3px 0 var(--ink); }

/* 浮動搖桿（input.js 依手指位置移動） */
.joy {
  position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none;
}
.joy::before, .joy-knob {
  content: ""; position: absolute; border-radius: 50%; border: 4px solid var(--ink);
}
.joy::before { width: 120px; height: 120px; left: -64px; top: -64px; background: color-mix(in oklch, var(--cream) 25%, transparent); }
.joy-knob { width: 52px; height: 52px; left: -30px; top: -30px; background: var(--ochre); }
/* 沒按的時候停在戰場外的空白處，提示拇指放這裡 */
.joy.rest { opacity: 0.55; }

.mute {
  position: fixed; right: calc(12px + env(safe-area-inset-right, 0px)); top: calc(12px + env(safe-area-inset-top, 0px));
  font: 700 var(--text-xs) "Noto Sans TC", sans-serif; color: var(--cream); background: color-mix(in oklch, var(--ink) 80%, transparent);
  border: 3px solid var(--cream); border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.mute[aria-pressed="true"] { color: var(--disabled); border-color: var(--disabled); }
.mute:focus-visible { outline: 3px solid var(--ochre); outline-offset: 2px; }

/* 直式手機：畫面等比縮放（上下留黑邊），提示轉成橫式 */
.rotate-hint { display: none; }
@media (orientation: portrait) {
  html.touch .rotate-hint {
    /* 和右上的音效鈕同一列，把第二列讓給史料註腳，戰場才不會被壓到 */
    display: block; position: fixed; left: calc(12px + env(safe-area-inset-left, 0px)); top: calc(12px + env(safe-area-inset-top, 0px));
    margin: 0; padding: 6px 10px 6px 36px; white-space: nowrap; pointer-events: none;
    font: 700 var(--text-xs) "Noto Sans TC", sans-serif; color: var(--ink); background: var(--cream);
    border: 3px solid var(--ink); box-shadow: 4px 5px 0 var(--ink);
  }
  html.touch .rotate-hint::before {
    content: ""; position: absolute; left: 11px; top: 50%; width: 14px; height: 22px; margin-top: -11px;
    border: 3px solid var(--ink); border-radius: 3px; box-sizing: border-box;
    animation: rotate-phone 2s ease-in-out infinite;
  }
}
@keyframes rotate-phone { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (prefers-reduced-motion: reduce) { html.touch .rotate-hint::before { animation: none; transform: rotate(-90deg); } }
.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); margin: 0;
  background: var(--ink); color: var(--cream); border: 3px solid var(--ochre); border-radius: 6px;
  padding: 8px 16px; font-weight: 700;
}
.debug-hud {
  position: fixed;
  top: 8px;
  left: 8px;
  background: color-mix(in oklch, var(--ink) 85%, transparent);
  color: var(--cream);
  font: var(--text-xs)/1.4 ui-monospace, Menlo, monospace;
  padding: 8px 10px;
  border-radius: 4px;
  pointer-events: auto;
}
.debug-hud pre { margin: 0 0 6px; }
.debug-hud button { font: inherit; }
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  background: var(--cream);
  color: var(--ink);
  border: 5px solid var(--ink);
  box-shadow: 10px 12px 0 var(--ink);
  padding: 24px 24px 20px;
  display: grid;
  gap: 14px;
}
.panel h1 { font: 900 var(--text-xl)/1.2 "Noto Serif TC", serif; margin: 0; border-bottom: 5px solid var(--red); padding-bottom: 8px; }
.panel .field { display: grid; gap: 6px; font-weight: 700; }
.panel input {
  font: 500 var(--text-xs) "Noto Sans TC", sans-serif;
  padding: 8px 10px;
  border: 3px solid var(--ink);
  background: var(--paper3);
  color: var(--ink);
  border-radius: 4px;
}
.panel .chars { border: 0; padding: 0; margin: 0; display: flex; gap: 18px; flex-wrap: wrap; }
.panel .chars legend { font-weight: 700; margin-bottom: 6px; }
.panel .msg { margin: 0; min-height: 1.4em; color: var(--red); font-weight: 700; }
#locked .msg { color: var(--ink); font-weight: 500; }
.panel .row { display: flex; gap: 12px; flex-wrap: wrap; }
.panel button, .panel .button {
  font: 900 var(--text-sm) "Noto Serif TC", serif;
  color: var(--ink);
  background: var(--ochre);
  border: 4px solid var(--ink);
  border-radius: 6px;
  padding: 8px 22px;
  box-shadow: 4px 5px 0 var(--ink);
  cursor: pointer;
  text-decoration: none;
}
.panel .secondary { background: var(--cream); }
.panel .lead a { color: var(--ink); font-weight: 700; }
.panel button:focus-visible, .panel .button:focus-visible, .panel input:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
.debug-hud .netsim { display: flex; gap: 6px; margin-top: 6px; }
.debug-hud .netsim label { display: grid; gap: 2px; }
.debug-hud .netsim input { width: 56px; font: inherit; }

/* 手機橫式（高度很矮）：面板縮小，立碑框改成一列，避免被鍵盤擠掉 */
@media (max-height: 520px) {
  .panel { padding: 12px 16px 12px; gap: 8px; box-shadow: 6px 7px 0 var(--ink); max-height: calc(100dvh - 24px); overflow: auto; }
  .panel h1 { font-size: var(--text-base); padding-bottom: 4px; border-bottom-width: 4px; }
  .panel button, .panel .button { font-size: var(--text-xs); padding: 6px 18px; }
  .panel input { padding: 6px 8px; }
  #memorial { bottom: calc(8px + var(--kb, 0px)); width: min(520px, calc(100vw - 32px)); grid-template-columns: 1fr auto; align-items: end; }
  #memorial h1, #memorial .msg { grid-column: 1 / -1; }
  #memorial .row { order: 1; }
  #memorial .msg { order: 2; }
  #memorial .lead, #memorial .msg:empty { display: none; }
  #memorial .row { flex-wrap: nowrap; }
  .controls .ab, #dash { width: 72px; height: 72px; }
  #ab-block { width: 82px; height: 82px; }
}
