/* =========================================================
   d9-y0w0y-d11.rsvp — 公告頁樣式
   單一畫面，不捲動。尺寸綁在 vh / vw 上，
   小螢幕靠 clamp 與短螢幕 media query 收斂，不靠溢出。
   ========================================================= */

/* --- 可選：中文像素字型 -------------------------------------
   把 Cubic 11（俐方體 11 號，OFL 授權）的 woff2 放進
   assets/fonts/Cubic_11.woff2，中文也會變成像素字。
   檔案不存在時瀏覽器會靜默 fallback，不會壞掉。         */
@font-face {
  font-family: "Cubic 11";
  src: url("assets/fonts/Cubic_11.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+2E80-2EFF, U+3000-303F, U+3100-312F, U+4E00-9FFF, U+FF00-FFEF;
}

:root {
  --void:   #0a0818;
  --night:  #171034;
  --deep:   #2b1c5e;
  --ink:    #f4f1ff;
  --dim:    #8a83bd;
  --d9:     #ff4d6d;
  --d11:    #3ef2c0;
  --gold:   #ffd23f;
  --violet: #7b5cff;
  --shadow: #04030c;

  --pixel: "Press Start 2P", "Courier New", ui-monospace, monospace;
  --han: "Cubic 11", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei",
         "Hiragino Sans GB", system-ui, sans-serif;

  /* --die-k / --gap-k 由 app.js 的 fit() 在畫面塞不下時往下調 */
  --die-base: clamp(112px, min(29vh, 44vw), 196px);
  --gap-base: clamp(.45rem, 2vh, 1.15rem);
  --die-k: 1;
  --gap-k: 1;
  --die: calc(var(--die-base) * var(--die-k));
  --gap: calc(var(--gap-base) * var(--gap-k));
  --edge: 4px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--void);
  color: var(--ink);
  font-family: var(--han);
  font-size: 15px;
  line-height: 1.8;
  letter-spacing: .02em;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; touch-action: manipulation; }

:where(button):focus-visible {
  outline: 3px solid var(--d11);
  outline-offset: 3px;
}

/* --- 背景層 ------------------------------------------------ */
#bg {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: -3;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.crt, .vignette { position: fixed; inset: 0; pointer-events: none; }
.crt {
  z-index: -1;
  background: repeating-linear-gradient(to bottom,
    rgba(0,0,0,.22) 0 2px, rgba(0,0,0,0) 2px 4px);
  opacity: .5;
  mix-blend-mode: multiply;
}
.vignette {
  z-index: -2;
  background: radial-gradient(120% 90% at 50% 40%, transparent 38%, var(--void) 100%);
}

/* --- 畫面骨架 ---------------------------------------------- */
.screen {
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- 頂欄 -------------------------------------------------- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: .55rem clamp(.7rem, 3vw, 1.6rem);
  border-bottom: 3px solid var(--violet);
  background: rgba(10,8,24,.7);
  font-family: var(--pixel);
  font-size: clamp(.4rem, 1.9vw, .52rem);
  color: var(--dim);
}
.bar p { margin: 0; }
.bar b { color: var(--gold); font-weight: normal; }
.bar .dot { color: var(--d9); animation: blink 1.1s steps(1) infinite; }
.bar .zh { font-family: var(--han); font-size: .75rem; }
@keyframes blink { 50% { opacity: 0; } }

/* --- 舞台 -------------------------------------------------- */
.stage {
  min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: var(--gap);
  padding: var(--gap) clamp(.8rem, 4vw, 2rem);
  text-align: center;
  overflow: hidden;
}

/* --- 識別 -------------------------------------------------- */
.ident { display: flex; flex-direction: column; align-items: center; gap: calc(var(--gap) * .55); }

.title {
  font-family: var(--pixel);
  margin: 0;
  display: flex; flex-wrap: wrap;
  align-items: baseline; justify-content: center;
  gap: .3em;
  line-height: 1.1;
}
.title .big {
  font-size: clamp(1.9rem, min(9.5vw, 6.2vh), 4.6rem);
  text-shadow: 3px 0 0 var(--shadow), -3px 0 0 var(--shadow),
               0 3px 0 var(--shadow), 0 -3px 0 var(--shadow),
               7px 7px 0 rgba(0,0,0,.5);
}
.title .d9  { color: var(--d9); }
.title .d11 { color: var(--d11); }
.title .conj { font-size: clamp(.62rem, 2.6vw, 1.15rem); color: var(--dim); }

