:root {
  --bg: #0f1020; --panel: #181a30; --panel2: #20233f; --line: #2c3054; --text: #eef0ff; --muted: #9aa0c7;
  --accent: #ffbf2f; --accent-ink: #261a00; --good: #3ddc97; --bad: #ff6b6b; --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; color: var(--text); background: var(--panel2); }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
code { background: var(--panel2); padding: 1px 6px; border-radius: 4px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: rgba(15,16,32,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 20px; }
.brand span { color: var(--accent); margin-left: 4px; font-size: 12px; vertical-align: super; }
nav { display: flex; gap: 4px; flex: 1; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
nav a.active { color: var(--text); background: var(--panel2); }
.account { display: flex; align-items: center; gap: 10px; }
.balance { font-weight: 700; padding: 6px 12px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); }
.balance small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.who { color: var(--muted); font-size: 14px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* Lobby */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip { white-space: nowrap; padding: 6px 14px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.chip small { opacity: .7; margin-left: 4px; }
.search { min-width: 220px; }
.meta { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.card { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--panel); border: 1px solid var(--line); }
.card .thumb { aspect-ratio: 287 / 402; background: var(--panel2) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .info { padding: 8px 10px; }
.card .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .prov { color: var(--muted); font-size: 12px; }
.card .badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.badge { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.6); }
.badge.jp { background: var(--accent); color: var(--accent-ink); }
.card .actions { position: absolute; inset: 0 0 auto 0; aspect-ratio: 287 / 402; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; background: rgba(10,10,25,.72); opacity: 0; transition: opacity .15s; }
.card:hover .actions, .card:focus-within .actions { opacity: 1; }
.card .actions button { width: 70%; }
.more { display: flex; justify-content: center; margin: 24px 0; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* Game page */
.game-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.game-bar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-bar .sub { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 8px; }
.frame-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #000; height: min(72vh, 760px); }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }
.loader { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: #000; }
.loader::before { content: ''; width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ticker { margin-top: 10px; color: var(--muted); font-size: 13px; min-height: 18px; }
body.fullscreen-game .topbar { display: none; }
body.fullscreen-game main { padding: 0; max-width: none; }
body.fullscreen-game .game-bar { margin: 0; padding: 6px 10px; background: var(--panel); height: 46px; }
body.fullscreen-game .game-bar h1 { font-size: 15px; }
body.fullscreen-game .game-bar .sub { display: none; }
body.fullscreen-game .game-bar button { padding: 6px 10px; font-size: 13px; }
body.fullscreen-game .frame-wrap { border-radius: 0; border: 0; height: calc(100dvh - 46px); }
body.fullscreen-game .ticker { display: none; }

/* History */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); } .neg { color: var(--bad); }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel); }
tr.detail td { background: var(--panel); font-size: 13px; color: var(--muted); }
.status { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); }
.table-wrap { overflow-x: auto; }

/* Modal + toasts */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.6); }
.modal[hidden] { display: none; }
.modal-card { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { margin: 0 0 4px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-card .row { display: flex; justify-content: flex-end; gap: 8px; }
.modal-card .hint { font-size: 12px; color: var(--muted); margin: 0; }
.error { color: var(--bad); font-size: 13px; margin: 0; min-height: 1em; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 340px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--good); }

@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .who { display: none; }
  main { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
  .card .actions { opacity: 1; background: linear-gradient(transparent 45%, rgba(10,10,25,.85)); justify-content: flex-end; padding-bottom: 10px; }
  .card .actions button { width: 86%; padding: 6px; font-size: 13px; }
  .search { min-width: 0; flex: 1; }
  .chips { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  #prov { flex: 1; min-width: 0; }
}
