:root {
  color-scheme: dark;
  --ink: #f1eadb;
  --muted: #9b9d93;
  --night: #090c0b;
  --warm-black: #141815;
  --cloth: #176b3a;
  --cloth-light: #42c96b;
  --wood: #48160f;
  --wood-light: #8c3320;
  --gold: #e4ba52;
  --foul: #e25545;
  --panel: rgb(8 12 10 / 78%);
  --line: rgb(235 221 192 / 16%);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; overflow: hidden; }

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 34%, rgb(47 66 53 / 32%), transparent 42%),
    linear-gradient(135deg, #151a17, var(--night) 64%);
}

button, kbd { font: inherit; }

.game-shell {
  width: 100%; height: 100%;
  display: grid;
  grid-template-rows: clamp(78px, 11vh, 106px) minmax(0, 1fr) clamp(92px, 13vh, 122px);
  padding: clamp(10px, 1.8vw, 24px);
  gap: clamp(8px, 1.3vh, 14px);
}

.match-hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(116px, 168px) minmax(0, 1fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgb(20 26 22 / 90%), var(--panel));
  box-shadow: 0 18px 50px rgb(0 0 0 / 36%), inset 0 1px rgb(255 255 255 / 5%);
  padding: 10px clamp(12px, 2vw, 28px);
}

.competitor { display: flex; align-items: center; gap: clamp(8px, 1.2vw, 16px); min-width: 0; }
.competitor--ai { justify-content: flex-end; }

.avatar {
  width: clamp(42px, 4vw, 58px); aspect-ratio: 1; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid rgb(228 186 82 / 52%); border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #f6db78, #98701b 58%, #2f2108);
  color: #171206; font: 800 clamp(16px, 1.7vw, 24px)/1 Georgia, serif;
  box-shadow: 0 0 0 4px rgb(0 0 0 / 24%);
}

.avatar--ai { background: radial-gradient(circle at 34% 28%, #9af0b2, #26784b 58%, #092416); color: #07180d; font-size: clamp(11px, 1.1vw, 16px); }
.competitor-copy { display: grid; gap: 3px; white-space: nowrap; }
.competitor-copy strong { font-family: Georgia, "STSong", serif; font-size: clamp(15px, 1.35vw, 20px); letter-spacing: .08em; }
.competitor-copy span { color: var(--muted); font-size: clamp(11px, .9vw, 13px); }

.ball-slots { display: flex; gap: clamp(3px, .4vw, 6px); min-width: 0; }
.ball-slots i {
  width: clamp(12px, 1.45vw, 21px); aspect-ratio: 1; flex: 0 1 auto;
  border: 1px solid rgb(255 255 255 / 9%); border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff, var(--ball-color, #202720) 28% 72%, #090b09);
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 60%);
  display: grid; place-items: center;
  color: #101310; font: 700 clamp(7px, .65vw, 10px)/1 Georgia, serif;
  transition: opacity 180ms ease, filter 180ms ease;
}
.ball-slots i.is-potted { opacity: .18; filter: grayscale(1); }

.versus { display: grid; place-items: center; position: relative; align-self: stretch; }
.versus b { font: 400 clamp(28px, 3.3vw, 46px)/1 Georgia, serif; letter-spacing: .06em; text-shadow: 0 4px 18px rgb(0 0 0 / 80%); }
.turn-indicator { color: var(--gold); font-size: 11px; letter-spacing: .18em; }
.rack-mark { color: var(--muted); font: 10px/1 Georgia, serif; letter-spacing: .2em; }

.table-stage { position: relative; min-height: 0; display: grid; place-items: center; }
#game-canvas { display: block; flex: 0 0 auto; aspect-ratio: 1200 / 650; filter: drop-shadow(0 30px 40px rgb(0 0 0 / 52%)); }

.turn-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  min-width: 240px; padding: 14px 28px; text-align: center;
  border-block: 1px solid rgb(228 186 82 / 25%);
  background: linear-gradient(90deg, transparent, rgb(4 9 6 / 84%) 18% 82%, transparent);
  color: var(--gold); font-family: Georgia, "STSong", serif; font-size: clamp(20px, 2vw, 28px); letter-spacing: .18em;
  pointer-events: none;
  opacity: 1; transition: opacity 220ms ease, transform 220ms ease;
}
.turn-banner.is-hidden { opacity: 0; transform: translate(-50%, calc(-50% - 8px)); }

body[data-phase="charging"] #game-canvas,
body[data-phase="aiming"] #game-canvas { cursor: crosshair; }
body[data-phase="ball-in-hand"] #game-canvas { cursor: copy; }
body[data-phase="ai-thinking"] #game-canvas,
body[data-phase="balls-moving"] #game-canvas { cursor: wait; }

.control-deck {
  display: grid; grid-template-columns: minmax(280px, 1fr) auto minmax(120px, .3fr);
  align-items: center; gap: clamp(18px, 3vw, 48px);
  border-top: 1px solid var(--line); padding-inline: clamp(4px, 2vw, 24px);
}

.power-block { display: grid; gap: 8px; }
.power-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; letter-spacing: .12em; }
.power-label output { color: var(--gold); }
.power-track { position: relative; height: 16px; overflow: hidden; border: 1px solid rgb(255 255 255 / 14%); border-radius: 3px; background: #070a08; box-shadow: inset 0 3px 7px rgb(0 0 0 / 70%); }
#power-fill { width: 0%; height: 100%; background: linear-gradient(90deg, #5bbf58, var(--gold) 62%, var(--foul)); transition: width 40ms linear; }
.power-glint { position: absolute; inset: 2px 3px auto; height: 2px; background: rgb(255 255 255 / 25%); }

.instructions { margin: 0; color: var(--muted); font-size: clamp(11px, .95vw, 14px); white-space: nowrap; text-wrap: pretty; }
kbd { color: var(--ink); border: 1px solid var(--line); border-bottom-color: rgb(255 255 255 / 28%); border-radius: 4px; background: rgb(255 255 255 / 5%); padding: 3px 6px; }

#restart-button {
  justify-self: end; min-width: 116px; min-height: 44px;
  border: 1px solid rgb(228 186 82 / 45%); border-radius: 10px;
  color: var(--ink); background: linear-gradient(180deg, #4b3512, #211706);
  box-shadow: inset 0 1px rgb(255 255 255 / 10%), 0 8px 24px rgb(0 0 0 / 28%);
  cursor: pointer; transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
#restart-button:hover { border-color: var(--gold); background: linear-gradient(180deg, #684917, #2a1c08); }
#restart-button:active { transform: translateY(1px) scale(.985); }
#restart-button:focus-visible { outline: 3px solid rgb(228 186 82 / 36%); outline-offset: 3px; }

@media (max-width: 920px) {
  .game-shell { grid-template-rows: 76px minmax(0, 1fr) 112px; padding: 8px; }
  .match-hud { padding-inline: 10px; grid-template-columns: 1fr 82px 1fr; }
  .ball-slots { display: none; }
  .versus b { font-size: 28px; }
  .control-deck { grid-template-columns: 1fr auto; gap: 12px; }
  .instructions { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