.sigil {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(.7rem, min(3.6vw, 2.4vh), 1.5rem);
  color: var(--gold);
  letter-spacing: .18em;
  text-shadow: 3px 3px 0 var(--shadow);
}
.sub {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(.42rem, min(2.1vw, 1.5vh), .8rem);
  color: var(--ink);
  line-height: 1.9;
}
.oath {
  margin: 0;
  color: var(--dim);
  font-size: clamp(.72rem, 3vw, .95rem);
  max-width: 30ch;
}
.oath .cursor {
  display: inline-block; width: .55em; height: .95em;
  background: var(--gold); vertical-align: -.1em;
  animation: blink 1s steps(1) infinite;
}

/* --- 擲骰 -------------------------------------------------- */
.rollbox { display: flex; flex-direction: column; align-items: center; gap: var(--gap); }

#die {
  width: var(--die); height: var(--die);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(5px 7px 0 rgba(0,0,0,.55));
}

.btn {
  font-family: var(--pixel);
  font-size: clamp(.52rem, min(2.6vw, 1.9vh), .82rem);
  line-height: 1.5;
  color: var(--void);
  background: var(--gold);
  border: var(--edge) solid var(--ink);
  box-shadow: 6px 6px 0 var(--shadow);
  padding: .85em 1.1em;
  cursor: pointer;
  transition: transform .06s steps(1), box-shadow .06s steps(1);
}
.btn:hover { background: var(--ink); }
.btn:active { transform: translate(6px, 6px); box-shadow: 0 0 0 var(--shadow); }
.btn[disabled] { opacity: .5; cursor: wait; }

.verdict {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(.6rem, min(3.1vw, 2.2vh), 1.1rem);
  color: var(--dim);
  min-height: 1.5em;
  text-shadow: 3px 3px 0 var(--shadow);
}
.verdict.low  { color: var(--d9); }
.verdict.pass { color: var(--gold); }
.verdict.high { color: var(--d11); }

.flavor {
  margin: 0;
  min-height: 3.2em;
  max-width: 27ch;
  font-size: clamp(.75rem, 3vw, .95rem);
  color: var(--ink);
}

/* --- 判定表（同時是計數器） -------------------------------- */
.legend {
  margin: 0;
  display: grid;
  gap: 2px;
  border: 3px solid var(--deep);
  background: rgba(4,3,12,.55);
  padding: .5rem .6rem;
  font-family: var(--pixel);
  font-size: clamp(.4rem, 1.95vw, .5rem);
  line-height: 1.7;
}
.legend__row {
  display: grid;
  grid-template-columns: 3.4em minmax(0, 1fr) auto 2.6em;
  gap: .7em;
  align-items: center;
  color: var(--dim);
  text-align: left;
}
.legend__row dt, .legend__row dd { margin: 0; }
.legend__row .l-zh { font-family: var(--han); font-size: .8rem; }
.legend__row .l-n { text-align: right; color: var(--ink); }
.legend__row[data-row="low"] dt  { color: var(--d9); }
.legend__row[data-row="pass"] dt { color: var(--gold); }
.legend__row[data-row="high"] { opacity: .4; }
.legend__row[data-row="high"].hit { opacity: 1; }
.legend__row[data-row="high"].hit dt,
.legend__row[data-row="high"].hit .l-n { color: var(--d11); }

/* --- 底欄 -------------------------------------------------- */
.base {
  border-top: 3px solid var(--deep);
  background: rgba(10,8,24,.7);
  padding: .7rem clamp(.7rem, 3vw, 1.6rem) .9rem;
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  gap: .5rem;
}
.base__en {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(.38rem, 1.85vw, .5rem);
  color: var(--gold);
  line-height: 1.9;
}
.base__zh { margin: 0; font-size: .78rem; color: var(--dim); }
.base__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem .7rem; }
.dom { font-family: var(--pixel); font-size: clamp(.38rem, 1.85vw, .5rem); color: var(--violet); }

.mini {
  font-family: var(--pixel);
  font-size: clamp(.36rem, 1.8vw, .46rem);
  background: transparent; color: var(--dim);
  border: 2px solid var(--dim);
  padding: .6em .7em; cursor: pointer;
}
.mini:hover { color: var(--ink); border-color: var(--ink); }
.mini[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }

