/* style.css - Premium theme design system with Glassmorphism and dynamic custom skins */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;700&family=Inter:wght@400;600;800&family=Space+Grotesk:wght@500;700;800&display=swap');

:root {
  /* Theme default: Classic Slate */
  --ink: #0B0E12;
  --paper: #E7ECEA;
  --dim: #7E8A94;
  --gold: #F2C14E;
  --volt: #37E1C4;
  --risk: #E0653F;
  --grid-bg: #11161c;
  --cell-bg: #182028;
  --btn-border: #23303a;
  --card-bg: linear-gradient(180deg, #12171d, #0d1116);
  --header-font: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --body-font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono-font: 'Fira Code', ui-monospace, monospace;
}

/* Cyberpunk Skin */
body.skin-cyberpunk {
  --ink: #05000a;
  --paper: #00ffcc;
  --dim: #bc00dd;
  --gold: #ffff00;
  --volt: #00ffff;
  --risk: #ff0055;
  --grid-bg: #110022;
  --cell-bg: #22003d;
  --btn-border: #ff0055;
  --card-bg: linear-gradient(180deg, #1f0035, #0a0015);
}

/* Cozy Wood Skin */
body.skin-wood {
  --ink: #2b1f14;
  --paper: #f7ecd8;
  --dim: #8b6b4f;
  --gold: #d4a373;
  --volt: #4f772d;
  --risk: #bc4749;
  --grid-bg: #3f2f21;
  --cell-bg: #4a3b2c;
  --btn-border: #8b6b4f;
  --card-bg: linear-gradient(180deg, #3d2d1e, #2b1f14);
}

/* Dark Void Skin */
body.skin-void {
  --ink: #020208;
  --paper: #e2e2ff;
  --dim: #5c5c99;
  --gold: #b39ddb;
  --volt: #64ffda;
  --risk: #ff5252;
  --grid-bg: #0b0c16;
  --cell-bg: #121528;
  --btn-border: #2c2e43;
  --card-bg: linear-gradient(180deg, #101226, #020208);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* Avoid overlap issues on iOS dynamic URL bar */
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--body-font);
  user-select: none;
  touch-action: none;
  transition: background-color 0.4s ease, color 0.4s ease;
}

#wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 14px;
  position: relative;
}

.row {
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#hud {
  margin-bottom: 6px;
  align-items: baseline;
}

.brand {
  font-family: var(--header-font);
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -.02em;
}

.brand b {
  color: var(--volt);
  text-shadow: 0 0 10px rgba(55, 225, 196, 0.3);
}

.scores {
  display: flex;
  gap: 16px;
  text-align: right;
  align-items: baseline;
}

.sc {
  display: flex;
  flex-direction: column;
}

.sc .lab {
  font-family: var(--mono-font);
  font-size: 8px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}

.sc .val {
  font-family: var(--mono-font);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
  color: var(--paper);
}

.iconbtn {
  background: rgba(35, 48, 58, 0.2);
  border: 1px solid var(--btn-border);
  color: var(--dim);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
  font-family: var(--mono-font);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(4px);
}

.iconbtn:active {
  transform: scale(0.95);
  background: var(--btn-border);
  color: var(--paper);
}

#subbar {
  margin-bottom: 8px;
  font-size: 11px;
  font-family: var(--mono-font);
}

#daylabel {
  color: var(--volt);
  letter-spacing: .06em;
  font-weight: 700;
}

#remain {
  color: var(--gold);
  margin-left: 8px;
  font-weight: 700;
}

.nextwrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .1em;
}

.chip {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  color: #0B0E12;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  transition: background-color 0.2s;
}

.chip.nx {
  width: 18px;
  height: 18px;
  font-size: 10px;
  opacity: .75;
}

canvas {
  border-radius: 16px;
  touch-action: none;
  display: block;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), inset 0 0 1px rgba(255,255,255,0.1);
  transition: border-color 0.3s;
}

#chargewrap {
  width: 100%;
  max-width: 440px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#chargelab {
  font-family: var(--mono-font);
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--dim);
}

#chargebar {
  flex: 1;
  height: 6px;
  border-radius: 6px;
  background: var(--cell-bg);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
  overflow: hidden;
}

#chargefill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--cell-bg), var(--volt));
  box-shadow: 0 0 8px var(--volt);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#controls {
  width: 100%;
  max-width: 440px;
  margin-top: 8px;
  min-height: 64px;
}

.hint {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.5;
}

.hint b {
  color: var(--paper);
  font-weight: 600;
}

#buildCtl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#undo {
  border-color: rgba(188, 71, 73, 0.4);
  color: var(--paper);
}

#primeCtl {
  display: none;
}

