:root {
  --bg: #0d0f14;
  --panel: rgba(20, 23, 31, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9e6df;
  --muted: #9a978f;
  --you: #7fd6ff;
  --ai: #ff6b5e;
  --gold: #d9b26f;
  --danger: #ff5a52;
  color-scheme: dark;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.04em; }
.topbar h1 span { color: var(--gold); font-weight: 400; }
.topbar-actions { display: flex; gap: 8px; }

.panel {
  position: fixed; right: 20px; top: 70px; width: 300px; max-height: calc(100% - 90px);
  overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.panel h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }

button, .filebtn {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover, .filebtn:hover { background: rgba(255, 255, 255, 0.13); }
button:focus-visible, .filebtn:focus-within, input:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.primary { width: 100%; margin-top: 14px; padding: 11px; background: linear-gradient(135deg, #e3bf7c, #b9884a); color: #1a1408; border: 0; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: rgba(10, 12, 16, 0.55); }
button.danger { border-color: rgba(255, 90, 82, 0.5); color: #ffb0ab; }
.filebtn { display: inline-block; position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.levels { display: grid; gap: 8px; }
.level { display: block; cursor: pointer; }
.level input { position: absolute; opacity: 0; }
.level span { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; transition: all 0.15s; }
.level small { color: var(--muted); }
.level input:checked + span { border-color: var(--gold); background: rgba(217, 178, 111, 0.12); }
.level input:focus-visible + span { outline: 2px solid var(--gold); }
.level.hell input:checked + span { border-color: var(--danger); background: rgba(255, 90, 82, 0.12); }

.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player { display: grid; grid-template-columns: auto 1fr auto auto; gap: 6px; align-items: baseline; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.player .dot { width: 10px; height: 10px; border-radius: 50%; align-self: center; }
.player.you .dot { background: var(--you); box-shadow: 0 0 10px var(--you); }
.player.ai .dot { background: var(--ai); box-shadow: 0 0 10px var(--ai); }
.player b { font-size: 18px; font-variant-numeric: tabular-nums; }
.player small { color: var(--muted); }

.status { margin: 14px 0 10px; font-size: 15px; min-height: 1.4em; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mode { padding: 8px 6px; font-size: 14px; }
.mode.active { border-color: var(--gold); background: rgba(217, 178, 111, 0.16); }
kbd { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 2px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.log { margin: 8px 0 12px; padding: 0 0 0 22px; max-height: 160px; overflow: auto; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; color: var(--muted); columns: 2; }
#btn-resign { width: 100%; }


dialog {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 48px); overflow: auto;
  color: var(--text); background: #161921; border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.dialog-head h2 { margin: 0; font-size: 18px; }
dialog h3 { margin: 18px 0 8px; font-size: 14px; color: var(--gold); font-weight: 600; }
.skin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.skin-grid h3 { margin-top: 12px; }
select, input[type="text"] { width: 100%; font: inherit; color: var(--text); background: #0f1117; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input[type="text"] { flex: 1 1 160px; width: auto; }
.custom-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.custom-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.custom-list li small { color: var(--muted); }
.custom-list li button { padding: 4px 10px; font-size: 13px; }
.rules { padding-left: 20px; line-height: 1.8; }

@media (max-width: 720px) {
  .panel { left: 12px; right: 12px; top: auto; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: auto; max-height: 46%; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .topbar h1 { font-size: 17px; }
  .log { display: none; }
  .skin-grid { grid-template-columns: 1fr; }
}
