:root {
  --ink: #f4f1ff;
  --gold: #ffd45e;
  --panel: rgba(18, 12, 38, 0.92);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0818;
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, #1d1440, #08060f 75%);
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #7fd4ff;
  box-shadow: 0 0 0 2px #2a1f4d, 0 10px 40px rgba(0, 0, 0, .6);
  touch-action: none;
}

.hidden { display: none !important; }

/* ------------------------- 覆蓋畫面 ------------------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(6, 4, 16, .72);
  backdrop-filter: blur(2px);
  z-index: 20;
}

.panel {
  width: min(440px, 92vw);
  max-height: 92vh;
  overflow: auto;
  text-align: center;
  padding: 18px 18px 20px;
  border: 2px solid #4b3a86;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

.panel h1 {
  margin: 2px 0 4px;
  font-size: clamp(28px, 8vw, 44px);
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 3px 0 #7a3f14, 0 0 18px rgba(255, 212, 94, .35);
}

.panel h1 span { color: #ff8fb0; }

.panel h2 {
  margin: 2px 0 10px;
  font-size: clamp(20px, 6vw, 30px);
  color: var(--gold);
}

.sub {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: 2px;
  color: #9f95c8;
}

.bigbtn {
  display: block;
  width: 100%;
  margin: 10px 0 12px;
  padding: 14px 10px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #24123a;
  background: linear-gradient(#ffe58a, #ffc23d);
  border: none;
  border-bottom: 4px solid #b8791b;
  border-radius: 10px;
  cursor: pointer;
}

.bigbtn:active { transform: translateY(2px); border-bottom-width: 2px; }

.help {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.75;
  color: #cfc7ee;
  text-align: left;
}

.help p { margin: 2px 0; }
.help b { color: var(--gold); }

.carted { margin: -4px 0 8px; font-size: 13px; color: #ffd9e2; }

.best, .score { margin: 10px 0 0; font-size: 13px; color: #cfc7ee; }
.score b { color: var(--gold); font-size: 17px; }

/* ------------------------- 系統鍵 ------------------------- */
#sysbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 15;
}

.sysbtn {
  width: 38px;
  height: 38px;
  font-size: 17px;
  line-height: 1;
  color: var(--ink);
  background: rgba(20, 14, 44, .6);
  border: 1px solid #4b3a86;
  border-radius: 9px;
  cursor: pointer;
}

/* ------------------------- 觸控搖桿 ------------------------- */
#pad {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.padside {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
  pointer-events: none;
}

.padleft { left: max(14px, env(safe-area-inset-left)); }
.padright { right: max(14px, env(safe-area-inset-right)); align-items: flex-end; }

.btn {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 700;
  color: #fff;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  background: rgba(30, 20, 60, .45);
  backdrop-filter: blur(2px);
  touch-action: none;
  cursor: pointer;
}

.btn.is-down { background: rgba(255, 212, 94, .55); transform: scale(.94); }

.dir { width: 64px; height: 64px; font-size: 22px; }
.act { width: 62px; height: 62px; font-size: 16px; }
.at { width: 76px; height: 76px; font-size: 19px; background: rgba(226, 70, 92, .5); }
.jp { background: rgba(63, 208, 224, .42); }
.sp { width: 54px; height: 54px; font-size: 13px; background: rgba(111, 240, 200, .38); }

/* 橫向、螢幕矮的時候縮小按鈕，避免擋住畫面 */
@media (max-height: 420px) {
  .dir { width: 56px; height: 56px; }
  .act { width: 54px; height: 54px; font-size: 14px; }
  .at { width: 66px; height: 66px; font-size: 17px; }
  .sp { width: 48px; height: 48px; font-size: 12px; }
}

/* 直向手機：畫面往上擺，下方留給虛擬按鍵 */
@media (orientation: portrait) {
  #wrap { align-items: center; padding-bottom: 20vh; }
}

/* ------------------- 封面插畫（assets/ 有檔案才會出現） ------------------- */
.cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  z-index: 0;
}

.cover-wide { display: none; }

/* 橫向優先用寬版；沒有寬版時（.no-wide）仍用直版 */
@media (orientation: landscape) {
  .screen.has-wide .cover { display: none; }
  .screen.has-wide .cover-wide { display: block; }
}

.screen.has-art { background: #06040f; }

.screen.has-art::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(to bottom,
    rgba(6, 4, 16, .55) 0%,
    rgba(6, 4, 16, .12) 35%,
    rgba(6, 4, 16, .82) 78%,
    rgba(6, 4, 16, .95) 100%);
}

