/* ── Reset & Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black:   #0a0a0a;
  --bg:      #111111;
  --surface: #1a1a1a;
  --border:  #2a2a2a;
  --yellow:  #f5d800;
  --yellow2: #ffec4a;
  --white:   #f0f0f0;
  --gray:    #888;
  --red:     #ff4a4a;
  --green:   #4ade80;
  --mono: 'IBM Plex Mono', monospace;
  --display: 'Boogaloo', cursive;
}

html, body {
  height: 100%;
  background: var(--black);
  color: var(--white);
  font-family: var(--mono);
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg);
  border-bottom: 2px solid var(--yellow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo { height: 48px; width: 48px; object-fit: contain; border-radius: 10px; }
.brand-title {
  font-family: var(--display);
  font-size: 1.5rem;
  letter-spacing: 0.05em;
  color: var(--white);
}
.yellow { color: var(--yellow); }

.wallet-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.wallet-info { font-size: 0.7rem; color: var(--gray); }
.wallet-addr {
  display: inline-block;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--yellow);
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.5rem 1.1rem;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  letter-spacing: 0.04em;
  transition: all 0.15s;
  text-transform: uppercase;
}
.btn-yellow {
  background: var(--yellow);
  color: var(--black);
}
.btn-yellow:hover { background: var(--yellow2); transform: translateY(-1px); }
.btn-yellow:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--gray);
}
.btn-ghost:hover { border-color: var(--gray); color: var(--white); }
.btn-big { font-size: 1rem; padding: 0.75rem 2rem; width: 100%; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.main-layout {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  gap: 1rem;
  padding: 1rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
  min-height: calc(100vh - 68px);
}

/* ── Scoreboard ──────────────────────────────────────────────────────────────── */
.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
}
.score-label {
  font-size: 0.65rem;
  color: var(--gray);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}
.score-value {
  font-family: var(--display);
  font-size: 2rem;
  color: var(--white);
  line-height: 1.1;
}
.tiny-value { color: var(--yellow); }
.cost-val { font-size: 1.4rem; color: var(--green); }
.score-sub { font-size: 0.6rem; color: var(--gray); margin-top: 0.15rem; }
.tiny-card { border-color: var(--yellow); box-shadow: 0 0 12px rgba(245,216,0,0.15); }

.rules-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  font-size: 0.72rem;
  line-height: 1.7;
}
.rules-box h3 {
  font-size: 0.65rem;
  color: var(--yellow);
  letter-spacing: 0.12em;
  margin-bottom: 0.5rem;
}
.rules-box ul { list-style: none; padding: 0; }
.rules-box li { margin-bottom: 0.2rem; }

/* ── Game Canvas ─────────────────────────────────────────────────────────────── */
.game-section {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.canvas-wrapper {
  position: relative;
  border: 2px solid var(--yellow);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(245,216,0,0.3), 0 0 80px rgba(245,216,0,0.1);
}
#pinball-canvas {
  display: block;
  background: #0d0d0d;
}

