:root {
  --bg: #070812;
  --panel: rgba(18, 20, 39, 0.88);
  --panel-2: rgba(28, 31, 57, 0.82);
  --line: rgba(255, 255, 255, 0.11);
  --text: #f8f7ff;
  --muted: #a8a7bd;
  --cyan: #40e0ff;
  --pink: #ff4fb8;
  --gold: #ffd166;
  --green: #51e59b;
  --danger: #ff667d;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 5%, rgba(64, 224, 255, 0.12), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(255, 79, 184, 0.12), transparent 30%),
    linear-gradient(145deg, #070812, #0d1020 55%, #090b16);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Overlay */
.overlay-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.overlay-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  color: #070812;
  font-size: 24px;
  box-shadow: 0 12px 36px rgba(64, 224, 255, 0.2);
}

.brand h1 {
  margin: 0;
  font-size: clamp(18px, 3vw, 28px);
  letter-spacing: -0.03em;
}
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.live-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 10, 20, 0.75);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.live-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #72758b; }
.live-pill.online .dot { background: var(--green); box-shadow: 0 0 14px var(--green); }
.live-pill.connecting .dot { background: var(--gold); animation: pulse 1s infinite; }
.live-pill.error .dot { background: var(--danger); }

.overlay-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
}

.game-stage,
.event-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.game-stage {
  position: relative;
  min-height: 650px;
  overflow: hidden;
  border-radius: 28px;
}

.game-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 95%);
  pointer-events: none;
}

.game-root { position: relative; z-index: 1; min-height: 650px; }

.event-panel {
  border-radius: 24px;
  padding: 16px;
  min-height: 650px;
  display: flex;
  flex-direction: column;
}
.event-panel h2 { margin: 0 0 5px; font-size: 16px; }
.event-panel .caption { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.event-feed { display: flex; flex-direction: column; gap: 8px; overflow: hidden; flex: 1; }
.event-card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255,255,255,0.035);
  animation: slideIn .25s ease;
}
.event-card strong { display: block; font-size: 12px; margin-bottom: 3px; }
.event-card span { color: var(--muted); font-size: 12px; line-height: 1.35; word-break: break-word; }
.event-card.gift { border-color: rgba(255, 209, 102, 0.25); }
.event-card.gift strong { color: var(--gold); }
.event-card.comment strong { color: var(--cyan); }

.game-wrap {
  min-height: 650px;
  padding: 26px;
  display: flex;
  flex-direction: column;
}
.game-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.game-heading h2 { margin: 0; font-size: clamp(24px, 4vw, 42px); letter-spacing: -0.04em; }
.game-heading p { margin: 7px 0 0; color: var(--muted); }
.score-box { display: flex; gap: 8px; }
.score-chip {
  min-width: 84px;
  text-align: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.045);
}
.score-chip small { display:block; color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.1em; }
.score-chip b { font-size:22px; }
.game-center { flex: 1; display: grid; place-items: center; padding: 24px 0; }
.game-help {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.game-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 12, 0.68);
  backdrop-filter: blur(7px);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.game-message.show { opacity: 1; }
.game-message-card {
  text-align: center;
  padding: 24px 30px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: #15182d;
  transform: scale(.9);
  transition: transform .2s;
}
.game-message.show .game-message-card { transform: scale(1); }
.game-message-card strong { display:block; font-size:32px; margin-bottom:6px; }
.game-message-card span { color:var(--muted); }