#primeCtl .call {
  font-family: var(--mono-font);
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  margin-bottom: 6px;
}

#primeCtl .call b {
  color: var(--gold);
}

#primeCtl .stakes {
  font-family: var(--mono-font);
  font-size: 10px;
  text-align: center;
  color: var(--dim);
  margin-bottom: 4px;
}

#primeCtl .stakes b {
  color: var(--risk);
}

input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--gold) 0 var(--bpfill,0%), var(--btn-border) var(--bpfill,0%) 100%);
  outline: none;
  margin: 2px 0 6px;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--gold);
  box-shadow: 0 0 10px rgba(242, 193, 78, 0.4);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:active {
  transform: scale(1.15);
}

input[type=range]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--gold);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type=range]::-moz-range-thumb:active {
  transform: scale(1.15);
}

#firePrompt {
  text-align: center;
  color: var(--volt);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .02em;
  animation: pulse 1.3s ease-in-out infinite;
}

#firePrompt.after {
  color: var(--gold);
}

@keyframes pulse {
  0%, 100% { opacity: .55; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.02); }
}

/* Modals & Dialog overlays */
#over, #intro, .modal-panel {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 9, 13, 0.74);
  backdrop-filter: blur(10px);
  z-index: 10;
  animation: fadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#card, .modal-card {
  width: calc(100% - 48px);
  max-width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--btn-border);
  border-radius: 20px;
  padding: 24px 22px;
  text-align: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
  transform: scale(0.9);
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-family: var(--header-font);
  font-weight: 800;
  font-size: 26px;
  margin-bottom: 12px;
}

.modal-desc {
  color: var(--dim);
  font-size: 13.5px;
  line-height: 1.6;
  margin-bottom: 20px;
}

#card .k, .modal-card .k {
  font-family: var(--mono-font);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}

#card .big {
  font-weight: 800;
  font-size: 52px;
  line-height: 1.05;
  margin: 6px 0 2px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-family: var(--header-font);
}

#card .line {
  color: var(--dim);
  font-size: 13px;
  margin-bottom: 6px;
}

#card .bp {
  font-family: var(--mono-font);
  font-size: 11px;
  margin-bottom: 14px;
}

#card .bp.hit { color: var(--volt); }
#card .bp.miss { color: var(--risk); }
#card .bp.off { color: var(--dim); }

#card .squares {
  font-size: 22px;
  letter-spacing: 3px;
  margin: 8px 0 16px;
}

.btns {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

#card button, .modal-card button {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-weight: 700;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

#card button:active, .modal-card button:active {
  transform: scale(0.97);
}

#replayBtn, .btn-primary {
  background: var(--volt);
  color: #04201b;
}

#copyBtn, .btn-secondary {
  background: var(--gold);
  color: #231803;
}

#againBtn, .btn-outline {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--btn-border);
}

#clipBtn, .btn-outline-volt {
  background: transparent;
  color: var(--volt);
  border: 1px solid rgba(55, 225, 196, 0.3);
}

#cardStats {
  border-top: 1px solid var(--btn-border);
  padding-top: 12px;
  margin-bottom: 14px;
  text-align: left;
}

#cardStats div {
  font-family: var(--mono-font);
  font-size: 11px;
}

#toast {
  height: 14px;
  margin-top: 10px;
  font-family: var(--mono-font);
  font-size: 11px;
  color: var(--gold);
  opacity: 0;
  transition: opacity .3s;
}

#toast.show {
  opacity: 1;
}

/* Custom skins / Shop Grid */
.theme-grid, .shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
  text-align: left;
}

.theme-card, .shop-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-card.active, .shop-card.purchased {
  border-color: var(--volt);
  background: rgba(55, 225, 196, 0.05);
}

.theme-name {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 4px;
}

.theme-preview {
  display: flex;
  gap: 4px;
}

.theme-preview span {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* Leaderboard details styling */
.leaderboard-list {
  max-height: 200px;
  overflow-y: auto;
  margin: 12px 0;
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  padding: 4px;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  font-family: var(--mono-font);
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.02);
}

.leaderboard-item:last-child {
  border-bottom: none;
}

.leaderboard-item.highlight {
  background: rgba(242, 193, 78, 0.1);
  color: var(--gold);
  border-radius: 6px;
}

.rank-badge {
  font-weight: 700;
  margin-right: 6px;
}

.leaderboard-item.highlight .rank-badge {
  color: var(--volt);
}

/* Scrollbar tuning */
.leaderboard-list::-webkit-scrollbar {
  width: 6px;
}
.leaderboard-list::-webkit-scrollbar-track {
  background: transparent;
}
.leaderboard-list::-webkit-scrollbar-thumb {
  background: var(--btn-border);
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
