:root {
  --ink: #0b2a3c;
  --panel: rgba(11, 42, 60, 0.92);
  --accent: #f2b134;
  --orange: #e8622a;
  --green: #2e9e4f;
  --text: #eef6fa;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--ink); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none;
}
#stage { position: fixed; inset: 0; }
canvas#game { position: absolute; display: block; background: #bfe3f5; }
.hidden { display: none !important; }

.screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 22, 32, 0.45); padding: 16px; z-index: 5;
}
.card {
  background: var(--panel); border-radius: 14px; padding: 22px 28px; max-width: 620px; width: 100%;
  max-height: 100%; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.35); text-align: center;
  touch-action: pan-y;
}
.card.small { max-width: 360px; }
h1 { margin: 0; font-size: 56px; letter-spacing: 6px; color: var(--accent); }
h2 { margin: 0 0 8px; font-size: 32px; color: var(--accent); }
.sub { margin: 0 0 12px; font-size: 18px; color: #9fd3e8; letter-spacing: 2px; }
.goal { font-size: 18px; margin: 8px 0 10px; }
.rules { text-align: left; margin: 0 auto 12px; padding-left: 20px; max-width: 520px; line-height: 1.45; font-size: 15px; }
.keys { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 14px; color: #cfe6f0; margin-bottom: 14px; }
kbd { display: inline-block; min-width: 26px; padding: 2px 6px; margin: 0 2px; border-radius: 5px; background: #123e57; border: 1px solid #2d6684; font-family: inherit; }
.buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
button {
  font: inherit; font-size: 18px; padding: 10px 22px; border-radius: 10px; border: 0; cursor: pointer;
  background: #2a5a76; color: var(--text); touch-action: manipulation;
}
button.primary { background: var(--accent); color: #1d1d1d; font-weight: 700; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.credit { margin: 16px 0 0; font-size: 13px; color: #9fd3e8; }
.bigtime { font-size: 54px; font-weight: 800; margin: 4px 0; color: #fff; font-variant-numeric: tabular-nums; }
.stats { color: #cfe6f0; margin: 0 0 12px; font-size: 15px; }
form { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 6px 0; }
label { width: 100%; font-size: 15px; color: #cfe6f0; }
input#initials {
  font: inherit; font-size: 28px; width: 110px; text-align: center; text-transform: uppercase; letter-spacing: 6px;
  padding: 6px 8px; border-radius: 10px; border: 2px solid #2d6684; background: #fff; color: #111;
  -webkit-user-select: text; user-select: text;
}
.msg { min-height: 1.3em; margin: 6px 0; color: #ffd34d; font-size: 15px; }
ol#boardList { text-align: left; margin: 8px auto; padding-left: 0; max-width: 360px; list-style: none; counter-reset: r; }
ol#boardList li { counter-increment: r; display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 8px; font-size: 20px; font-variant-numeric: tabular-nums; }
ol#boardList li::before { content: counter(r) "."; width: 2.2em; color: #9fd3e8; }
ol#boardList li .n { flex: 1; letter-spacing: 3px; font-weight: 700; }
ol#boardList li.me { background: var(--accent); color: #1d1d1d; }
ol#boardList li.me::before { color: #1d1d1d; }
ol#boardList li.empty::before { content: ""; }

#touch { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.tgroup { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 14px; align-items: center; pointer-events: none; }
.tgroup.left { left: max(14px, env(safe-area-inset-left)); }
.tgroup.right { right: max(14px, env(safe-area-inset-right)); flex-direction: column-reverse; gap: 10px; }
.tlabel { position: absolute; bottom: -2px; font-size: 11px; color: #fff; opacity: .7; width: 100%; text-align: center; pointer-events: none; display: none; }
.tbtn {
  pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; font-size: 30px; padding: 0;
  background: rgba(11, 42, 60, 0.72); color: #fff; border: 2px solid rgba(255,255,255,.25);
  touch-action: none;
}
.tbtn.on { background: rgba(242, 177, 52, 0.85); color: #1d1d1d; }
.tbtn.dump {
  position: absolute; right: calc(max(14px, env(safe-area-inset-right)) + 96px); bottom: max(14px, env(safe-area-inset-bottom));
  width: 130px; height: 64px; border-radius: 14px; font-size: 18px; font-weight: 800; background: rgba(46, 158, 79, 0.85);
}
#rotate {
  position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center;
  background: var(--ink); font-size: 22px; padding: 24px; text-align: center;
}

@media (max-height: 520px) {
  .card { padding: 12px 18px; }
  h1 { font-size: 38px; }
  h2 { font-size: 24px; margin-bottom: 4px; }
  .sub { margin-bottom: 6px; font-size: 15px; }
  .goal { font-size: 15px; margin: 4px 0 6px; }
  .rules { font-size: 13px; line-height: 1.35; margin-bottom: 6px; }
  .keys { display: none; }
  .bigtime { font-size: 36px; margin: 0; }
  .stats { margin-bottom: 6px; font-size: 13px; }
  button { font-size: 16px; padding: 8px 18px; }
  input#initials { font-size: 22px; width: 96px; padding: 4px 6px; }
  ol#boardList li { font-size: 16px; padding: 3px 10px; }
  .credit { margin-top: 8px; }
}
