/* ============================================================
   Impossipool — styles
   Dark, glassy arcade-lounge UI. All layout is viewport-based so
   it scales from phones to desktops. Touch targets >= 44px.
   ============================================================ */

:root {
  --bg: #0a0c12;
  --panel: rgba(16, 20, 30, 0.82);
  --panel-border: rgba(120, 200, 255, 0.18);
  --text: #e8eef6;
  --dim: #93a1b5;
  --accent: #38d9a9;
  --accent-2: #4dabf7;
  --danger: #ff6b6b;
  --gold: #ffd43b;
  --solid: #ffa94d;
  --stripe: #74c0fc;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; background: radial-gradient(ellipse at 50% 35%, #131a28 0%, #07080d 75%);
}
.load-ball {
  width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff 0 18%, #111 60%);
  animation: roll 1.1s linear infinite;
  box-shadow: 0 8px 24px rgba(0,0,0,.7);
}
@keyframes roll { to { transform: rotate(360deg); } }
#loading-text { color: var(--dim); letter-spacing: .18em; text-transform: uppercase; font-size: 12px; }

#fatal {
  position: fixed; inset: 0; z-index: 101;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center; background: #0a0c12;
}
#fatal h2 { color: var(--danger); }
#fatal p { color: var(--dim); max-width: 460px; line-height: 1.5; }

/* ---------- Overlays / menu cards ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 12, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}
.menu-card {
  width: min(560px, 100%);
  max-height: 96vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 36px);
  text-align: center;
}
.menu-card.small { width: min(420px, 100%); }
.menu-card h2 { margin-bottom: 18px; letter-spacing: .06em; }

.title {
  font-size: clamp(34px, 8vw, 58px);
  font-weight: 800;
  letter-spacing: .06em;
  background: linear-gradient(120deg, #e8fff6, var(--accent) 45%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 18px rgba(56, 217, 169, .35));
}
.title span { font-weight: 300; }
.tagline { color: var(--dim); margin: 6px 0 22px; font-size: 14px; }

.menu-section { margin: 16px 0; }
.menu-label { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--dim); margin-bottom: 10px; }
.menu-sub { text-transform: none; letter-spacing: 0; opacity: .8; }

.seg-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.seg {
  flex: 1 1 0; min-width: 74px; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.seg small { color: var(--dim); font-size: 11px; font-weight: 400; }
.seg:hover { border-color: var(--accent); }
.seg.selected {
  background: linear-gradient(140deg, rgba(56,217,169,.25), rgba(77,171,247,.2));
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(56,217,169,.25);
}
.seg.selected small { color: var(--accent); }

.mode-buttons { display: flex; flex-direction: column; gap: 10px; }

.btn {
  min-height: 46px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font-size: 15px; font-weight: 600; letter-spacing: .03em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-icon { width: 20px; height: 20px; color: currentColor; flex-shrink: 0; }
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.11); }
.btn:active { transform: translateY(1px); }
.btn.big { min-height: 56px; font-size: 17px; width: 100%; }
.btn.primary {
  background: linear-gradient(135deg, #1d8f6c, #1668a8);
  border-color: rgba(120, 255, 210, .35);
  box-shadow: 0 6px 22px rgba(30, 150, 120, .35);
}
.btn.primary:hover { box-shadow: 0 8px 28px rgba(30, 170, 130, .5); }

.row-2 { display: flex; gap: 10px; }
.row-2 .btn { flex: 1; }

.rules-blurb {
  margin-top: 18px; font-size: 12.5px; line-height: 1.55; color: var(--dim);
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px;
}
.rules-blurb b { color: var(--gold); }

/* ---------- Settings ---------- */
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin: 14px 0; font-size: 14px; color: var(--text); text-align: left;
}
.set-row input[type="range"] { flex: 1; max-width: 180px; accent-color: var(--accent); height: 30px; }
.set-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.set-row select {
  background: #141a26; color: var(--text); border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px; padding: 8px 10px; font-size: 14px;
}
#settings-close { width: 100%; margin-top: 12px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud > * { pointer-events: auto; }