/* ── Overlays ────────────────────────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,10,10,0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
.overlay.active { display: flex; }

.overlay-inner {
  text-align: center;
  padding: 2rem;
  max-width: 320px;
}
.overlay-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.overlay-inner h1 {
  font-family: var(--display);
  font-size: 2.8rem;
  line-height: 1.1;
  margin-bottom: 0.25rem;
}
.overlay-sub { color: var(--gray); font-size: 0.75rem; margin-bottom: 1rem; }
.overlay-desc { font-size: 0.82rem; line-height: 1.7; margin-bottom: 1.5rem; color: var(--white); }
.overlay-hint { font-size: 0.7rem; color: var(--gray); margin-top: 0.75rem; }

.overlay-inner h2 {
  font-family: var(--display);
  font-size: 2.5rem;
  color: var(--red);
  margin-bottom: 1rem;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.result-highlight { grid-column: 1 / -1; }
.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
}
.result-label { display: block; font-size: 0.6rem; color: var(--gray); margin-bottom: 0.2rem; }
.result-val { display: block; font-family: var(--display); font-size: 1.6rem; }

.reward-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 0.5rem;
}
.reward-done { margin-bottom: 0.75rem; }
.reward-ok { color: var(--green); font-size: 0.85rem; margin-bottom: 0.4rem; }
.tx-link { font-size: 0.7rem; color: var(--yellow); text-decoration: none; }
.tx-link:hover { text-decoration: underline; }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Info Panel ──────────────────────────────────────────────────────────────── */
.info-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.info-card h3 {
  font-size: 0.65rem;
  color: var(--yellow);
  letter-spacing: 0.12em;
  margin-bottom: 0.6rem;
  text-transform: uppercase;
}
.token-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  margin-bottom: 0.35rem;
}
.token-label { color: var(--gray); }
.token-val { color: var(--white); font-weight: 600; }
.vestige-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.65rem;
  color: var(--yellow);
  text-decoration: none;
}
.vestige-link:hover { text-decoration: underline; }

.element-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  margin-bottom: 0.35rem;
}
.el-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.algo-card { border-color: rgba(255,255,255,0.08); }
.house-note { font-size: 0.65rem; color: var(--gray); margin-bottom: 0.5rem; line-height: 1.5; }
.house-addr {
  font-size: 0.6rem;
  color: var(--yellow);
  word-break: break-all;
  line-height: 1.4;
}

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 0.65rem 1.5rem;
  border-radius: 50px;
  font-size: 0.8rem;
  z-index: 999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .scoreboard { flex-direction: row; flex-wrap: wrap; }
  .score-card { flex: 1 1 120px; }
  .rules-box { flex: 1 1 100%; }
  .info-panel { flex-direction: row; flex-wrap: wrap; }
  .info-card { flex: 1 1 180px; }
  .canvas-wrapper { margin: 0 auto; }
  #pinball-canvas { width: 100%; height: auto; max-width: 420px; }
}

/* ── In-canvas Game Controls (mobile overlay at bottom of canvas) ────────────── */
.game-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  gap: 0;
  background: rgba(10,10,10,0.82);
  border-top: 2px solid var(--yellow);
  backdrop-filter: blur(4px);
}
.game-controls.hidden { display: none; }

.ctrl-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.6rem 0.25rem;
  background: transparent;
  border: none;
  border-right: 1px solid rgba(255,255,255,0.08);
  color: var(--white);
  font-family: var(--mono);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:last-child { border-right: none; }
.ctrl-btn:active, .ctrl-btn.pressed {
  background: var(--yellow);
  color: var(--black);
}
.ctrl-icon { font-size: 1.3rem; line-height: 1; }
.ctrl-label { font-size: 0.55rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; }
.ctrl-launch-btn {
  border-left: 1px solid rgba(245,216,0,0.3);
  border-right: 1px solid rgba(245,216,0,0.3);
  background: rgba(245,216,0,0.08);
}
.ctrl-launch-btn:active, .ctrl-launch-btn.pressed { background: var(--yellow); color: var(--black); }

@media (max-width: 900px) {
  .main-layout { padding: 0.5rem; gap: 0.5rem; }
}

/* ── Hits card ───────────────────────────────────────────────────────────────── */
.hits-card { border-color: rgba(107, 203, 119, 0.3); }

/* ── Fullscreen Button ───────────────────────────────────────────────────────── */
.btn-fs {
  display: none; /* shown only on mobile via JS */
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--white);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-fs:hover, .btn-fs.fs-active {
  background: var(--yellow);
  color: var(--black);
  border-color: var(--yellow);
}

/* ── True Fullscreen styles ──────────────────────────────────────────────────── */
:fullscreen body,
:-webkit-full-screen body,
:-moz-full-screen body,
:-ms-fullscreen body {
  background: var(--black);
  overflow: hidden;
}

