/* ── Custom properties ─────────────────────────────────────────────────────── */
:root {
  --tile-size:        72px;

  /* backgrounds */
  --board-bg:         #080810;
  --viewport-bg:      #050508;
  --ui-bg:            #0a0a14;
  --ui-border:        #18183a;

  /* neon accent colours */
  --neon-cyan:        #00f5ff;
  --neon-pink:        #ff006e;
  --neon-purple:      #9b5de5;
  --neon-yellow:      #ffe600;
  --neon-green:       #39ff14;

  /* text */
  --text-color:       #c8d8ff;
  --text-dim:         #3a3a6a;

  /* interactive states */
  --valid-fill:       rgba(0, 245, 255, 0.07);
  --valid-border:     rgba(0, 245, 255, 0.75);
  --blossom-color:    var(--neon-yellow);

  /* modals */
  --overlay-bg:       rgba(3, 3, 10, 0.94);
  --card-bg:          #0c0c1e;
  --card-border:      #2a0a5a;

  /* misc */
  --radius-sm:        3px;
  --radius-md:        8px;
  --font:             'Orbitron', system-ui, sans-serif;
  --mono:             'Share Tech Mono', monospace;
}

/* ── Reset / base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--viewport-bg);
  font-family: var(--font);
  color: var(--text-color);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: var(--font);
}

/* ── Top bar ───────────────────────────────────────────────────────────────── */
#ui-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 12px;
  background: var(--ui-bg);
  border-bottom: 1px solid var(--ui-border);
  box-shadow: 0 1px 0 rgba(0, 245, 255, 0.08);
  z-index: 20;
}

#deck-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan);
  min-width: 64px;
  letter-spacing: 0.04em;
}

#game-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-color);
  text-shadow: 0 0 10px var(--neon-cyan), 0 0 20px rgba(0, 245, 255, 0.3);
  animation: title-glow 3s ease-in-out infinite alternate;
}

@keyframes title-glow {
  from { text-shadow: 0 0 8px var(--neon-cyan), 0 0 16px rgba(0, 245, 255, 0.3); }
  to   { text-shadow: 0 0 14px var(--neon-cyan), 0 0 30px rgba(0, 245, 255, 0.5), 2px 0 var(--neon-pink), -2px 0 var(--neon-cyan); }
}

#ui-top-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

#help-btn, #new-game-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
  box-shadow: 0 0 6px rgba(0, 245, 255, 0.15), inset 0 0 6px rgba(0, 245, 255, 0.05);
  transition: box-shadow 0.15s, background 0.15s;
}

#help-btn {
  width: 30px;
  padding: 0;
  text-align: center;
  font-size: 14px;
  border-color: var(--neon-purple);
  color: var(--neon-purple);
  text-shadow: 0 0 6px var(--neon-purple);
  box-shadow: 0 0 6px rgba(155, 93, 229, 0.2);
}

#help-btn:active {
  background: rgba(155, 93, 229, 0.15);
  box-shadow: 0 0 16px rgba(155, 93, 229, 0.5);
}

#new-game-btn:active {
  background: rgba(0, 245, 255, 0.1);
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.5), inset 0 0 10px rgba(0, 245, 255, 0.1);
}

/* ── Board viewport ────────────────────────────────────────────────────────── */
#board-viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  touch-action: none;
  /* circuit-board grid */
  background-color: var(--viewport-bg);
  background-image:
    linear-gradient(rgba(0, 245, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 245, 255, 0.04) 1px, transparent 1px);
  background-size: var(--tile-size) var(--tile-size);
}

/* scanline overlay */
#board-viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.1) 3px,
    rgba(0, 0, 0, 0.1) 4px
  );
  pointer-events: none;
  z-index: 10;
}

/* ── Board (inner, panned) ─────────────────────────────────────────────────── */
#board {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  will-change: transform;
  z-index: 1;
}

/* ── Tiles (SVG-rendered) ──────────────────────────────────────────────────── */
.tile {
  position: absolute;
  width:  var(--tile-size);
  height: var(--tile-size);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(0, 245, 255, 0.18);
  box-shadow:
    0 0 12px rgba(0, 0, 0, 0.8),
    0 0 5px rgba(0, 245, 255, 0.12);
}

.tile svg {
  display: block;
  position: absolute;
  inset: 0;
}

