:root {
  color-scheme: dark;
  --bg: #081016;
  --panel: #0e1921;
  --line: rgba(144, 245, 255, 0.14);
  --text: #edf9ff;
  --muted: #8da6b2;
  --accent: #27d7ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 10%, rgba(39, 215, 255, 0.12), transparent 28rem),
    radial-gradient(circle at 82% 86%, rgba(175, 108, 255, 0.11), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
select,
input {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:hover,
button:focus-visible {
  border-color: rgba(39, 215, 255, 0.55);
  outline: none;
}

.primary {
  border-color: rgba(39, 215, 255, 0.6);
  background: linear-gradient(135deg, rgba(39, 215, 255, 0.26), rgba(175, 108, 255, 0.2));
  box-shadow: 0 0 22px rgba(39, 215, 255, 0.14);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100svh;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
}

.hidden {
  display: none !important;
}

#menu {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 22px;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.brand {
  width: min(420px, 100%);
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(42px, 12vw, 72px);
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow: 0 0 26px rgba(39, 215, 255, 0.28);
}

.brand p {
  margin: 14px 0 0;
  color: var(--muted);
}

.control-group,
.control-row,
.target-score,
.primary {
  width: min(420px, 100%);
}

.label,
label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented .selected {
  color: #071018;
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 0 20px rgba(39, 215, 255, 0.2);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

select,
input {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
}

#gameScreen {
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}

.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: min(860px, 100%);
  margin: 0 auto 10px;
}

.turn-indicator {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.swatch,
.winner-swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
}

.turn-text {
  white-space: nowrap;
}

.score-board {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
  overflow: hidden;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 5px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.score-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

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

.hud button {
  min-height: 38px;
  padding: 0 12px;
}

#boardWrap {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
}

#gameCanvas {
  display: block;
  width: min(100%, 860px, calc(100svh - 76px));
  height: min(calc(100vw - 20px), 860px, calc(100svh - 76px));
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: rgba(4, 11, 16, 0.62);
  box-shadow: 0 0 0 1px rgba(144, 245, 255, 0.11), 0 20px 80px rgba(0, 0, 0, 0.34);
  touch-action: none;
}

.chain-popup {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(5, 12, 18, 0.72);
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 0 28px rgba(39, 215, 255, 0.18);
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 14, 0.72);
  backdrop-filter: blur(10px);
}

.dialog {
  width: min(320px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(13, 25, 34, 0.92);
  padding: 22px;
  text-align: center;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
}

.winner-swatch {
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
}

.dialog h2 {
  margin: 0 0 18px;
  font-size: 24px;
}

.dialog button {
  width: 100%;
  margin-top: 10px;
}

@media (max-width: 520px) {
  .hud {
    align-items: stretch;
  }

  .score-board {
    order: 3;
    flex-basis: 100%;
  }

  .hud-actions button {
    min-width: 0;
    padding: 0 10px;
  }

  #gameCanvas {
    width: min(100%, calc(100svh - 72px));
    height: min(calc(100vw - 20px), calc(100svh - 72px));
  }
}
