:root {
  --bg: #0f1117;
  --panel: #191c26;
  --panel2: #222633;
  --text: #e8eaf0;
  --dim: #9aa0b0;
  --accent: #e53aa3;
  --blue: #1e93ff;
  --green: #4fcc30;
  --red: #f93c31;
  --yellow: #ffdc00;
}
* { box-sizing: border-box; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 64px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 28px;
}
.topbar .brand { font-weight: 700; font-size: 1.05em; color: var(--text); }
.topbar .brand span { color: var(--accent); }
.topbar .who { margin-left: auto; color: var(--dim); font-size: .9em; }

h1 { font-size: 1.9em; margin-bottom: 8px; }
h2 { font-size: 1.2em; margin: 24px 0 8px; color: var(--yellow); }
p { line-height: 1.75; }
.lead { color: var(--dim); margin-bottom: 24px; }

.card {
  background: var(--panel);
  border: 1px solid #2b3040;
  border-radius: 14px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
}
.card input[type=text] {
  width: 100%;
  padding: 12px 14px;
  font-size: 1.05em;
  border-radius: 10px;
  border: 1px solid #3a4155;
  background: var(--panel2);
  color: var(--text);
  margin: 10px 0 18px;
}
.notice {
  background: var(--panel2);
  border-left: 3px solid var(--yellow);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 22px;
  font-size: .92em;
  line-height: 1.8;
}
.notice ol { margin: 8px 0 0 0; padding-left: 20px; }
.notice li { margin-bottom: 6px; }
.notice li:last-child { margin-bottom: 0; }

.btn {
  display: inline-block;
  padding: 11px 22px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid #3a4155; }

/* 選關 grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 960px;
}
.gcard {
  background: var(--panel);
  border: 1px solid #2b3040;
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: transform .08s, border-color .08s;
}
.gcard:hover { transform: translateY(-2px); border-color: var(--accent); }
.gcard .gid { font-size: 1.3em; font-weight: 700; letter-spacing: .04em; }
.gcard .ginfo { color: var(--dim); font-size: .85em; margin-top: 6px; line-height: 1.6; }
.gcard .done { color: var(--green); }

/* 遊戲畫面 */
.hud {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 14px 0;
}
.chip {
  background: var(--panel);
  border: 1px solid #2b3040;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .92em;
  color: var(--dim);
}
.chip b { color: var(--text); }
.chip.win { border-color: var(--green); color: var(--green); }
.chip.over { border-color: var(--red); color: var(--red); }

#stagewrap { display: flex; flex-direction: column; align-items: center; }
.stage { position: relative; }
canvas#board {
  width: min(88vw, 640px);
  height: min(88vw, 640px);
  image-rendering: pixelated;
  border-radius: 8px;
  border: 1px solid #2b3040;
  background: #000;
  display: block;
}
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(10, 12, 18, .82);
  border-radius: 8px;
  text-align: center;
}
.overlay.show { display: flex; }
.overlay .big { font-size: 2.2em; font-weight: 800; }
.overlay .big.win { color: var(--green); }
.overlay .big.over { color: var(--red); }
.overlay .sub { color: var(--dim); }

/* 觸控方向鍵：容器不吃事件，讓空白處的點擊照樣穿到棋盤（點擊型遊戲用）；只有按鈕吃 */
.touchpad { position: absolute; inset: 0; pointer-events: none; }
.touchpad[hidden] { display: none; }
.touchpad .tbtn {
  pointer-events: auto;
  width: 52px; height: 52px;
  border: none; border-radius: 50%;
  background: rgba(25, 28, 38, .5);
  color: #fff; font-size: 1.15em;
  display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touchpad .tbtn:active { background: rgba(233, 69, 96, .8); }
.touchpad .tbtn[hidden] { display: none; }
.dpad {
  position: absolute; left: 12px; bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
}
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }
.dpad[hidden] { display: none; }
.tbtn.act { position: absolute; right: 14px; bottom: 26px; width: 60px; height: 60px; font-size: 1.4em; }
.tbtn.padtoggle { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; font-size: 1em; }
.touchpad.collapsed .tbtn:not(.padtoggle) { display: none; }
.touchpad.collapsed .padtoggle { opacity: .45; }

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #06210a;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.toast.show { opacity: 1; }

.controls { color: var(--dim); font-size: .9em; margin-top: 14px; text-align: center; line-height: 1.9; }
.controls .na { opacity: .4; text-decoration: line-through; text-decoration-thickness: 2px; }
kbd {
  background: var(--panel2);
  border: 1px solid #3a4155;
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-family: inherit;
  font-size: .92em;
}

/* 載入進度 */
#loader { width: min(88vw, 520px); text-align: center; padding: 60px 0; }
.pbar {
  height: 10px;
  background: var(--panel2);
  border-radius: 999px;
  overflow: hidden;
  margin: 16px 0 10px;
}
.pbar > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--accent));
  transition: width .6s ease;
}
#ptext { color: var(--dim); font-size: .9em; }

table { border-collapse: collapse; margin: 8px 0; }
td, th { border: 1px solid #2b3040; padding: 8px 14px; text-align: left; }
th { color: var(--dim); font-weight: 600; }

/* 全破成績表（overlay 內） */
.overlay .sub table { margin: 10px auto; color: var(--text); background: rgba(15, 17, 23, .6); }
.overlay .sub td, .overlay .sub th { padding: 5px 12px; font-size: .95em; }
.overlay .sub .better { color: var(--green); }
.overlay .sub .worse { color: var(--red); }
