:root {
  --bg: #07070d;
  --panel: #10121f;
  --panel2: #171a2c;
  --line: #262a46;
  --text: #e9ecff;
  --muted: #8a90b8;
  --accent: #2ee6d6;
  --hot: #ff3d6e;
  --gold: #ffd23f;
  --offense: #ff3d6e;
  --defense: #2ee6d6;
  --utility: #ffd23f;
  --radius: 14px;
  --display: 'Bungee', 'Impact', system-ui, sans-serif;
  --ui: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #1a1440 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #0c2a33 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

/* ---------- shared screen layout ---------- */
.screen { min-height: 100dvh; }
#home, #lobby {
  display: flex;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.col { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 16px; }
.col.wide { max-width: 640px; }
h2 { font-family: var(--display); font-weight: 400; font-size: 0.95rem; letter-spacing: 0.04em; margin: 0 0 10px; }

.logo {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3rem, 15vw, 4.6rem);
  line-height: 0.9;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  letter-spacing: 0.02em;
}
.logo span:first-child { color: var(--accent); text-shadow: 0 0 24px rgba(46, 230, 214, 0.45); }
.logo span:last-child { color: var(--hot); text-shadow: 0 0 24px rgba(255, 61, 110, 0.45); margin-left: 0.6em; }
.tagline { margin: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.45; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1.05rem;
  outline: none;
  min-width: 0;
}
input:focus { border-color: var(--accent); }

.btn {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.btn:hover { border-color: #3c4270; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--hot), #ff7a3d);
  border: none;
  color: #12030a;
  box-shadow: 0 6px 24px rgba(255, 61, 110, 0.3);
}
.btn.big { font-family: var(--display); font-weight: 400; font-size: 1.15rem; padding: 16px; letter-spacing: 0.03em; }
.btn.small { padding: 8px 12px; font-size: 0.85rem; }
.btn.ghost { background: transparent; }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--display); text-align: center; }

#room-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#room-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 8px 8px 14px;
}
#room-list b { font-family: var(--display); font-weight: 400; letter-spacing: 0.1em; }

.how ul { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.5; display: flex; flex-direction: column; gap: 6px; }
.how b { color: var(--text); }

/* ---------- lobby ---------- */
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.code-box { display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; }
.code-box strong { font-family: var(--display); font-weight: 400; font-size: 2rem; letter-spacing: 0.18em; color: var(--gold); line-height: 1.1; }
.slots { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slots li {
  display: flex; align-items: center; gap: 10px; min-height: 48px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  overflow: hidden;
}
.slots li.empty { border-style: dashed; color: var(--muted); background: transparent; }
.slots .dot { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: 0 0 10px currentColor; background: currentColor; }
.slots .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.tag { font-size: 0.7rem; padding: 2px 6px; border-radius: 6px; background: var(--panel2); color: var(--muted); flex: none; }
.tag.you { color: var(--accent); }
.tag.host { color: var(--gold); }
.kick { border: none; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 6px; }
.row { display: flex; gap: 8px; margin-top: 10px; }

.settings { display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg button:disabled { cursor: default; }

.pool summary { cursor: pointer; font-family: var(--display); font-size: 0.95rem; padding: 6px 0; }
.pool summary .muted { font-family: var(--ui); font-size: 0.8rem; }
#pool { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
#pool li { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border-radius: 10px; padding: 10px; border-left: 3px solid var(--c); }
#pool .ic { font-size: 1.4rem; line-height: 1; }
#pool b { display: block; font-size: 0.9rem; }
#pool span { font-size: 0.8rem; color: var(--muted); }

/* ---------- game ---------- */
#game { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  font-size: 0.85rem; pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#game-code { font-family: var(--display); letter-spacing: 0.12em; }
#phase-info { flex: 1; text-align: center; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: rgba(16, 18, 31, 0.8);
  cursor: pointer; display: grid; place-items: center; font-size: 1rem; touch-action: manipulation;
}

#board {
  position: absolute; left: max(10px, env(safe-area-inset-left)); top: 56px;
  display: flex; flex-direction: column; gap: 6px; width: 230px; pointer-events: none;
}
.pl {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 8px;
  background: rgba(16, 18, 31, 0.78); border-radius: 10px; border-left: 3px solid var(--c);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.pl.out { opacity: 0.4; }
.pl.me { box-shadow: inset 0 0 0 1px var(--c); }
.pl .nm { font-weight: 700; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 96px; color: var(--c); }
.pl .lv { font-size: 0.8rem; white-space: nowrap; }
.pl .augs { font-size: 0.85rem; letter-spacing: 1px; margin-left: auto; text-align: right; overflow: hidden; }
.pl .augs i { font-style: normal; }
.pl .augs sub { font-size: 0.6rem; color: var(--muted); }

#center-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-family: var(--display); font-size: clamp(1.6rem, 7vw, 3.2rem); text-align: center; pointer-events: none;
  text-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 12px currentColor; white-space: nowrap;
}
#center-msg.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.5); opacity: 0; } }

