/* 經典遊戲盒：紅白機風格。遊戲模組請用這裡的色票變數，不要自己寫死顏色，深色模式才會跟著換。 */
@font-face { font-family: "Cubic11"; src: url("../fonts/Cubic_11.woff2") format("woff2"); font-display: swap; }
:root {
  --paper: #efe6d2;      /* 機身米白（頁面底） */
  --card: #fffaf0;       /* 面板 */
  --ink: #1e1b1a;        /* 主文字、黑框 */
  --muted: #7a6f5c;      /* 次要文字 */
  --line: #1e1b1a;       /* 邊框一律黑框 */
  --accent: #b8202a;     /* 機身深紅 */
  --accent-2: #7e121a;   /* 深紅陰影 */
  --accent-ink: #efe6d2;
  --gold: #c9a24a;       /* 控制器金色面板 */
  --gold-2: #8e6c22;
  --ok: #3d9a5c;
  --screen: #1e1b1a;     /* 螢幕黑框 */
  --wood: #e3c48f;       /* 棋盤木色 */
  --wood-dark: #a97a3a;
  --board-line: #4a3216;
  --felt: #2d7a4d;       /* 牌桌綠 */
  --red-piece: #b8202a;
  --black-piece: #1e1b1a;
  --piece-face: #f6e4c0;
  --hl: rgba(255, 210, 60, .6);     /* 選取／上一步高亮 */
  --hint: rgba(255, 215, 94, .9);   /* 可走位置提示點 */
  --radius: 4px;
  --shadow: 0 4px 0 rgba(0,0,0,.25);
  --font: "Cubic11", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #2a2624; --card: #36312e; --ink: #f1e8d6; --muted: #b3a690; --line: #0d0b0a;
    --accent: #d23a42; --accent-2: #7e121a; --wood: #c09a5e; --wood-dark: #7d5a2a; --board-line: #3a2814;
    --felt: #24603e; --piece-face: #ecdcbf; --screen: #0d0b0a;
    --shadow: 0 4px 0 rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.5; overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none; -webkit-user-select: none;
}
button, input { font-family: var(--font); }
button { color: inherit; }