#hud-top {
  position: absolute; top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 12px; gap: 8px;
  pointer-events: none;
}
.player-card {
  min-width: 118px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  transition: box-shadow .25s ease, border-color .25s ease, transform .25s ease;
}
.player-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 22px rgba(56,217,169,.4);
  transform: translateY(2px);
}
.player-card.flipping { animation: cardflip .6s ease; }
@keyframes cardflip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); filter: brightness(2); }
  100% { transform: rotateX(0); }
}
.pc-name { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.pc-group { margin: 5px 0 4px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 800; letter-spacing: .1em;
}
.badge.open   { background: rgba(255,255,255,.12); color: var(--dim); }
.badge.solid  { background: rgba(255,169,77,.2); color: var(--solid); border: 1px solid rgba(255,169,77,.5); }
.badge.stripe { background: rgba(116,192,252,.16); color: var(--stripe); border: 1px solid rgba(116,192,252,.5); }
.badge.eight  { background: rgba(255,212,59,.15); color: var(--gold); border: 1px solid rgba(255,212,59,.55); }
.pc-balls { display: flex; justify-content: center; gap: 3px; min-height: 10px; }
.pc-balls i {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
}
.pc-balls i.solid { background: var(--solid); }
.pc-balls i.stripe {
  background: linear-gradient(180deg, #fff 0 25%, var(--stripe) 25% 75%, #fff 75%);
}

#hud-center { text-align: center; padding-top: 2px; }
#turn-label {
  font-size: clamp(13px, 2.6vw, 17px); font-weight: 800; letter-spacing: .06em;
  text-shadow: 0 2px 10px rgba(0,0,0,.8);
}
#diff-label { font-size: 11px; color: var(--dim); letter-spacing: .14em; text-transform: uppercase; margin-top: 2px; }
#fate-risk { font-size: 11px; color: var(--gold); margin-top: 2px; letter-spacing: .05em; }

#hud-buttons {
  position: absolute; left: 10px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 8px;
}
.hud-btn {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-border);
  color: var(--text); cursor: pointer;
  transition: transform .12s ease;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.hud-btn:active { transform: scale(.92); }
.hud-icon { width: 22px; height: 22px; color: currentColor; }

/* Power bar */
#power-wrap {
  position: absolute; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  touch-action: none;
}
#power-track {
  width: 34px; height: min(38vh, 260px);
  border-radius: 20px;
  background: rgba(10, 14, 22, .8);
  border: 1px solid var(--panel-border);
  overflow: hidden; position: relative;
  cursor: pointer;
}
#power-fill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 0%;
  background: linear-gradient(180deg, #ff6b6b, #ffd43b 45%, #38d9a9);
  border-radius: 0 0 20px 20px;
  transition: height .04s linear;
}
#power-hint { font-size: 9px; letter-spacing: .22em; color: var(--dim); }

#hint {
  position: absolute; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  font-size: 11.5px; color: var(--dim);
  background: rgba(10,14,22,.6); padding: 6px 14px; border-radius: 20px;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}

/* Toast messages */
#toast {
  position: absolute; top: 86px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--panel-border);
  padding: 10px 22px; border-radius: 24px;
  font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow);
  animation: toastin .25s ease;
  max-width: 90vw;
  z-index: 30;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, -8px); } }

/* Fate flip banner */
#fate-banner {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(255,212,59,.16), rgba(160,40,220,.22) 60%, rgba(5,6,10,.55));
  animation: fatebg 3s ease forwards;
  pointer-events: none;
}
@keyframes fatebg { 0% { opacity: 0; } 12% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.fate-inner { text-align: center; animation: fatepop 3s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes fatepop {
  0% { transform: scale(.3) rotate(-8deg); opacity: 0; }
  14% { transform: scale(1.12) rotate(2deg); opacity: 1; }
  22% { transform: scale(1) rotate(0); }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0; }
}
.fate-title {
  font-size: clamp(38px, 10vw, 84px); font-weight: 900; letter-spacing: .04em;
  background: linear-gradient(120deg, #ffd43b, #ff6b6b 50%, #b197fc);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(255, 210, 60, .65));
}
.fate-sub {
  font-size: clamp(15px, 4vw, 24px); font-weight: 700; color: #fff;
  text-shadow: 0 2px 16px rgba(0,0,0,.8); margin-top: 6px;
}

/* End screen */
#end-title { font-size: clamp(28px, 7vw, 48px); margin-bottom: 8px; color: var(--gold); text-shadow: 0 0 30px rgba(255,212,59,.4); }
#end-sub { color: var(--dim); margin-bottom: 22px; font-size: 15px; }

/* Compact layout for small screens */
@media (max-width: 640px) {
  .player-card { min-width: 96px; padding: 6px 8px; }
  .pc-name { font-size: 10px; }
  #hint { display: none; }
  .hud-btn { width: 42px; height: 42px; }
}
@media (max-height: 480px) {
  #power-track { height: 44vh; }
  #hud-top { padding: 6px 8px; }
}