:fullscreen .site-header,
:-webkit-full-screen .site-header,
:-moz-full-screen .site-header,
:-ms-fullscreen .site-header {
  display: none;
}

:fullscreen .main-layout,
:-webkit-full-screen .main-layout,
:-moz-full-screen .main-layout,
:-ms-fullscreen .main-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 0;
  gap: 0;
  max-width: 100vw;
}

:fullscreen .scoreboard,
:fullscreen .info-panel,
:-webkit-full-screen .scoreboard,
:-webkit-full-screen .info-panel,
:-moz-full-screen .scoreboard,
:-moz-full-screen .info-panel {
  display: none;
}

:fullscreen .game-section,
:-webkit-full-screen .game-section,
:-moz-full-screen .game-section,
:-ms-fullscreen .game-section {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100dvh;
}

:fullscreen .canvas-wrapper,
:-webkit-full-screen .canvas-wrapper,
:-moz-full-screen .canvas-wrapper,
:-ms-fullscreen .canvas-wrapper {
  border-radius: 0;
  border: none;
  box-shadow: none;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

:fullscreen #pinball-canvas,
:-webkit-full-screen #pinball-canvas,
:-moz-full-screen #pinball-canvas,
:-ms-fullscreen #pinball-canvas {
  width: auto !important;
  height: 100dvh !important;
  max-height: 100dvh;
  max-width: 100vw;
  object-fit: contain;
}

/* Fullscreen HUD overlay (score shown inside canvas area) */
:fullscreen .fs-hud,
:-webkit-full-screen .fs-hud {
  display: flex !important;
}

/* ── iOS pseudo-fullscreen ───────────────────────────────────────────────────── */
html.ios-fs .site-header { display: none; }
html.ios-fs .scoreboard  { display: none; }
html.ios-fs .info-panel  { display: none; }
html.ios-fs .main-layout {
  padding: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.ios-fs .game-section { width: 100vw; }
html.ios-fs .canvas-wrapper { border-radius: 0; border: none; box-shadow: none; }
html.ios-fs #pinball-canvas { width: 100vw !important; height: auto !important; }

/* ── Safe area insets for notched phones ─────────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  :fullscreen .game-section,
  :-webkit-full-screen .game-section {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Leaderboard ─────────────────────────────────────────────────────────────── */
.leaderboard-card { padding: 0.85rem 0.75rem 0.6rem; }
.leaderboard-card h3 { margin-bottom: 0.5rem; }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.65rem;
  table-layout: fixed;
}
.lb-table th {
  color: var(--gray);
  font-weight: 600;
  text-align: left;
  padding: 0.2rem 0.25rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.lb-table th:first-child { width: 20px; }
.lb-table th:nth-child(2) { width: auto; }
.lb-table th:nth-child(3) { width: 58px; text-align: right; }
.lb-table th:nth-child(4) { width: 48px; text-align: right; }

.lb-table td {
  padding: 0.28rem 0.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-table td:nth-child(3),
.lb-table td:nth-child(4) { text-align: right; }

.lb-table tbody tr:hover { background: rgba(255,255,255,0.03); }

/* Rank badges */
.lb-rank { font-weight: 700; }
.lb-rank-1 { color: #ffd700; }
.lb-rank-2 { color: #c0c0c0; }
.lb-rank-3 { color: #cd7f32; }
.lb-rank-other { color: var(--gray); }

.lb-wallet { color: var(--yellow); font-family: var(--mono); }
.lb-wallet.lb-me { color: #4ade80; } /* highlight own address */

.lb-score { color: var(--white); font-weight: 600; }
.lb-tiny  { color: var(--yellow); }

.lb-empty {
  text-align: center;
  color: var(--gray);
  padding: 1rem 0;
  font-size: 0.7rem;
}

.btn-lb-refresh {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.35rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--gray);
  font-family: var(--mono);
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-lb-refresh:hover { border-color: var(--yellow); color: var(--yellow); }
.btn-lb-refresh.spinning { animation: spin 0.6s linear infinite; }
