:root {
  --bg: #070b14;
  --bg2: #0d1526;
  --panel: rgba(12, 20, 36, 0.94);
  --line: rgba(120, 180, 255, 0.16);
  --txt: #e9f1ff;
  --muted: #8fa3c4;
  --gold: #ffcc66;
  --lagon: #35d6c4;
  --lave: #ff7a4d;
  --ombre: #c084fc;
  --danger: #ff5d7a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #16233c 0%, var(--bg) 60%);
  color: var(--txt);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

#topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(7, 11, 20, 0.92), rgba(7, 11, 20, 0));
}
.brand { font-weight: 700; letter-spacing: 0.14em; font-size: 13px; line-height: 1.2; }
.brand span { display: block; font-weight: 400; letter-spacing: 0.06em; font-size: 10px; color: var(--muted); }
#hud { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  font-size: 11px; padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(15, 28, 48, 0.75); color: var(--txt);
  white-space: nowrap;
}
.chip.gold { color: var(--gold); border-color: rgba(255, 204, 102, 0.35); }

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

#toolbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 15; padding: 8px; border-radius: 14px;
  background: rgba(10, 17, 30, 0.85); border: 1px solid var(--line); backdrop-filter: blur(8px);
}

.btn {
  font: inherit; font-size: 12px; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  background: rgba(30, 48, 78, 0.9); color: var(--txt);
  border: 1px solid var(--line); min-height: 40px;
}
.btn:hover:not(:disabled) { border-color: rgba(120, 200, 255, 0.5); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #2a7d78, #1c5b58); border-color: #3fd0c0; font-weight: 700; }
.btn.danger { background: linear-gradient(180deg, #8a2a3c, #5c1b28); border-color: #ff5d7a; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: 11px; }

.panel {
  position: fixed; right: 14px; top: 74px; width: 320px; max-width: calc(100vw - 28px);
  z-index: 18; padding: 16px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel .close, .modal .close {
  position: absolute; top: 8px; right: 10px; background: none; border: 0;
  color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1;
}
.panel dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 10px 0; font-size: 12px; }
.panel dt { color: var(--muted); }
.panel dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.modal {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: rgba(4, 8, 16, 0.82); backdrop-filter: blur(6px); padding: 16px;
}
.card {
  position: relative; width: 380px; max-width: 100%; padding: 22px; border-radius: 18px;
  background: var(--panel); border: 1px solid var(--line);
}
.card.wide { width: 560px; }
.card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: 0.04em; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
label { display: block; font-size: 11px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.08em; }
input {
  width: 100%; padding: 11px 12px; border-radius: 10px; font: inherit;
  background: rgba(8, 14, 26, 0.9); color: var(--txt); border: 1px solid var(--line);
}
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
.tiny { font-size: 10px; margin-top: 12px; }
.hidden { display: none !important; }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  z-index: 40; padding: 10px 16px; border-radius: 12px; font-size: 12px;
  background: rgba(8, 16, 30, 0.95); border: 1px solid var(--line); max-width: 90vw;
}
#toast.error { border-color: var(--danger); color: #ffd0d8; }

.list { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.row {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 10px; background: rgba(20, 34, 56, 0.6);
  border: 1px solid var(--line); font-size: 12px;
}
.row .tag { font-size: 10px; padding: 3px 7px; border-radius: 999px; border: 1px solid var(--line); }
.win { color: var(--lagon); }
.loss { color: var(--danger); }

#legend {
  position: fixed; left: 14px; bottom: 16px; z-index: 14;
  font-size: 10px; color: var(--muted); line-height: 1.6;
}
#legend b { color: var(--txt); font-weight: 600; }

.gridhint {
  position: fixed; left: 50%; top: 66px; transform: translateX(-50%);
  z-index: 16; font-size: 11px; color: var(--muted); text-align: center;
}
