:root {
  --bg: #10141c;
  --bg2: #171d28;
  --card: #1c2331;
  --line: #2c3547;
  --text: #edf1f7;
  --muted: #b3bdcc;
  --accent: #5ee08f;
  --accent-ink: #08210f;
  --danger: #ff8080;
  --warn: #ffd166;
  --focus: #8ab4ff;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--focus); }
.muted { color: var(--muted); }
.small { font-size: 16px; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 1rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Üst çubuk */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.15rem; }
.topbar-right { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: .2rem .75rem; font-size: 16px; white-space: nowrap;
}
.nick-chip { cursor: pointer; font: inherit; font-size: 16px; font-weight: 700; }
.ping.good { color: #8ef0b0; }
.ping.mid { color: var(--warn); }
.ping.bad { color: var(--danger); }

.banner {
  background: #4a3a10; color: #fff3cd; text-align: center; padding: .5rem 1rem; font-weight: 600;
  border-bottom: 1px solid #7a6420;
}

@media (max-width: 420px) { .brand span { display: none; } }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.view { animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 480px; margin: 2rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .5rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; margin-top: .5rem; }
.empty { padding: 1rem 0; text-align: center; }

.lobby, .room { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 860px) { .lobby, .room { grid-template-columns: minmax(0, 1fr); } }

/* Form ve düğmeler */
label { font-weight: 600; }
input, select {
  font: inherit; font-size: 17px; color: var(--text); background: var(--bg2);
  border: 1px solid #435069; border-radius: 10px; padding: .6rem .75rem; width: 100%;
}
input:focus, select:focus { border-color: var(--focus); }
.btn {
  font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  border-radius: 10px; padding: .6rem 1rem; min-height: 44px;
  border: 1px solid #435069; background: #273044; color: var(--text);
}
.btn:hover { background: #313c55; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #7deba6; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #6b3a44; }
.btn.on { background: #1f5134; border-color: var(--accent); color: #c9f7da; }
.small-btn { width: 100%; margin-top: .5rem; }

.chip {
  font: inherit; font-size: 16px; cursor: pointer; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted); padding: .3rem .85rem; min-height: 38px;
}
.chip.active { background: #2b3550; color: var(--text); border-color: #56658a; }
.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
.tab {
  font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; background: none; border: 0; color: var(--muted);
  padding: .5rem .75rem; border-bottom: 3px solid transparent; min-height: 44px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Oda listesi */
.room-list, .player-list, .history-list, .score-list, .chat-log { list-style: none; margin: 0; padding: 0; }
.room-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem 1rem; align-items: center;
  padding: .75rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; background: var(--bg2);
}
.room-name { font-weight: 700; overflow-wrap: anywhere; }
.room-meta { display: flex; flex-wrap: wrap; gap: .35rem .75rem; color: var(--muted); font-size: 16px; }
.badge { display: inline-block; border-radius: 6px; padding: 0 .45rem; font-size: 15px; font-weight: 700; border: 1px solid var(--line); }
.badge.waiting { color: #8ef0b0; border-color: #2f6b47; }
.badge.playing, .badge.countdown { color: var(--warn); border-color: #7a6420; }
.badge.mode { color: #b9d2ff; border-color: #3c507a; }

.mode-help dt { font-weight: 700; margin-top: .5rem; }
.mode-help dd { margin: 0 0 .25rem; color: var(--muted); }

/* Tablolar */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th, .table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 700; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.me td { background: #22304a; }
.dot { display: inline-block; width: .8em; height: .8em; border-radius: 50%; margin-right: .4em; vertical-align: -0.05em; }

.history-item {
  padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; background: var(--bg2);
  cursor: pointer; width: 100%; text-align: left; font: inherit; color: var(--text); display: block;
}
.history-item:hover { border-color: #56658a; }
.history-top { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.history-players { color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }

/* Oda */
.player-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: 10px; background: var(--bg2);
  border: 1px solid var(--line); margin-bottom: .4rem; flex-wrap: wrap;
}
.player-item .name { font-weight: 700; flex: 1; min-width: 6rem; overflow-wrap: anywhere; }
.player-item .tags { display: flex; gap: .35rem; flex-wrap: wrap; }
.tag { font-size: 15px; border-radius: 6px; padding: 0 .45rem; border: 1px solid var(--line); color: var(--muted); }
.tag.ready { color: #8ef0b0; border-color: #2f6b47; }
.tag.host { color: var(--warn); border-color: #7a6420; }
.tag.off { color: var(--danger); border-color: #6b3a44; }
.swatch { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 2px solid rgba(255,255,255,.25); }
.room-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0 .5rem; }
.room-actions .btn { flex: 1 1 10rem; }
.ability-box { margin-top: .75rem; }
.ability-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; }
.ability-opt {
  display: flex; flex-direction: column; justify-content: flex-start; gap: .15rem;
  font: inherit; text-align: left; cursor: pointer; background: var(--bg2); color: var(--text);
  border: 2px solid var(--line); border-radius: 10px; padding: .55rem .7rem;
}
.ability-opt strong { display: block; }
.ability-opt span { color: var(--muted); font-size: 15.5px; }
.ability-opt[aria-checked="true"] { border-color: var(--accent); background: #1d3326; }

.chat { display: flex; flex-direction: column; min-height: 420px; }
.chat-log {
  flex: 1; overflow-y: auto; max-height: 52vh; min-height: 240px; padding: .25rem; margin-bottom: .5rem;
  background: var(--bg2); border-radius: 10px; border: 1px solid var(--line);
}
.chat-log li { padding: .25rem .5rem; overflow-wrap: anywhere; }
.chat-log li.sys { color: var(--muted); font-style: italic; }
.chat-log .who { font-weight: 700; margin-right: .35rem; }
.chat-log time { color: #8d98aa; font-size: 15px; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.chat-form { display: flex; gap: .5rem; }
.chat-form input { flex: 1; }

/* Oyun */
.game-hud { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; align-items: center; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.status:empty { display: none; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .game-layout { grid-template-columns: minmax(0, 1fr); gap: .5rem; } }
.stage { position: relative; width: 100%; display: flex; justify-content: center; }
#canvas {
  display: block; background: #0b0f16; border-radius: 10px; border: 1px solid var(--line);
  touch-action: none; user-select: none; -webkit-user-select: none; max-width: 100%;
}
.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: clamp(3rem, 12vw, 7rem); font-weight: 900; color: #fff; text-shadow: 0 4px 24px #000; pointer-events: none;
}
.score-list li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.score-list li.dead { opacity: .55; text-decoration: line-through; }
.score-list .sc { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.score-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keys { margin-top: .75rem; }

.touch-controls { display: none; }
@media (pointer: coarse) {
  .touch-controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem .25rem; }
  .keys { display: none; }
}
.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 6px; }
.dpad-btn {
  font-size: 24px; border-radius: 14px; border: 1px solid #435069; background: #273044; color: var(--text);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.dpad-btn:active { background: #3a4866; }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
.ability-btn {
  width: 110px; height: 110px; border-radius: 50%; border: 3px solid var(--accent); background: #1d3326; color: var(--text);
  font: inherit; font-weight: 800; font-size: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none;
}
.ability-btn.cooling { border-color: #435069; background: #222a3a; color: var(--muted); }
.ability-btn .cd { font-variant-numeric: tabular-nums; }
#hud-ability.ready { color: #8ef0b0; border-color: #2f6b47; font-weight: 700; }

/* Diyaloglar */
dialog {
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.25rem; width: min(560px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
}
dialog#dlg-results, dialog#dlg-match { width: min(760px, calc(100vw - 1rem)); }
dialog::backdrop { background: rgba(5, 8, 12, .7); }
.winner { color: var(--warn); font-weight: 800; }

.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #3a1d24; color: #ffe1e5; border: 1px solid #6b3a44; border-radius: 10px; padding: .7rem 1rem; z-index: 50;
  max-width: calc(100vw - 2rem); font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.info { background: #1d2c3a; color: #e1efff; border-color: #3c507a; }

@media (prefers-reduced-motion: reduce) { .view { animation: none; } }