/* ── Valid placement spots ─────────────────────────────────────────────────── */
.valid-spot {
  position: absolute;
  width:  var(--tile-size);
  height: var(--tile-size);
  border: 1px solid var(--valid-border);
  background: var(--valid-fill);
  border-radius: var(--radius-sm);
  cursor: pointer;
  animation: neon-pulse 1.4s ease-in-out infinite;
}

@keyframes neon-pulse {
  0%, 100% {
    box-shadow: 0 0 6px var(--neon-cyan), inset 0 0 6px rgba(0, 245, 255, 0.08);
    border-color: rgba(0, 245, 255, 0.6);
  }
  50% {
    box-shadow: 0 0 18px var(--neon-cyan), inset 0 0 14px rgba(0, 245, 255, 0.15);
    border-color: rgba(0, 245, 255, 1);
  }
}

.valid-spot:active {
  background: rgba(0, 245, 255, 0.2);
  box-shadow: 0 0 30px var(--neon-cyan);
}

/* ── Blossom dots ──────────────────────────────────────────────────────────── */
.blossom-dot {
  position: absolute;
  width:  22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blossom-color, var(--neon-yellow));
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow:
    0 0 12px 3px var(--blossom-color, var(--neon-yellow)),
    0 0 30px 6px var(--blossom-color, var(--neon-yellow)),
    0 0 60px     var(--blossom-color, var(--neon-yellow));
  z-index: 5;
}

.blossom-dot.pending {
  animation: pending-pulse 0.8s ease-in-out infinite;
}

@keyframes pending-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1);   opacity: 0.7; }
  50%       { transform: translate(-50%, -50%) scale(1.4); opacity: 1;   }
}

/* ── Token choosable state ─────────────────────────────────────────────────── */
.token.choosable {
  transform: scale(1.25);
  box-shadow: 0 0 18px var(--token-color, #fff), 0 0 4px var(--token-color, #fff);
  animation: choosable-pulse 0.7s ease-in-out infinite;
  cursor: pointer;
  opacity: 1 !important;
}

@keyframes choosable-pulse {
  0%, 100% { transform: scale(1.2);  }
  50%       { transform: scale(1.35); }
}

.token.not-choosable {
  opacity: 0.15 !important;
  filter: grayscale(0.7);
}

/* ── Bottom bar ────────────────────────────────────────────────────────────── */
#ui-bottom {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 88px;
  padding: 0 12px;
  background: var(--ui-bg);
  border-top: 1px solid var(--ui-border);
  box-shadow: 0 -1px 0 rgba(0, 245, 255, 0.08);
  z-index: 20;
}

#current-tile-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

#current-tile-label {
  font-size: 9px;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

#current-tile-container {
  width: 52px;
  height: 52px;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.25);
}

#current-tile-container .tile {
  width: 52px;
  height: 52px;
}

#score {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--neon-pink);
  text-shadow: 0 0 8px var(--neon-pink);
  flex: 0 0 auto;
  min-width: 60px;
  text-align: center;
  letter-spacing: 0.04em;
}

/* ── Token rack ────────────────────────────────────────────────────────────── */
#token-rack {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-content: center;
  flex: 1 1 auto;
  max-width: 200px;
}

.token {
  width:  28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--token-color, rgba(255, 255, 255, 0.4));
  box-shadow: 0 0 8px var(--token-color, rgba(255, 255, 255, 0.3));
  flex: 0 0 auto;
  position: relative;
  transition: opacity 0.3s, box-shadow 0.3s;
}

.token.placed {
  opacity: 0.25;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.token.placed::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
}

/* ── Win / end overlay ─────────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
}

#overlay.hidden { display: none; }

#overlay-content {
  background: var(--card-bg);
  border: 1px solid var(--neon-pink);
  border-radius: var(--radius-md);
  padding: 28px 24px;
  max-width: 320px;
  width: 90%;
  max-height: 90dvh;
  overflow-y: auto;
  text-align: center;
  box-shadow:
    0 0 30px rgba(255, 0, 110, 0.25),
    0 0 60px rgba(255, 0, 110, 0.1),
    inset 0 0 20px rgba(255, 0, 110, 0.05);
}

#overlay-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 10px;
  color: var(--neon-pink);
  text-shadow: 0 0 12px var(--neon-pink), 0 0 24px rgba(255, 0, 110, 0.5);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#overlay-message {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text-color);
  margin: 0 0 16px;
  line-height: 1.6;
  letter-spacing: 0.04em;
}

/* ── Initials entry ────────────────────────────────────────────────────────── */
#initials-section {
  margin: 0 0 16px;
  text-align: center;
}

