:root {
  --bg: #11141a;
  --bg-2: #171b23;
  --panel: #1d222c;
  --panel-2: #252b37;
  --line: #2f3747;
  --text: #e8ecf4;
  --muted: #94a0b4;
  --accent: #f2a65a;
  --accent-2: #5ab0f2;
  --good: #58c98a;
  --bad: #e5664f;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  background: radial-gradient(1200px 700px at 50% -10%, #1e2533 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s, opacity .15s;
}
button:hover:not(:disabled) { background: #303848; border-color: #44506633; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, var(--accent), #d98b3c);
  border-color: #00000000;
  color: #231402;
  font-weight: 700;
}
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffb96b, #e2954a); }

button.ghost { background: transparent; }
button.ghost.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }

kbd {
  font: 600 11px/1 ui-monospace, monospace;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 4px;
  color: var(--muted);
}

/* ---------- 開局畫面 ---------- */

.screen { min-height: 100%; }

#setup {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

h1 {
  margin: 0;
  font-size: 40px;
  letter-spacing: -1px;
}
h1 span { color: var(--accent); }

.tagline {
  margin: 6px 0 26px;
  color: var(--muted);
}

.field { margin-bottom: 18px; }
.field > label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.choices { display: flex; gap: 8px; }
.choices button { flex: 1; padding: 10px 6px; }
.choices button.on {
  background: #33405a;
  border-color: var(--accent-2);
  color: #fff;
}

#btn-start { width: 100%; padding: 14px; font-size: 16px; margin-top: 6px; }

.rules { margin-top: 20px; font-size: 13px; color: var(--muted); }
.rules summary { cursor: pointer; color: var(--accent-2); }
.rules ul { margin: 12px 0 0; padding-left: 18px; line-height: 1.75; }
.rules b { color: var(--text); font-weight: 600; }

/* ---------- 對局畫面 ---------- */

#game { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.brand { font-weight: 800; letter-spacing: -.5px; }
.brand span { color: var(--accent); }
.clock {
  font: 600 15px/1 ui-monospace, monospace;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.topbar button { padding: 7px 12px; font-size: 13px; }

.layout {
  flex: 1;
  display: flex;
  gap: 20px;
  padding: 20px;
  align-items: flex-start;
  justify-content: center;
}

.board-col {
  flex: 1 1 auto;
  max-width: min(76vh, 720px);
  min-width: 280px;
}

.board-frame {
  background: #c8a06a;
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .5);
}
#board {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: pointer;
}

.banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #2a2f3d;
  border: 1px solid var(--line);
  text-align: center;
  font-size: 14px;
}
.banner.warn { border-color: var(--accent); color: var(--accent); }