#summary {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  background: rgba(16, 18, 31, 0.92); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; pointer-events: none;
  max-width: calc(100vw - 32px);
}
#summary div { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
#summary b { color: var(--c); max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

#spectating {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(16, 18, 31, 0.85); padding: 6px 14px; border-radius: 99px; font-size: 0.85rem; color: var(--muted); pointer-events: none;
}

#dash-btn {
  position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom));
  width: 76px; height: 76px; border-radius: 50%; border: 2px solid var(--gold); background: rgba(255, 210, 63, 0.15);
  font-size: 2rem; touch-action: manipulation; box-shadow: 0 0 24px rgba(255, 210, 63, 0.35);
}
#dash-btn.cool { opacity: 0.35; box-shadow: none; }

.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 5, 12, 0.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.draft-inner { width: 100%; max-width: 860px; display: flex; flex-direction: column; gap: 14px; margin: auto; }
.draft-title { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
#draft-round { font-family: var(--display); font-size: clamp(1.4rem, 5vw, 2rem); color: var(--gold); }
.timer { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; }
#draft-timer { height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), var(--hot)); transform-origin: left; }
#cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card {
  position: relative; text-align: left; cursor: pointer;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 2px solid var(--line); border-radius: 18px; padding: 20px 18px 18px;
  display: flex; flex-direction: column; gap: 8px; min-height: 230px;
  transition: transform 0.12s, border-color 0.12s, opacity 0.2s, box-shadow 0.12s;
  touch-action: manipulation;
}
.card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; border-radius: 16px 16px 0 0; background: var(--c);
}
.card:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--c); box-shadow: 0 10px 30px -10px var(--c); }
.card .ic { font-size: 3rem; line-height: 1.1; }
.card .nm { font-family: var(--display); font-size: 1.15rem; }
.card .cat { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--c); font-weight: 700; }
.card .ds { color: var(--muted); font-size: 0.95rem; line-height: 1.4; }
.card .own { margin-top: auto; font-size: 0.8rem; color: var(--gold); }
.card .key { position: absolute; top: 12px; right: 14px; font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.card.picked { border-color: var(--c); box-shadow: 0 0 0 3px var(--c), 0 10px 40px -10px var(--c); transform: translateY(-4px); }
.card.dim { opacity: 0.35; }
.card:disabled { cursor: default; }
#draft-status { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 0.85rem; }
#draft-status span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
#draft-status i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--c); display: inline-block; }
#draft-status .done i { background: var(--c); }
#draft-status .done { color: var(--text); }

.over-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; max-width: 420px; margin: auto; }
#winner { font-family: var(--display); font-size: clamp(2rem, 10vw, 3.4rem); text-shadow: 0 0 30px currentColor; word-break: break-word; }
#over-augs { font-size: 1.6rem; letter-spacing: 4px; }
#lost-msg { font-family: var(--display); font-size: 1.5rem; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem;
  max-width: calc(100vw - 32px);
}

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  #board {
    left: 0; right: 0; top: calc(max(8px, env(safe-area-inset-top)) + 44px); width: auto;
    flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 0 8px;
  }
  .pl { padding: 3px 7px 3px 6px; gap: 5px; border-radius: 8px; }
  .pl .nm { max-width: 64px; font-size: 0.75rem; }
  .pl .lv { font-size: 0.72rem; }
  .pl .augs { font-size: 0.72rem; letter-spacing: 0; }
  #cards { grid-template-columns: 1fr; gap: 10px; }
  .card { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 14px 14px 12px; gap: 4px 12px; border-radius: 14px; }
  .card .ic { font-size: 2.2rem; flex: none; width: 48px; text-align: center; }
  .card .head { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
  .card .ds { flex-basis: 100%; font-size: 0.9rem; }
  .card .own { margin: 0; }
  .card .key { display: none; }
  .card:hover:not(:disabled) { transform: none; }
}
@media (min-width: 861px) {
  .card .head { display: contents; }
}
@media (max-width: 420px) {
  .slots { grid-template-columns: 1fr; }
}