/* --- 覆蓋視窗（RPG 選單） ---------------------------------- */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: clamp(.8rem, 4vw, 2rem);
  background: rgba(4,3,12,.86);
}
.sheet[hidden] { display: none; }
.sheet__win {
  width: min(100%, 34rem);
  max-height: 88svh;
  overflow: auto;
  background: var(--void);
  border: var(--edge) solid var(--gold);
  box-shadow: 8px 8px 0 var(--shadow);
  padding: clamp(1rem, 4vw, 1.6rem);
}
.sheet--win11 .sheet__win { border-color: var(--d11); }
.sheet__title {
  margin: 0 0 .3rem;
  font-family: var(--pixel);
  font-size: clamp(.7rem, 3.4vw, 1rem);
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--shadow);
}
.sheet--win11 .sheet__title { color: var(--d11); }
.sheet__sub { margin: 0 0 1.1rem; font-size: .82rem; color: var(--dim); }
.sheet__note { margin: 1.1rem 0 0; font-size: .78rem; color: var(--dim); }
.sheet__close { margin-top: 1.2rem; width: 100%; }
.sheet p { line-height: 1.9; }

.rows { display: grid; gap: 3px; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .6rem;
  align-items: center;
  border: 2px solid var(--deep);
  padding: .5rem .6rem;
  text-align: left;
}
.row__name { font-family: var(--pixel); font-size: clamp(.44rem, 2.1vw, .56rem); color: var(--ink); }
.row__zh { font-size: .78rem; color: var(--dim); margin-top: .25rem; }
.tag {
  font-family: var(--pixel); font-size: .4rem; line-height: 1;
  padding: .5em .55em; border: 2px solid currentColor; white-space: nowrap;
}
.tag--yes { color: var(--d11); }
.tag--maybe { color: var(--gold); }
.tag--no { color: var(--d9); }

/* 奇蹟紀錄 */
.record {
  margin: 1.1rem 0 0;
  border: 3px solid var(--d11);
  padding: .8rem;
  font-family: var(--pixel);
  font-size: clamp(.4rem, 2vw, .5rem);
  line-height: 2.2;
  color: var(--d11);
  display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: .2rem .6rem;
  text-align: left;
}
.record span:nth-child(even) { color: var(--ink); overflow-wrap: anywhere; }

/* --- 提示 -------------------------------------------------- */
.toast {
  position: fixed; left: 50%; top: 3.4rem; z-index: 60;
  transform: translateX(-50%);
  font-family: var(--pixel); font-size: .5rem;
  background: var(--gold); color: var(--void);
  border: 3px solid var(--void);
  box-shadow: 5px 5px 0 var(--shadow);
  padding: .8em 1em;
  max-width: min(90vw, 24rem); text-align: center; line-height: 1.8;
}
.toast[hidden] { display: none; }

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

/* --- 寬螢幕：左識別 / 右擲骰 ------------------------------- */
@media (min-width: 880px) and (min-height: 560px) {
  :root { --die-base: clamp(150px, 30vh, 224px); }
  .stage { flex-direction: row; gap: clamp(2rem, 7vw, 5.5rem); }
  .ident { align-items: flex-start; text-align: left; max-width: 26rem; }
  .title { justify-content: flex-start; }
  .oath { max-width: 24ch; }
}

/* --- 橫向手機 ---------------------------------------------- */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --die-base: clamp(88px, 32vh, 148px); --gap-base: clamp(.3rem, 1.6vh, .7rem); }
  .stage { flex-direction: row; gap: clamp(1rem, 5vw, 3rem); }
  .ident { align-items: flex-start; text-align: left; }
  .title { justify-content: flex-start; }
  .oath, .base__zh { display: none; }
  .flavor { min-height: 2.6em; }
}

/* --- 矮螢幕：收掉次要資訊 ---------------------------------- */
@media (max-height: 700px) and (orientation: portrait) {
  :root { --die-base: clamp(96px, min(24vh, 40vw), 150px); }
  .oath, .base__zh { display: none; }
}
@media (max-height: 600px) and (orientation: portrait) {
  .legend { display: none; }
  .flavor { min-height: 2.6em; }
}

@media (prefers-reduced-motion: reduce) {
  .bar .dot, .oath .cursor { animation: none; }
  .btn { transition: none; }
}