/* Tic tac toe */
.ttt-board { width: min(470px, 82vw); aspect-ratio:1; display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.ttt-cell {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px;
  display:grid;
  place-items:center;
  background: linear-gradient(145deg, rgba(255,255,255,.075), rgba(255,255,255,.025));
  font-size: clamp(52px, 9vw, 94px);
  font-weight: 900;
  color: var(--cyan);
  box-shadow: inset 0 1px rgba(255,255,255,.08);
  position:relative;
  transition: transform .15s, border-color .15s;
}
.ttt-cell::after { content: attr(data-index); position:absolute; right:10px; bottom:8px; color:rgba(255,255,255,.18); font-size:12px; }
.ttt-cell.o { color:var(--pink); }
.ttt-cell.pop { animation: cellPop .35s ease; }
.ttt-cell.win { border-color:var(--gold); box-shadow:0 0 30px rgba(255,209,102,.28); }
.turn-badge { margin-top:14px; padding:9px 15px; border-radius:999px; background:rgba(255,255,255,.05); color:var(--muted); }
.turn-badge b { color:var(--text); }

/* Race */
.race-board { width:100%; max-width:760px; display:flex; flex-direction:column; gap:24px; }
.race-track { position:relative; height:130px; border:1px solid var(--line); border-radius:24px; background:rgba(255,255,255,.035); overflow:hidden; }
.race-track::after { content:"🏁"; position:absolute; right:16px; top:50%; transform:translateY(-50%); font-size:42px; }
.race-label { position:absolute; left:16px; top:12px; color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.14em; }
.racer { position:absolute; left:18px; bottom:20px; transform:translateX(0); transition:left .35s cubic-bezier(.2,.8,.2,1); font-size:56px; filter:drop-shadow(0 12px 14px rgba(0,0,0,.35)); }
.race-progress { position:absolute; left:0; bottom:0; height:6px; width:0; transition:width .35s; }
.race-progress.blue { background:var(--cyan); }
.race-progress.pink { background:var(--pink); }

/* Tower */
.tower-arena { width:min(680px, 100%); height:470px; border:1px solid var(--line); border-radius:26px; position:relative; overflow:hidden; background:linear-gradient(to bottom,#111933,#0b0d1b); }
.tower-arena::before { content:""; position:absolute; inset:0; background:radial-gradient(circle at 50% 20%, rgba(64,224,255,.12), transparent 50%); }
.tower-block { position:absolute; height:32px; border-radius:7px; background:linear-gradient(90deg,var(--cyan),#758bff); box-shadow:0 8px 20px rgba(64,224,255,.2); }
.tower-block.fixed:nth-child(odd) { background:linear-gradient(90deg,var(--pink),#8f6cff); }
.tower-ground { position:absolute; left:0; right:0; bottom:0; height:18px; background:rgba(255,255,255,.13); }
.tower-stats { display:flex; gap:12px; margin-top:12px; justify-content:center; color:var(--muted); }

/* Treasure */
.chest-grid { width:min(600px, 100%); display:grid; grid-template-columns:repeat(3,1fr); gap:14px; }
.chest { aspect-ratio:1.15; border:1px solid var(--line); border-radius:20px; display:grid; place-items:center; background:linear-gradient(145deg,rgba(255,209,102,.12),rgba(255,255,255,.03)); position:relative; overflow:hidden; }
.chest .icon { font-size:48px; transition:transform .35s; }
.chest .number { position:absolute; top:9px; right:11px; color:rgba(255,255,255,.32); font-weight:800; }
.chest.open .icon { transform:scale(1.35) rotate(-5deg); }
.chest.hint { border-color:var(--gold); box-shadow:0 0 28px rgba(255,209,102,.25); }
.treasure-lives { font-size:20px; letter-spacing:5px; }

/* Battle */
.battle-stage { width:100%; max-width:780px; display:grid; grid-template-columns:1fr 80px 1fr; align-items:center; gap:14px; }
.monster-card { border:1px solid var(--line); border-radius:26px; padding:22px; background:rgba(255,255,255,.04); text-align:center; position:relative; overflow:hidden; }
.monster-card.fire { box-shadow:inset 0 0 50px rgba(255,94,91,.07); }
.monster-card.ice { box-shadow:inset 0 0 50px rgba(64,224,255,.07); }
.monster { font-size:88px; display:block; filter:drop-shadow(0 16px 20px rgba(0,0,0,.35)); transition:transform .2s; }
.monster.hit { animation:hit .32s ease; }
.monster-card h3 { margin:8px 0; }
.health { height:16px; border-radius:999px; background:rgba(255,255,255,.09); overflow:hidden; }
.health > div { height:100%; width:100%; transition:width .3s; }
.fire .health > div { background:linear-gradient(90deg,#ff765e,#ff3f83); }
.ice .health > div { background:linear-gradient(90deg,#40e0ff,#637bff); }
.hp-text { margin-top:7px; color:var(--muted); font-size:12px; }
.versus { text-align:center; font-weight:900; font-size:28px; color:var(--gold); }

/* Admin */
.admin-shell { width:min(1280px, calc(100% - 28px)); margin:0 auto; padding:24px 0 46px; }
.admin-header { display:flex; justify-content:space-between; align-items:center; gap:18px; margin-bottom:20px; }
.admin-header h1 { margin:0; font-size:clamp(26px,4vw,42px); letter-spacing:-.04em; }
.admin-header p { margin:6px 0 0; color:var(--muted); }
.admin-actions { display:flex; flex-wrap:wrap; gap:8px; }
.admin-grid { display:grid; grid-template-columns:330px minmax(0,1fr); gap:16px; align-items:start; }
.admin-sidebar, .admin-main { display:flex; flex-direction:column; gap:16px; }
.card { border:1px solid var(--line); border-radius:22px; background:var(--panel); box-shadow:var(--shadow); padding:18px; }
.card h2 { margin:0 0 4px; font-size:18px; }
.card .sub { color:var(--muted); font-size:12px; margin-bottom:14px; }
.field { display:flex; flex-direction:column; gap:6px; margin-bottom:12px; }
.field label { font-size:12px; color:var(--muted); }
.field input, .field select {
  width:100%; border:1px solid var(--line); border-radius:12px; padding:11px 12px; background:#0d1020; color:var(--text); outline:none;
}
.field input:focus, .field select:focus { border-color:rgba(64,224,255,.55); }
.checkbox-row { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 0; color:var(--muted); font-size:13px; }
.checkbox-row input { width:18px; height:18px; accent-color:var(--cyan); }
.btn { border:1px solid transparent; border-radius:12px; padding:10px 14px; background:linear-gradient(135deg,var(--cyan),#7b7cff); color:#060812; font-weight:800; }
.btn.secondary { background:rgba(255,255,255,.06); color:var(--text); border-color:var(--line); }
.btn.danger { background:rgba(255,102,125,.12); color:#ff91a4; border-color:rgba(255,102,125,.25); }
.btn.gold { background:linear-gradient(135deg,var(--gold),#ff9e62); }
.btn:disabled { opacity:.5; cursor:not-allowed; }
.btn-row { display:flex; gap:8px; flex-wrap:wrap; }
.status-panel { border-radius:16px; padding:12px; background:rgba(255,255,255,.04); border:1px solid var(--line); }
.status-line { display:flex; align-items:center; gap:8px; font-size:13px; }
.status-line .dot { width:9px; height:9px; border-radius:50%; background:#777a90; }
.status-line.online .dot { background:var(--green); box-shadow:0 0 12px var(--green); }
.status-line.connecting .dot { background:var(--gold); }
.status-line.error .dot { background:var(--danger); }
.status-detail { color:var(--muted); font-size:11px; margin:6px 0 0 17px; word-break:break-word; }
.game-selector { display:grid; grid-template-columns:repeat(5, minmax(130px,1fr)); gap:10px; }
.game-option { border:1px solid var(--line); border-radius:16px; background:rgba(255,255,255,.035); padding:14px; color:var(--text); text-align:left; min-height:112px; transition:.18s; }
.game-option:hover { transform:translateY(-2px); border-color:rgba(64,224,255,.35); }
.game-option.active { border-color:var(--cyan); background:rgba(64,224,255,.08); box-shadow:0 0 24px rgba(64,224,255,.12); }
.game-option .emoji { font-size:25px; }
.game-option strong { display:block; margin-top:8px; }
.game-option span { color:var(--muted); font-size:11px; line-height:1.3; display:block; margin-top:4px; }
.tabs { display:flex; gap:8px; margin-bottom:14px; }
.tab { border:1px solid var(--line); border-radius:999px; background:transparent; color:var(--muted); padding:8px 13px; }
.tab.active { color:#071018; background:var(--cyan); border-color:var(--cyan); font-weight:800; }
.rule-list { display:flex; flex-direction:column; gap:8px; }
.rule-row { display:grid; grid-template-columns:minmax(130px,1.1fr) minmax(160px,1.3fr) 90px 90px 42px; gap:8px; align-items:center; }
.rule-row input, .rule-row select { min-width:0; border:1px solid var(--line); border-radius:10px; padding:9px 10px; background:#0d1020; color:var(--text); }
.icon-btn { width:38px; height:38px; border-radius:10px; border:1px solid rgba(255,102,125,.24); background:rgba(255,102,125,.08); color:#ff91a4; }
.rule-head { display:grid; grid-template-columns:minmax(130px,1.1fr) minmax(160px,1.3fr) 90px 90px 42px; gap:8px; color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.08em; margin-bottom:6px; padding:0 3px; }
.sim-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.notice { border-radius:14px; padding:11px 12px; font-size:12px; line-height:1.4; background:rgba(255,209,102,.07); border:1px solid rgba(255,209,102,.18); color:#ffe7a5; }
.toast { position:fixed; right:20px; bottom:20px; z-index:100; padding:12px 16px; border-radius:13px; background:#20243f; border:1px solid var(--line); box-shadow:var(--shadow); opacity:0; transform:translateY(10px); pointer-events:none; transition:.22s; }
.toast.show { opacity:1; transform:translateY(0); }
.toast.error { border-color:rgba(255,102,125,.4); color:#ff9caf; }
.key-gate { min-height:100vh; display:grid; place-items:center; padding:20px; }
.key-card { width:min(430px,100%); border:1px solid var(--line); border-radius:24px; background:var(--panel); box-shadow:var(--shadow); padding:24px; }
.key-card h1 { margin:0 0 8px; }
.key-card p { color:var(--muted); line-height:1.5; }

@keyframes pulse { 50% { opacity:.35; transform:scale(.8); } }
@keyframes slideIn { from { opacity:0; transform:translateY(-8px); } }
@keyframes cellPop { 0% { transform:scale(.75); } 70% { transform:scale(1.08); } }
@keyframes hit { 25% { transform:translateX(-12px) rotate(-5deg); } 70% { transform:translateX(10px) rotate(4deg); } }

@media (max-width: 960px) {
  .overlay-grid, .admin-grid { grid-template-columns:1fr; }
  .event-panel { min-height:220px; max-height:300px; }
  .game-selector { grid-template-columns:repeat(2,1fr); }
}
@media (max-width: 660px) {
  .overlay-topbar, .admin-header { align-items:flex-start; flex-direction:column; }
  .game-stage, .game-root { min-height:590px; }
  .game-wrap { min-height:590px; padding:18px; }
  .game-heading { flex-direction:column; }
  .battle-stage { grid-template-columns:1fr; }
  .versus { font-size:18px; }
  .monster { font-size:62px; }
  .rule-head { display:none; }
  .rule-row { grid-template-columns:1fr 1fr; border:1px solid var(--line); border-radius:14px; padding:10px; }
  .rule-row .icon-btn { grid-column:2; justify-self:end; }
  .sim-grid { grid-template-columns:1fr; }
  .game-selector { grid-template-columns:1fr; }
}
