:root {
  --bg: #0d1412;
  --panel: #16211d;
  --text: #e8efe9;
  --muted: #8fa39a;
  --accent: #f2c200;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, #1b2a24 0%, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
}

.hud {
  width: 100%;
  max-width: 1128px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.12em;
  font-weight: 800;
}
h1 span { color: var(--accent); margin-left: 0.3em; }

.players { display: flex; gap: 8px; }

.player {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.player { display: flex; flex-direction: column; align-items: center; line-height: 1.2; border-radius: 12px; }
.player .group { font-size: 11px; font-weight: 500; opacity: 0.8; text-transform: capitalize; }
.player[data-group="solids"] .group::before,
.player[data-group="stripes"] .group::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: -1px;
  background: #d42a1e;
}
.player[data-group="stripes"] .group::before {
  background: linear-gradient(#f4f1e6 0 28%, #d42a1e 28% 72%, #f4f1e6 72%);
}
.player.active {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(242, 194, 0, 0.25);
}
.player.winner { background: var(--accent); color: #111; }

button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid #2c3d36;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button[hidden] { display: none; }
.actions { display: flex; gap: 8px; }
button.replace { border-color: var(--accent); color: var(--accent); }

main { display: flex; justify-content: center; align-items: center; gap: 12px; }

/* The board wraps the table canvas so overlays (the win screen) sit exactly on top of it. */
.board { position: relative; line-height: 0; }

canvas {
  display: block;
  touch-action: none;
  cursor: crosshair;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

footer {
  width: 100%;
  max-width: 1128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#status { min-height: 1.4em; font-weight: 600; text-align: center; }

#tray { display: flex; flex-wrap: wrap; gap: 4px; min-height: 24px; justify-content: center; }

.ball {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.35), inset 2px 2px 4px rgba(255, 255, 255, 0.3);
}
.ball b {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #f4f1e6;
  color: #111;
  font-size: 8px;
  display: grid;
  place-items: center;
}

.help { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* Touch power bar (shown only on touch devices) */
.power { display: none; }
body.touch .power {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 64px;
  padding: 10px 0;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: ns-resize;
  transition: opacity 0.2s;
}
body.touch .power.disabled { opacity: 0.35; }
.power-label { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; color: var(--muted); }
.power-cue {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  border-radius: 0;
  box-shadow: none;
  touch-action: none;
  cursor: ns-resize;
}
.power.active .power-label { color: var(--accent); }

body.touch .mouse-help, body:not(.touch) .touch-help { display: none; }

/* Level badge */
.brand { display: flex; align-items: center; gap: 10px; }
.level {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #111;
  background: var(--accent);
}

/* Win screen */
.win {
  position: absolute;
  inset: 0;
  z-index: 10;
  border-radius: 20px;
  line-height: normal;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(5, 10, 8, 0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.35s;
  overflow: hidden;
}
.win[hidden] { display: none; }
.win.show { opacity: 1; }

.win-card {
  position: relative;
  max-width: min(520px, 90%);
  max-height: 100%;
  overflow: auto;
  width: 100%;
  text-align: center;
  padding: clamp(14px, 3.5vmin, 32px) clamp(16px, 3vmin, 28px);
  border-radius: 24px;
  background: linear-gradient(180deg, #1d2c26, #121a17);
  border: 2px solid var(--accent);
  box-shadow: 0 0 60px rgba(242, 194, 0, 0.35), 0 30px 80px rgba(0, 0, 0, 0.6);
  transform: scale(0.6);
}
.win.show .win-card { animation: pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) forwards; }
@keyframes pop { to { transform: scale(1); } }

.win-trophy { font-size: clamp(32px, 7vmin, 64px); line-height: 1; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }

.win-level {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.win-title {
  margin: 6px 0 8px;
  font-size: clamp(26px, 6.5vmin, 60px);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(242, 194, 0, 0.55), 0 4px 0 #7a5d00;
}
.win-reason { margin: 0 0 6px; color: var(--text); }
.win-next { margin: 0 0 clamp(10px, 2.4vmin, 22px); color: var(--muted); font-size: 14px; }

.win-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.win-actions button { min-width: min(240px, 100%); }
button.primary {
  font-size: 18px;
  padding: 12px 28px;
  border: none;
  color: #111;
  background: var(--accent);
  box-shadow: 0 6px 20px rgba(242, 194, 0, 0.35);
}
button.primary:hover { filter: brightness(1.1); }

.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: fall linear forwards;
}
@keyframes fall {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0.9; transform: translate(var(--drift), 110vh) rotate(var(--spin)); }
}

@media (prefers-reduced-motion: reduce) {
  .win.show .win-card { animation: none; transform: none; }
  .win-trophy { animation: none; }
  .confetti { display: none; }
}

/* Player avatars beside the table: you on the left, the computer on the right */
.avatar {
  position: relative;
  flex: none;
  width: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.avatar-face {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid #2c3d36;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}
.avatar-face svg { display: block; width: 100%; height: 100%; }
.avatar.active .avatar-face {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(242, 194, 0, 0.18), 0 0 28px rgba(242, 194, 0, 0.45);
  transform: scale(1.06);
}
.avatar-name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.avatar-status {
  min-height: 1.2em;
  font-size: 12px;
  color: var(--muted);
  text-transform: capitalize;
}
.avatar.active .avatar-status { color: var(--accent); font-weight: 600; }

.avatar[data-mood="happy"] .avatar-face { animation: hop 0.5s ease-out 2; }
.avatar[data-mood="sad"] .avatar-face { animation: droop 0.6s ease-out; }
.avatar[data-mood="thinking"] .avatar-face { animation: ponder 1.6s ease-in-out infinite; }
@keyframes hop { 40% { translate: 0 -10px; } }
@keyframes droop { 50% { rotate: -8deg; } }
@keyframes ponder { 50% { rotate: 5deg; } }

@media (max-width: 900px) {
  .avatar { width: 72px; }
  .avatar-face { width: 60px; height: 60px; }
  .avatar-name { font-size: 12px; }
}
@media (max-width: 560px) {
  .avatar { width: 48px; }
  .avatar-face { width: 44px; height: 44px; border-width: 2px; }
  .avatar-name, .avatar-status { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .avatar-face { animation: none !important; }
}

/* Level badge for Pro */
.level.pro { background: linear-gradient(135deg, #ffe680, #f2c200 50%, #b88a00); box-shadow: 0 0 12px rgba(242, 194, 0, 0.5); }

/* Spin control (Pro only) */
.status-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.spin { display: flex; align-items: center; gap: 8px; }
.spin[hidden] { display: none; }
.spin-ball {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #d8d2bf 70%, #a9a28c);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
  cursor: ns-resize;
  touch-action: none;
  flex: none;
}
.spin-ball::before {
  content: "";
  position: absolute;
  left: 50%; top: 16%; bottom: 16%;
  width: 1px;
  background: rgba(0, 0, 0, 0.2);
}
.spin-ball i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #d42a1e;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}
.spin-label { font-size: 12px; font-weight: 700; color: var(--accent); min-width: 72px; }

/* Home screen */
.home {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, #1b2a24 0%, var(--bg) 75%);
}
.home[hidden] { display: none; }
.home-card {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.home-title {
  margin: 0;
  font-size: clamp(40px, 11vmin, 88px);
  letter-spacing: 0.12em;
  line-height: 1;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}
.home-title span { color: var(--accent); margin-left: 0.25em; text-shadow: 0 0 30px rgba(242, 194, 0, 0.45), 0 6px 0 #7a5d00; }
.home-stats { margin: 0; color: var(--muted); font-size: 14px; }
.home .primary { min-width: min(260px, 100%); }
.home-levels {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 6px;
}
.level-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid #2c3d36;
  line-height: 1.25;
}
.level-card:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.level-card:disabled { opacity: 0.45; cursor: not-allowed; }
.lc-swatch {
  grid-row: 1 / span 3;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--cloth-a), var(--cloth-b));
  border: 3px solid #6b3f1d;
}
.lc-level { font-weight: 800; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.lc-opp { font-size: 13px; color: var(--text); font-weight: 600; }
.lc-status { font-size: 11px; color: var(--muted); font-weight: 500; }
.level-card.beaten .lc-status { color: #5fd38a; }
.level-card.pro {
  grid-column: 1 / -1;
  border: 2px solid var(--accent);
  background: linear-gradient(135deg, #2a2610, var(--panel) 60%);
  box-shadow: 0 0 24px rgba(242, 194, 0, 0.2);
}
.level-card.pro .lc-level { color: var(--accent); font-size: 15px; }
.level-card.pro:disabled { opacity: 0.6; box-shadow: none; }
.home-reset {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  padding: 4px;
}
.home-reset:hover { color: var(--text); }
body:not(.pro) .pro-help { display: none; }
@media (max-height: 500px) { .pro-help { display: none; } }
