/* 學科遠征 GAME-ADV — 復古街機風格介面 */
:root {
  --bg: #0b0f1a;
  --bg-2: #121a2b;
  --panel: #16203385;
  --line: #2a3a58;
  --ink: #e8eefc;
  --muted: #8fa3c8;
  --accent: #f2b134;
  --accent-2: #4fc3f7;
  --ok: #66bb6a;
  --no: #ef5350;
  --radius: 14px;
  --shadow: 0 10px 30px #0009;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* 元件上的 display:flex/grid 會蓋掉瀏覽器預設的 [hidden]{display:none}，這裡補回來，
   否則遮罩層即使 hidden 仍會覆蓋畫面並攔截點擊。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, #1d2b4a 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #2a1c3e 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.hide { display: none !important; }

/* ---------------------------------------------------------- 頁首 */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px clamp(12px, 3vw, 30px);
  border-bottom: 1px solid var(--line);
  background: #0b0f1acc;
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 18px; letter-spacing: .06em; }
.brand-text i { font-size: 11px; color: var(--muted); font-style: normal; letter-spacing: .3em; }

.tabs { display: flex; gap: 6px; margin-left: auto; }
.tabs a {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
  border: 1px solid transparent;
}
.tabs a:hover { color: var(--ink); background: #ffffff0e; }
.tabs a.on { color: var(--bg); background: var(--accent); font-weight: 700; }

.player-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}
.player-chip .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #ff7043);
  color: #201400; font-weight: 800;
}
.player-chip .who { display: flex; flex-direction: column; line-height: 1.15; }
.player-chip .who b { font-size: 14px; }
.player-chip .who small { color: var(--muted); font-size: 11px; }
.player-chip .xp { width: 92px; height: 6px; background: #0008; border-radius: 999px; overflow: hidden; }
.player-chip .xp i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }

/* ---------------------------------------------------------- 版面 */
.app {
  flex: 1;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px);
}
.loading { text-align: center; padding: 60px; color: var(--muted); }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px clamp(12px, 3vw, 30px);
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}

.btn {
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--accent), #d99a1f);
  color: #241700;
  font-weight: 800;
  padding: 11px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  transition: transform .08s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #ffffff10; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 7px 13px; font-size: 13px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; background: #ffffff18; color: var(--ink); border-color: var(--line); }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

/* ---------------------------------------------------------- 登入 */
.auth {
  max-width: 460px; margin: 6vh auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.auth h1 { margin: 0 0 6px; font-size: 24px; }
.auth p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.auth label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.auth input {
  width: 100%; margin-top: 6px; padding: 11px 13px;
  background: #0a1120; border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink); font-size: 15px; font-family: inherit;
}
.auth input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.auth .switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth .switch button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }
.auth .err { color: var(--no); font-size: 13px; min-height: 20px; }

/* ---------------------------------------------------------- 大廳 */
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 6px; font-size: clamp(22px, 3.4vw, 30px); letter-spacing: .02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }

.summary-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 18px 0 26px;
}
.summary-strip div {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px;
}
.summary-strip i { display: block; font-style: normal; font-size: 12px; color: var(--muted); }
.summary-strip b { font-size: 20px; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.game-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease, border-color .15s ease;
}
.game-card::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--gc, var(--accent));
}
.game-card:hover { transform: translateY(-3px); border-color: var(--gc, var(--accent)); }
.game-card .head { display: flex; align-items: flex-start; gap: 12px; }
.game-card .icon {
  font-size: 30px; width: 52px; height: 52px; border-radius: 12px;
  display: grid; place-items: center; background: #0a1120; border: 1px solid var(--line);
}
.game-card h3 { margin: 0; font-size: 18px; }
.game-card .subject { color: var(--gc, var(--accent)); font-size: 12px; font-weight: 700; }
.game-card .arch { color: var(--muted); font-size: 11px; }
.game-card .tagline { margin: 12px 0 14px; font-size: 13px; color: #c4d2ee; line-height: 1.65; min-height: 42px; }
.game-card .stars-row { display: flex; gap: 4px; margin-bottom: 10px; }
.game-card .ms-dot {
  flex: 1; height: 7px; border-radius: 999px; background: #ffffff14;
}
.game-card .ms-dot.s1 { background: #8d6e63; }
.game-card .ms-dot.s2 { background: #b0bec5; }
.game-card .ms-dot.s3 { background: var(--accent); }
.game-card .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------- 遊戲詳情 */
.detail-head {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.detail-head .icon { font-size: 46px; }
.detail-head h1 { margin: 0; font-size: 26px; }
.detail-head .sub { color: var(--muted); font-size: 13px; }
.detail-head .lvl { margin-left: auto; text-align: right; }
.detail-head .lvl b { font-size: 26px; color: var(--accent); }

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.panel h2 { margin: 0 0 14px; font-size: 16px; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }

.ms-list { display: flex; flex-direction: column; gap: 10px; }
.ms-item {
  display: flex; gap: 14px; align-items: center;
  padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #0a112080;
}
.ms-item.locked { opacity: .5; }
.ms-item.done { border-color: #3c6b46; }
.ms-item .no {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: #0d1526; border: 1px solid var(--line); font-weight: 800; color: var(--accent);
}
.ms-item .body { flex: 1; min-width: 0; }
.ms-item .body b { display: block; font-size: 15px; }
.ms-item .body span { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.ms-item .body .goal { display: block; font-size: 11.5px; color: #7f93b8; margin-top: 4px; }
.ms-item .stars { color: var(--accent); letter-spacing: 2px; font-size: 14px; }
.ms-item .go { white-space: nowrap; }

.item-list { display: flex; flex-direction: column; gap: 9px; }
.item-row {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 9px 11px; border-radius: 10px; background: #0a112080; border: 1px solid var(--line);
}
.item-row.have { border-color: var(--accent); }
.item-row.miss { opacity: .45; }
.item-row .ic { font-size: 22px; }
.item-row b { display: block; font-size: 13.5px; }
.item-row span { font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.topic-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: #ffffff10; border: 1px solid var(--line); color: #c9d7f2;
}

/* ---------------------------------------------------------- 遊戲畫面 */
.play { display: flex; flex-direction: column; gap: 10px; }
.play-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px;
}
.play-title { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.play-title .muted { font-size: 12px; }
.play-stats { display: flex; gap: 14px; margin-left: auto; flex-wrap: wrap; }
.play-stats .stat { display: flex; flex-direction: column; line-height: 1.2; min-width: 54px; }
.play-stats .stat i { font-style: normal; font-size: 10.5px; color: var(--muted); }
.play-stats .stat b { font-size: 16px; font-variant-numeric: tabular-nums; }

.stage-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #05070d; border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.stage-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.layer {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: #04070ecc; backdrop-filter: blur(3px); padding: 3%;
  overflow-y: auto;
}

/* 非阻斷式解說條：知識機關答完後在畫面下方浮出，遊戲繼續跑 */
.toast-wrap {
  position: absolute; left: 0; right: 0; bottom: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; padding: 0 12px;
}
.toast {
  width: min(680px, 100%);
  background: #0b0f1aee; border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: 10px; padding: 8px 14px;
  display: flex; flex-direction: column; gap: 3px;
  animation: toastIn .22s ease;
  box-shadow: 0 6px 18px #0008;
}
.toast.no { border-left-color: var(--no); }
.toast b { font-size: 13.5px; }
.toast span { font-size: 12px; color: var(--muted); line-height: 1.6; }
.toast.out { animation: toastOut .4s ease forwards; }
@keyframes toastIn { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(10px); opacity: 0; } }

.play-stats .stat.know { min-width: 96px; }
.play-stats .kbar {
  display: block; width: 92px; height: 9px; margin-top: 4px;
  background: #ffffff14; border-radius: 999px; overflow: hidden;
}
.play-stats .kbar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #4fc3f7, #8ef1ff);
  transition: width .25s ease;
}

.banner { text-align: center; animation: pop .28s ease; }
.banner h2 { margin: 0 0 8px; font-size: clamp(24px, 4vw, 40px); letter-spacing: .08em; }
.banner p { margin: 0; color: var(--muted); font-size: 14px; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.quiz {
  width: min(760px, 100%);
  background: #0d1526f2; border: 1px solid var(--line);
  border-radius: 14px; padding: clamp(14px, 2.4vw, 22px);
  box-shadow: var(--shadow); animation: pop .2s ease;
}
.quiz-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.pill {
  font-size: 11.5px; padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c, #f2b134) 22%, transparent);
  border: 1px solid var(--c, #f2b134); color: #fff;
}
.pill.tier { background: #ffffff10; border-color: var(--line); color: var(--muted); letter-spacing: 1px; }
.timer { flex: 1; min-width: 90px; height: 6px; background: #ffffff14; border-radius: 999px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; transform-origin: left; }

.quiz-prompt { margin: 0 0 10px; font-size: clamp(15px, 2.1vw, 19px); line-height: 1.75; }
.quiz-code {
  margin: 0 0 12px; padding: 11px 13px; background: #060a13; border: 1px solid var(--line);
  border-radius: 9px; font-size: 13px; line-height: 1.7; overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace; color: #b8ffd9;
}
.quiz-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 9px; }
.choice {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border-radius: 10px; cursor: pointer;
  background: #101a2e; border: 1px solid var(--line); color: var(--ink);
  font-size: 14.5px; font-family: inherit; line-height: 1.5;
  transition: background .12s ease, border-color .12s ease;
}
.choice b {
  width: 24px; height: 24px; flex: none; border-radius: 6px; display: grid; place-items: center;
  background: #ffffff14; font-size: 12px;
}
.choice:hover:not(:disabled) { background: #17253f; border-color: var(--accent-2); }
.choice.right { background: #1d4429; border-color: var(--ok); }
.choice.wrong { background: #4a1f22; border-color: var(--no); }
.choice.faded { opacity: .25; }
.choice:disabled { cursor: default; }

.quiz-feedback {
  margin-top: 13px; padding: 11px 13px; border-radius: 10px;
  background: #ffffff0b; border-left: 3px solid var(--muted);
  display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; line-height: 1.75;
}
.quiz-feedback.ok { border-left-color: var(--ok); }
.quiz-feedback.no { border-left-color: var(--no); }
.quiz-feedback b { font-size: 14.5px; }
.quiz-feedback em { color: var(--muted); font-size: 11.5px; font-style: normal; }

.result {
  width: min(720px, 100%); text-align: center;
  background: #0d1526f2; border: 1px solid var(--line);
  border-radius: 14px; padding: clamp(16px, 3vw, 26px); box-shadow: var(--shadow);
}
.result h2 { margin: 0 0 6px; font-size: clamp(22px, 3.6vw, 32px); }
.result h2.win { color: var(--accent); }
.result h2.lose { color: var(--muted); }
.result .result-msg { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.result .stars { font-size: 34px; color: var(--accent); letter-spacing: 8px; margin: 6px 0 14px; }
.result-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; text-align: left;
}
.result-grid div { background: #0a112080; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.result-grid i { display: block; font-style: normal; font-size: 11px; color: var(--muted); }
.result-grid b { font-size: 19px; }
.result-grid s { display: block; text-decoration: none; font-size: 11px; color: #7f93b8; }
.rewards { margin-top: 16px; text-align: left; }
.rewards h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); letter-spacing: .08em; }
.reward {
  display: block; padding: 8px 11px; margin-bottom: 6px;
  background: #ffffff0d; border: 1px solid var(--accent); border-radius: 9px; font-size: 13.5px;
}
.reward b { margin-right: 6px; }
.reward em { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); }

.controls-hint { text-align: center; font-size: 12px; color: var(--muted); }

.touchpad { display: none; justify-content: space-between; padding: 4px 6px 10px; }
.touchpad button {
  border: 1px solid var(--line); background: #16203390; color: var(--ink);
  border-radius: 12px; font-size: 16px; font-family: inherit;
  width: 58px; height: 52px; cursor: pointer; user-select: none;
}
.dpad { display: grid; grid-template-columns: repeat(3, auto); gap: 5px; align-items: center; }
.dpad [data-key="up"] { grid-column: 2; }
.dpad [data-key="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-key="right"] { grid-column: 3; grid-row: 2; }
.dpad [data-key="down"] { grid-column: 2; grid-row: 3; }
.abpad { display: flex; gap: 10px; align-items: center; }
.abpad button { border-radius: 50%; width: 62px; height: 62px; font-weight: 800; }
@media (hover: none) and (pointer: coarse) { .touchpad { display: flex; } }

/* ---------------------------------------------------------- 進度頁 */
.progress-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.bar { height: 9px; background: #ffffff12; border-radius: 999px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }

.topic-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid #ffffff0d; }
.topic-row:last-child { border-bottom: 0; }
.topic-row .name { width: 120px; flex: none; font-size: 13.5px; }
.topic-row .meter { flex: 1; }
.topic-row .num { width: 118px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--no); }

.spark { display: block; width: 100%; height: 60px; }

table.runs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.runs th, table.runs td { padding: 8px 6px; border-bottom: 1px solid #ffffff0d; text-align: left; }
table.runs th { color: var(--muted); font-weight: 600; font-size: 11.5px; }
table.runs td.num { text-align: right; font-variant-numeric: tabular-nums; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 11px; }
.ach {
  display: flex; gap: 11px; align-items: flex-start; padding: 12px;
  border-radius: 12px; background: #0a112080; border: 1px solid var(--line);
}
.ach.on { border-color: var(--accent); background: #f2b13412; }
.ach.off { opacity: .42; }
.ach .ic { font-size: 24px; }
.ach b { display: block; font-size: 13.5px; }
.ach span { font-size: 11.5px; color: var(--muted); line-height: 1.55; }

.back-link { display: inline-block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.back-link:hover { color: var(--ink); }