/* 頂欄：機身銘牌＋紅條 */
.bar { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px 12px 12px; position: sticky; top: 0; background: var(--paper); z-index: 5; border-bottom: 6px solid var(--accent); box-shadow: 0 4px 0 var(--paper), 0 8px 0 var(--accent); margin-bottom: 8px; }
.bar-title { flex: 1; font-size: 20px; font-weight: 400; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title.logo { flex: none; background: var(--accent); color: var(--accent-ink); font-size: 24px; padding: 4px 12px 2px; box-shadow: 0 4px 0 var(--accent-2); letter-spacing: .08em; }
.bar-en { flex: 1; font-size: 11px; color: var(--accent); line-height: 1.2; letter-spacing: .05em; }
.bar-back, .bar-rules { border: 3px solid var(--ink); background: var(--card); box-shadow: 0 4px 0 var(--ink); padding: 4px 10px 2px; font-size: 15px; cursor: pointer; }
.bar-back:active, .bar-rules:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#view { max-width: 980px; margin: 0 auto; padding: 12px 14px 20px; }

/* 按鈕：黑框方塊，按下會陷下去 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 2px 14px 0; border: 3px solid var(--ink); background: var(--card); box-shadow: 0 4px 0 var(--ink); cursor: pointer; font-size: 15px; color: var(--ink); text-decoration: none; border-radius: 0; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn[disabled] { opacity: .4; cursor: default; transform: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.center { display: flex; justify-content: center; }
.muted { color: var(--muted); }

/* 大廳：卡帶架 */
.lobby h2 { font-size: 16px; font-weight: 400; color: var(--accent); margin: 6px 2px 10px; display: flex; align-items: center; gap: 8px; }
.lobby h2::before { content: ""; width: 10px; height: 10px; background: var(--accent); }
.lobby h2 small { margin-left: auto; color: var(--muted); font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 14px 10px; margin-bottom: 22px; }
.tile { position: relative; display: block; border: 0; padding: 12px 7px 14px; border-radius: 6px 6px 3px 3px; cursor: pointer; text-align: left; box-shadow: inset 0 -6px 0 rgba(0,0,0,.2), 0 4px 0 rgba(0,0,0,.2); transition: transform .08s; }
.tile::before { content: ""; position: absolute; left: 8px; right: 8px; top: 4px; height: 4px; background: repeating-linear-gradient(90deg, rgba(0,0,0,.2) 0 6px, transparent 6px 10px); }
.tile:active { transform: translateY(4px); }
.tile-label { display: flex; flex-direction: column; background: #fff; border: 2px solid rgba(0,0,0,.3); height: 96px; overflow: hidden; }
.tile-art { flex: 1; display: grid; place-items: center; }
.tile-art svg { width: 48px; height: 48px; }
.tile-name { background: #1e1b1a; color: #fff; font-size: 13px; text-align: center; padding: 3px 0 1px; white-space: nowrap; }
.tile-no { position: absolute; right: 7px; bottom: 1px; font-size: 9px; color: rgba(0,0,0,.45); }
.lobby-note { font-size: 13px; text-align: center; color: var(--muted); margin: 0 0 16px; }

/* 裝飾控制器 */
.pad { background: var(--accent); padding: 10px 14px 14px; box-shadow: inset 0 4px 0 var(--accent-2); border-radius: 10px; max-width: 420px; margin: 0 auto; }
.pad-gold { background: linear-gradient(var(--gold), #b38b35); border-radius: 6px; height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; box-shadow: inset 0 0 0 3px var(--gold-2); }
.pad-dpad { position: relative; width: 60px; height: 60px; }
.pad-dpad i { position: absolute; background: #1e1b1a; }
.pad-dpad i:nth-child(1) { left: 20px; top: 0; width: 20px; height: 60px; }
.pad-dpad i:nth-child(2) { top: 20px; left: 0; width: 60px; height: 20px; }
.pad-mid { display: flex; gap: 8px; }
.pad-mid span { width: 30px; height: 9px; background: #1e1b1a; border-radius: 5px; }
.pad-ab { display: flex; gap: 10px; }
.pad-ab span { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); box-shadow: 0 3px 0 var(--accent-2), 0 0 0 3px #1e1b1a; color: #efe6d2; font-size: 11px; display: grid; place-items: center; }

/* 兩人對戰外框 */
.panel { background: var(--card); border: 3px solid var(--ink); padding: 16px; box-shadow: var(--shadow); }
.modes { display: grid; gap: 14px; max-width: 420px; margin: 8px auto; }
.modes .btn { min-height: 52px; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .code-input { font-size: 18px; padding: 8px 12px 6px; border: 3px solid var(--ink); background: #fff; color: #1e1b1a; border-radius: 0; }
.code-input { letter-spacing: .4em; text-align: center; }
.players { display: flex; gap: 8px; margin-bottom: 10px; }
.player { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 10px 4px; border: 3px solid var(--ink); background: var(--card); font-size: 14px; min-width: 0; }
.player.turn { background: #fff4c2; color: #1e1b1a; box-shadow: 0 0 0 3px var(--accent); }
.player .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #1e1b1a; }
.player .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .net { width: 8px; height: 8px; flex: none; margin-left: auto; background: var(--muted); }
.player .net.on { background: var(--ok); }
.status { text-align: center; min-height: 26px; margin: 6px 0; color: var(--accent); font-size: 18px; }
.room-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; font-size: 14px; }
.room-code { font-size: 22px; letter-spacing: .15em; background: #1e1b1a; color: #ffd75e; padding: 2px 8px 0; }
.board-root { display: flex; justify-content: center; touch-action: manipulation; background: var(--screen); padding: 10px; border-radius: 10px; box-shadow: inset 0 0 0 4px #3a3532; margin: 0 auto; max-width: max-content; }
.actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.result { text-align: center; padding: 12px; margin: 12px auto 0; max-width: 420px; background: #1e1b1a; color: #ffd75e; border: 3px solid var(--accent); font-size: 20px; }

/* 對話框、提示 */
dialog { border: 3px solid var(--ink); border-radius: 0; padding: 20px; max-width: min(520px, calc(100vw - 32px)); background: var(--card); color: var(--ink); box-shadow: 0 6px 0 var(--ink); font-family: var(--font); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin: 0 0 8px; font-weight: 400; color: var(--accent); font-size: 20px; }
dialog p, dialog li { font-size: 15px; line-height: 1.7; }
dialog b, dialog strong { font-weight: 400; color: var(--accent); }
dialog form { text-align: right; margin-top: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1e1b1a; color: #ffd75e; padding: 8px 18px 6px; border: 3px solid var(--accent); font-size: 15px; z-index: 50; max-width: calc(100vw - 32px); }

/* 大廳：電視裡的合卡選單 */
.tv { background: #3a3532; padding: 14px; border-radius: 18px; box-shadow: inset 0 0 0 4px #1e1b1a, 0 6px 0 rgba(0,0,0,.25); max-width: 560px; margin: 0 auto 14px; }
.tv-screen { position: relative; background: #000; border-radius: 14px; padding: 18px 12px 14px; color: #fff; overflow: hidden; }
.tv-screen::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(0deg, rgba(255,255,255,.04) 0 1px, transparent 1px 3px); border-radius: 14px; box-shadow: inset 0 0 40px rgba(0,0,0,.8); }
.menu-title { text-align: center; font-size: 40px; line-height: 1; color: #ffd75e; text-shadow: 3px 3px 0 #b8202a; letter-spacing: .08em; }
.menu-sub { text-align: center; font-size: 13px; color: #9fd8ff; margin: 8px 0 12px; }
.menu { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
@media (min-width: 560px) { .menu { grid-template-columns: 1fr 1fr; grid-auto-flow: column; grid-template-rows: repeat(6, auto); column-gap: 12px; } }
.menu li { display: flex; align-items: center; gap: 6px; padding: 5px 4px; cursor: pointer; font-size: 17px; }
.menu-cur { width: 16px; color: #b8202a; visibility: hidden; }
.menu li.on .menu-cur { visibility: visible; animation: blink 1s steps(1) infinite; }
.menu li.on .menu-name { color: #ffd75e; }
.menu-no { color: #9a9a9a; font-size: 14px; }
.menu-art { width: 26px; height: 26px; flex: none; background: #efe6d2; border-radius: 3px; }
.menu-art svg { width: 26px; height: 26px; }
.menu-name { flex: 1; }
.menu-tag { font-size: 11px; padding: 1px 5px 0; border: 2px solid #9fd8ff; color: #9fd8ff; }
.menu-tag.duel { border-color: #ff8a8a; color: #ff8a8a; }
.menu-tag.multi { border-color: #ffd75e; color: #ffd75e; }
.menu-foot { text-align: center; margin-top: 14px; font-size: 13px; color: #fff; animation: blink 1.4s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 控制器按鈕可以按 */
.pad-dpad button { position: absolute; width: 20px; height: 20px; border: 0; background: transparent; padding: 0; cursor: pointer; }
.pad-dpad button[data-k="up"] { left: 20px; top: 0; } .pad-dpad button[data-k="down"] { left: 20px; bottom: 0; }
.pad-dpad button[data-k="left"] { left: 0; top: 20px; } .pad-dpad button[data-k="right"] { right: 0; top: 20px; }
.pad-dpad button:active { background: rgba(255,255,255,.25); }
.pad-mid button { width: 34px; height: 10px; background: #1e1b1a; border-radius: 5px; border: 0; padding: 0; cursor: pointer; position: relative; }
.pad-mid button::after { content: ""; position: absolute; inset: -12px -4px; }
.pad-ab button { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); box-shadow: 0 3px 0 var(--accent-2), 0 0 0 3px #1e1b1a; color: #efe6d2; font-size: 12px; border: 0; cursor: pointer; padding: 0; }
.pad-mid button:active, .pad-ab button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-2), 0 0 0 3px #1e1b1a; }
.pad-mid button:active { box-shadow: none; }

/* 多人、藏牌遊戲（UNO、拉密）外框：2–4 個座位、電腦標記、分段選擇鈕、換人蓋牌 */
.players.multi { flex-wrap: wrap; }
.players.multi .player { flex: 1 1 calc(50% - 4px); }
@media (min-width: 640px) { .players.multi .player { flex-basis: 0; } }
.player .seat-tag { flex: none; font-size: 11px; padding: 1px 5px 0; border: 2px solid var(--ink); background: var(--paper); color: var(--ink); }
.player .seat-tag.me { background: var(--accent); color: var(--accent-ink); }
.player.turn .seat-tag { border-color: #1e1b1a; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 40px; min-width: 52px; padding: 2px 8px 0; border: 3px solid var(--ink); background: var(--card); color: var(--ink); box-shadow: 0 3px 0 var(--ink); font-size: 15px; cursor: pointer; border-radius: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.seat-setup { display: grid; gap: 10px; max-width: 420px; margin: 0 auto 12px; padding: 10px 12px; border: 3px dashed var(--ink); background: var(--card); }
.seat-setup[hidden] { display: none; }
.hand-cover { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--screen); cursor: pointer; }
.hand-cover[hidden] { display: none; }
.hand-cover-box { text-align: center; color: #ffd75e; border: 3px solid var(--accent); background: #1e1b1a; padding: 24px 20px; max-width: 360px; font-size: 15px; line-height: 1.8; }
.hand-cover-big { font-size: 26px; color: #fff; margin-bottom: 6px; }

/* iPhone Safari：格線項目預設不縮，輸入框與長按鈕會把面板撐破，強制可縮 */
.modes { grid-template-columns: minmax(0, 1fr); }
.modes > *, .seat-setup > * { min-width: 0; }
.field input, .modes input { width: 100%; min-width: 0; }
.modes .btn { white-space: normal; text-align: center; }
.seg button { min-width: 0; }
.modes .code-input, .modes input[data-r="code"] { border-radius: 0 !important; border: 3px solid var(--ink) !important; background: #fff !important; color: #1e1b1a !important; }