.hs-prompt {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
  margin: 0 0 10px;
}

#initials-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

#initials-input {
  width: 72px;
  background: transparent;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  font-family: var(--mono);
  font-size: 22px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  outline: none;
  caret-color: var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.25);
}

#initials-input:focus {
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.55);
}

#initials-submit {
  background: transparent;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-shadow: 0 0 6px var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.2);
  transition: background 0.12s, box-shadow 0.12s;
}

#initials-submit:active {
  background: rgba(0, 245, 255, 0.15);
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.55);
}

#initials-submit:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}

/* ── Leaderboard ───────────────────────────────────────────────────────────── */
#leaderboard {
  margin: 0 0 16px;
  text-align: left;
}

.hs-title {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--neon-purple);
  text-shadow: 0 0 6px var(--neon-purple);
  margin: 0 0 8px;
  text-align: center;
}

#score-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
}

#score-list li {
  display: flex;
  align-items: center;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-color);
  gap: 6px;
}

#score-list li.hs-highlight {
  color: var(--neon-yellow);
  text-shadow: 0 0 8px var(--neon-yellow);
}

.hs-rank {
  width: 20px;
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.hs-initials {
  flex: 1;
  letter-spacing: 0.15em;
}

.hs-score {
  min-width: 28px;
  text-align: right;
}

.hs-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 8px 0;
  font-size: 11px;
}

#play-again-btn {
  background: transparent;
  border: 2px solid var(--neon-cyan);
  color: var(--neon-cyan);
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 0 8px var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.3), inset 0 0 12px rgba(0, 245, 255, 0.05);
  transition: box-shadow 0.15s, background 0.15s;
}

#play-again-btn:active {
  background: rgba(0, 245, 255, 0.12);
  box-shadow: 0 0 24px rgba(0, 245, 255, 0.6);
}

/* ── Help modal ────────────────────────────────────────────────────────────── */
#help-modal {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
}

#help-modal.hidden { display: none; }

#help-content {
  background: var(--card-bg);
  border: 1px solid var(--neon-purple);
  border-radius: var(--radius-md);
  padding: 28px 24px;
  max-width: 340px;
  width: 92%;
  box-shadow:
    0 0 24px rgba(155, 93, 229, 0.2),
    inset 0 0 16px rgba(155, 93, 229, 0.04);
}

#help-content h2 {
  margin: 0 0 14px;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--neon-purple);
  text-shadow: 0 0 10px var(--neon-purple);
}

#help-content ul {
  margin: 0 0 20px;
  padding-left: 18px;
  font-family: var(--mono);
  color: var(--text-color);
  font-size: 13px;
  line-height: 1.8;
}

#help-content ul li { margin-bottom: 4px; }

#help-content ul strong {
  color: var(--neon-cyan);
  text-shadow: 0 0 6px rgba(0, 245, 255, 0.5);
}

#help-close {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px solid var(--neon-purple);
  color: var(--neon-purple);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 0 6px var(--neon-purple);
  box-shadow: 0 0 8px rgba(155, 93, 229, 0.2);
  transition: background 0.15s, box-shadow 0.15s;
}

#help-close:active {
  background: rgba(155, 93, 229, 0.15);
  box-shadow: 0 0 18px rgba(155, 93, 229, 0.5);
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes tile-drop {
  from { opacity: 0; transform: scale(0.65) translateY(-10px); filter: brightness(2); }
  to   { opacity: 1; transform: scale(1)    translateY(0);     filter: brightness(1); }
}

@keyframes blossom-pulse {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0); }
  40%  { opacity: 1; transform: translate(-50%, -50%) scale(2); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
}

@keyframes token-appear {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; filter: brightness(3); }
  60%  { transform: scale(1.25) rotate(5deg); opacity: 1; filter: brightness(1.5); }
  100% { transform: scale(1) rotate(0);      opacity: 0.25; filter: brightness(1); }
}

.tile.placing {
  animation: tile-drop 0.2s ease-out;
}

.blossom-dot.new {
  animation: blossom-pulse 0.6s ease-out;
}

.token.placed {
  animation: token-appear 0.35s ease-out;
}

/* ── Responsive tweaks ─────────────────────────────────────────────────────── */
@media (min-width: 500px) {
  :root { --tile-size: 80px; }
  #ui-bottom { height: 96px; }
  #current-tile-container,
  #current-tile-container .tile { width: 58px; height: 58px; }
}

@media (min-width: 768px) {
  :root { --tile-size: 88px; }
}