.side-col {
  width: 290px;
  flex: 0 0 290px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 玩家面板 */

.player-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.player-card.active { border-color: var(--accent-2); }

.pc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.pc-name { font-weight: 600; font-size: 14px; }
.pc-caps { margin-left: auto; color: var(--muted); }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22);
}
.dot.black { background: radial-gradient(circle at 35% 30%, #6a6a6a, #0b0b0b); }
.dot.white { background: radial-gradient(circle at 35% 30%, #fff, #c5c0b4); }

.pc-stones {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 10px 0 8px;
}
.pc-stones .num { font-size: 30px; line-height: 1; font-weight: 700; }
.pc-stones .cap { color: var(--muted); font-size: 15px; }
.pc-stones .unit { color: var(--muted); font-size: 12px; margin-left: 2px; }
.player-card.full .num { color: var(--accent); }

.bar {
  height: 6px;
  background: #0f131a;
  border-radius: 99px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-2), #8fd0ff);
  border-radius: 99px;
}
.player-card.full .bar i { background: #4a5365; }

.pc-stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
  font-size: 12px;
  color: var(--muted);
}

/* 操作區 */

.actions { display: flex; flex-direction: column; gap: 8px; }

button.upgrade {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  text-align: left;
  padding: 11px 14px;
  background: var(--panel);
}
.u-title { font-weight: 600; font-size: 14px; }
.u-sub { grid-column: 1; font-size: 12px; color: var(--muted); }
.u-cost {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
button.upgrade:disabled .u-cost { color: var(--muted); }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.wide { flex: 2; }
#btn-pass.on { border-color: var(--accent); color: var(--accent); }

/* 庫存條。到 1 顆就換色 —— 那是「現在就下得出一手」的分界，
   盯著這個顏色比盯小數點容易。 */
.bar i.ready {
  background: linear-gradient(90deg, var(--accent), #f0a04b);
}

/* 虛手按鈕上的拖延倒數。對手落子之後輪到我，拖太久會自動虛手，
   超時多次時限還會縮短，所以這個數字要看得見但不要搶戲。 */
.pass-clock {
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}
.pass-clock.hot { color: var(--accent); font-weight: 600; }

.log {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--muted);
  max-height: 190px;
  overflow-y: auto;
  line-height: 1.65;
}
.log li.b::before { content: "● "; color: #000; text-shadow: 0 0 2px #888; }
.log li.w::before { content: "● "; color: #fff; }
.log li.sys { color: #6f7b8f; }
/* 手數。最新的在最上面，有編號才讀得出先後 */
.log li .ply {
  display: inline-block;
  min-width: 2.4em;
  margin-right: 2px;
  color: #5a6475;
  font-variant-numeric: tabular-nums;
}

/* ---------- 終局 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.result-card { max-width: 400px; }
.result-card h2 { margin: 0 0 4px; font-size: 26px; }
.result-card .row { margin-top: 20px; }

.score-rows {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.score-rows .sr {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--panel-2);
  border-radius: 9px;
}
.score-rows .sr b { margin-left: auto; font-size: 17px; }
.score-rows .sr.win { outline: 1px solid var(--good); }

.hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }

/* ---------- 窄螢幕 ---------- */

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: stretch; padding: 14px; }
  .board-col { max-width: none; width: 100%; }
  .side-col { width: 100%; flex: none; }
  .log { max-height: 120px; }
}

.banner.clickable { cursor: pointer; }
.banner.clickable:hover { background: #333a4a; }

.choices.wrap { flex-wrap: wrap; }
.choices.wrap button { flex: 1 1 28%; min-width: 72px; }

.pc-think {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.pc-think:empty { display: none; }
.pc-think b { color: var(--text); font-weight: 600; }

/* ---------- 職業 ---------- */

/* 職業用格線排，每一格一樣大。
   用 flex-wrap 的話，最後一列的按鈕會被拉開去填滿整行，六個職業就會變成
   一列四個、一列兩個而且大小不同。 */
.choices.classes,
.choices.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.choices.classes button.class-btn,
.choices.grid-3 button {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 4px;
}

/* AI 職業多一個「隨機」，讓它獨佔一整列，下面兩列才會是整齊的 3 + 3 */
#choice-aiclass button:first-child {
  grid-column: 1 / -1;
}
.cb-name { font-weight: 600; font-size: 14px; }
.cb-role { font-size: 11px; color: var(--muted); }
.choices.classes button.on .cb-role { color: var(--accent-2); }

.class-info {
  margin-top: 10px;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}
.class-info p { margin: 0; }
.class-info .ci-stats { margin-top: 5px; color: var(--text); font-size: 12px; }
.class-info .ci-ult {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.class-info .ci-ult b { color: var(--accent); }
.class-info .ci-cost { float: right; color: var(--muted); font-size: 11.5px; }
.class-info .ci-ult i { color: var(--accent-2); font-style: normal; }

.pc-class {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: -2px 0 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.pc-fx { white-space: nowrap; }
.pc-fx.hot { color: var(--accent); font-weight: 600; }

button.upgrade.ult { border-color: #3d3550; }
button.upgrade.ult .u-cost { color: #c79bf2; }
button.upgrade.ult:not(:disabled):hover { border-color: #a97fe0; }
button.upgrade.ult.on {
  border-color: var(--bad);
  background: #2a1d20;
}
button.upgrade.ult.on .u-sub { color: var(--bad); }
button.upgrade.ult.spent { opacity: .55; }

/* ---------- 強度滑桿 ---------- */

.diff-name {
  float: right;
  color: var(--accent-2);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: 4px 0 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #35507a, var(--accent-2));
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--accent-2);
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--accent-2);
  cursor: pointer;
}
.slider-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}
.diff-blurb {
  margin: 7px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}