.screen .panel { position: relative; z-index: 2; }

.screen.has-art .panel {
  background: rgba(12, 8, 26, .74);
  backdrop-filter: blur(8px);
  border-color: rgba(255, 212, 94, .45);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
}

/* 有插畫時把面板推到下半部，讓角色露出來 */
.screen.has-art { align-items: flex-end; }
.screen.has-art .panel { margin-bottom: 2vh; }

/* 說明收合起來 */
details.help > summary {
  cursor: pointer;
  list-style: none;
  margin: 4px 0 2px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--gold);
  text-align: center;
}

details.help > summary::-webkit-details-marker { display: none; }
details.help > summary::after { content: ' ▾'; }
details.help[open] > summary::after { content: ' ▴'; }

/* 結算畫面的哭哭立繪 */
.cryart {
  display: block;
  width: min(360px, 82vw);
  height: auto;
  margin: -2px auto 10px;
  border-radius: 10px;
  border: 2px solid rgba(255, 212, 94, .45);
  image-rendering: pixelated;
}

.verdict { margin: 6px 0 0; font-size: 13px; color: #cfc7ee; }
.verdict b { color: var(--gold); letter-spacing: 2px; }

.story p { margin: 6px 0; line-height: 1.8; }
.story .tiny { font-size: 11.5px; color: #9f95c8; }

/* 橫向且夠寬時，面板靠左，右邊留給插畫裡的角色 */
@media (orientation: landscape) and (min-width: 680px) {
  .screen.has-art {
    align-items: center;
    justify-content: flex-start;
    padding-left: max(5vw, env(safe-area-inset-left));
  }
  .screen.has-art .panel {
    width: min(400px, 46vw);
    margin-bottom: 0;
  }
  .screen.has-art::before {
    background: linear-gradient(to right,
      rgba(6, 4, 16, .92) 0%,
      rgba(6, 4, 16, .72) 42%,
      rgba(6, 4, 16, .15) 78%,
      rgba(6, 4, 16, .05) 100%);
  }
}

/* ------------------------- 選角 ------------------------- */
.chars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 6px;
}

.charcard {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 4px 6px;
  font: inherit;
  color: var(--ink);
  background: rgba(30, 22, 58, .6);
  border: 2px solid #4b3a86;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: transform .12s, border-color .12s, background .12s;
}

.charcard:active { transform: scale(.97); }

.charcard.is-on {
  border-color: var(--gold);
  background: rgba(255, 212, 94, .16);
  box-shadow: 0 0 14px rgba(255, 212, 94, .25);
}

.charcard.is-locked { cursor: not-allowed; opacity: .55; }
.charcard.is-locked .cface { filter: grayscale(1) brightness(.6); }

.charcard .cface {
  display: block;
  width: 100%;
  max-width: 74px;
  aspect-ratio: 1;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .25);
  object-fit: cover;
}

.charcard .cname { display: block; font-size: 13px; font-weight: 700; }
.charcard .cdiff { display: block; font-size: 11px; color: #a99fd0; }
.charcard.is-on .cdiff { color: var(--gold); }

.charcard .clock {
  position: absolute;
  inset: 6px 4px 38px;   /* 只蓋住頭像，讓名字與難度露出來 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  line-height: 1.3;
  color: #ffe4a8;
  text-align: center;
  padding: 4px;
  background: rgba(10, 6, 24, .68);
  border-radius: 10px;
}

.clock b { font-size: 17px; }

.blurb {
  margin: 2px 0 4px;
  min-height: 34px;
  font-size: 12px;
  line-height: 1.6;
  color: #cfc7ee;
}

.blurb .todo { color: #a99fd0; }

.smallbtn {
  display: block;
  width: 100%;
  margin: -4px 0 2px;
  padding: 9px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: rgba(30, 22, 58, .6);
  border: 1px solid #4b3a86;
  border-radius: 9px;
  cursor: pointer;
}

.smallbtn:active { transform: translateY(1px); }

/* ------------------------- 過場 ------------------------- */
.cutskip {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  padding: 7px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: rgba(20, 14, 44, .7);
  border: 1px solid #4b3a86;
  border-radius: 9px;
  cursor: pointer;
  z-index: 18;
}

.cutskip:active { transform: translateY(1px); }

.replay { margin-top: 10px; display: grid; gap: 6px; }
.replay .smallbtn { margin: 0; }
