:root {
  color-scheme: dark;
  --bg: #0d1017;
  --panel: #161b25;
  --panel-2: #1d2431;
  --line: #30394a;
  --text: #f2f4f8;
  --muted: #8d98aa;
  --accent: #5de4c7;
  --danger: #ff667a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, #162235 0, transparent 34rem),
    var(--bg);
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(20px, 5vw, 72px);
  border-bottom: 1px solid var(--line);
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); letter-spacing: -0.05em; }
h2 { font-size: 1.35rem; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: .7rem;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.connection { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .85rem; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #60697a; }
.connection-dot.online { background: var(--accent); box-shadow: 0 0 12px #5de4c780; }
.connection-dot.error { background: var(--danger); }

main { width: min(1200px, calc(100% - 32px)); margin: 0 auto; }

.join-panel { min-height: calc(100vh - 165px); display: grid; place-items: center; }
.join-card {
  width: min(430px, 100%);
  padding: 32px;
  background: linear-gradient(145deg, #1c2330, #131821);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px #0008;
}
.join-card h2 { margin-bottom: 10px; font-size: 1.8rem; }
.join-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; margin-bottom: 24px; }
.join-card label { display: block; margin-bottom: 8px; color: var(--muted); font-size: .85rem; }
.join-card input {
  width: 100%; padding: 13px 14px; color: var(--text); background: #0e131b;
  border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.join-card input:focus { border-color: var(--accent); }
.join-card button, .chat-form button, .match-toolbar button {
  border: 0; border-radius: 8px; color: #07120f; background: var(--accent); font-weight: 750;
}
.join-card button { width: 100%; margin-top: 12px; padding: 13px; }
.join-card .text-button {
  padding: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 600;
}
.auth-form label { margin-top: 13px; }
.auth-form small { display: block; margin-top: 6px; color: var(--muted); }
.form-error { padding: 9px 11px; color: #ffc4cc !important; background: #4b1722; border-radius: 7px; }
.lobby-card { width: min(760px, 100%); }
.lobby-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.lobby-heading h2 { margin: 0; }
.join-card .logout-button { width: auto; min-width: 92px; margin: 0; padding: 10px 14px; color: var(--text); background: transparent; border: 1px solid var(--line); }
.lobby-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.join-card .lobby-tabs button { width: 100%; margin: 0; padding: 11px 8px; color: var(--muted); background: var(--panel-2); border-radius: 0; border-right: 1px solid var(--line); }
.join-card .lobby-tabs button:last-child { border-right: 0; }
.join-card .lobby-tabs button[aria-selected="true"] { color: #07120f; background: var(--accent); }
.lobby-tab-panel { min-height: 250px; padding: 16px; background: #0e131b; border: 1px solid var(--line); border-radius: 8px; }
.lobby-tab-panel > p { color: var(--muted); }
.controls-form input[readonly] { cursor: pointer; }
.controls-form { width: 100%; }
.controls-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 14px; }
.controls-grid .control-field { min-width: 0; }
.controls-grid .control-field label { margin-top: 0; }
.controls-form > button { width: 100%; }
.account-form { max-width: 460px; margin: 0 auto; }
.winlist-mode-select { width: 100%; margin-bottom: 8px; padding: 9px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; }
.winlist-mode { max-height: 240px; overflow-y: auto; }
.winlist-ranking { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.winlist-ranking li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 7px; align-items: center; padding: 6px 7px; background: var(--panel); border-radius: 5px; }
.winlist-rank { color: var(--muted); font-family: ui-monospace, monospace; }
.winlist-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.winlist-points { white-space: nowrap; }
.winlist-ranking .empty-winlist { display: block; color: var(--muted); }
.channel-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 10px;
}
.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  background: #0e131b;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.channel-row div { min-width: 0; display: grid; gap: 2px; }
.channel-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-row span, .empty-channel { color: var(--muted); font-size: .78rem; }
.channel-row button { width: auto; min-width: 116px; margin: 0; padding: 9px 10px; }
.channel-row button:disabled { cursor: default; opacity: .35; }
.create-channel-form { display: flex; gap: 8px; margin-top: 10px; }
.create-channel-form input { min-width: 0; }
.create-channel-form button { width: auto; flex: none; margin: 0; padding: 0 12px; }

.game { padding: 24px 0 48px; }
.channel-title {
  min-width: 0;
  margin-right: auto;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-title strong { color: var(--text); }
.match-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  margin: 0 auto 16px;
  padding: 9px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.match-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
}
.match-toolbar button { min-width: 76px; padding: 8px 12px; }
.match-toolbar button:disabled { cursor: default; opacity: .35; }
.match-toolbar label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.match-toolbar select {
  min-width: 0;
  padding: 7px 9px;
  color: var(--text);
  background: #0e131b;
  border: 1px solid var(--line);
  border-radius: 7px;
}
#phase-label { color: var(--muted); font-size: .8rem; font-weight: 750; }
#mode-value { font-size: .8rem; white-space: nowrap; }
.playing-fields {
  display: grid;
  grid-template-columns: 460px minmax(480px, 1fr);
  align-items: start;
  justify-content: center;
  gap: clamp(18px, 3vw, 42px);
}
.local-station { min-width: 0; }
.field-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 31px;
  padding: 6px 10px;
  overflow: hidden;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  font-size: .84rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-name span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.field-id {
  flex: none;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
}
.local-zone { display: flex; align-items: flex-start; justify-content: flex-start; gap: 14px; }
.board-frame { position: relative; padding: 7px; border: 1px solid #475269; border-radius: 8px; background: #080b10; box-shadow: 0 18px 60px #0008; }
.local-station .board-frame { border-radius: 0 0 8px 8px; }
#board { display: block; width: min(288px, 64vw); height: auto; background: #090d14; }
.game-over { position: absolute; inset: 45% 7px auto; padding: 12px; text-align: center; color: white; background: #b51f3ddd; font-weight: 900; letter-spacing: .2em; }
.side-panel { width: 150px; display: grid; gap: 10px; margin-top: 10px; }
.stat-card, .preview-card { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.stat-card span, .preview-card > span { display: block; color: var(--muted); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; }
.stat-card strong { display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; }
.stat-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.preview-card canvas { display: block; width: 100%; height: auto; margin-top: 8px; }

.weapons-panel {
  min-height: 76px;
  margin-top: 10px;
  padding: 9px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.battle-panel {
  min-height: 118px;
  margin-top: 10px;
  padding: 9px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.battle-events { height: 98px; margin: 7px 0 0; padding: 0; overflow-y: auto; list-style: none; font-size: .76rem; }
.battle-events li { display: flex; gap: 6px; padding: 2px 0; color: var(--text); overflow-wrap: anywhere; }
.battle-sequence { flex: none; color: var(--muted); font-family: ui-monospace, monospace; }
.battle-action { color: #b16fea; }
.weapons-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
.weapons-heading small { text-transform: none; letter-spacing: 0; }
kbd { padding: 1px 4px; color: var(--text); background: #0e131b; border: 1px solid var(--line); border-radius: 3px; font-family: ui-monospace, monospace; }
.weapons { display: flex; min-height: 25px; margin-top: 7px; gap: 4px; overflow-x: auto; }
.weapon {
  display: grid;
  flex: 0 0 34px;
  height: 34px;
  place-items: center;
  color: #05070a;
  background: #aeb4bf;
  border-radius: 7px;
  font-weight: 900;
  font-size: 1rem;
  font-family: ui-monospace, monospace;
}
.weapon-o { color: #cf1836; }
.weapon-q, .weapon-n, .weapon-s { color: #185bd6; }
.weapon.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.empty-weapon { color: var(--muted); font-size: .78rem; }
.opponents {
  display: grid;
  grid-template-columns: repeat(3, minmax(158px, 196px));
  align-items: start;
  justify-content: center;
  gap: 14px;
}
.opponent-card { overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
.opponent-card header {
  display: flex;
  min-height: 31px;
  padding: 6px 8px;
  justify-content: space-between;
  align-items: baseline;
  gap: 5px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.opponent-card header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opponent-card header span { flex: none; color: var(--muted); font-size: .65rem; }
.opponent-card canvas { display: block; width: 100%; height: auto; background: #090d14; }
.opponent-card.empty header strong { color: var(--muted); font-weight: 500; }
.opponent-card.empty canvas { opacity: .42; }

.chat-panel { width: 100%; margin: 20px auto 0; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.chat-heading { display: flex; justify-content: space-between; padding: 9px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.chat-heading span { color: var(--muted); font-size: .72rem; }
.chat-messages { height: 130px; margin: 0; padding: 9px 12px; overflow-y: auto; list-style: none; font-size: .82rem; }
.chat-messages li { padding: 2px 0; overflow-wrap: anywhere; }
.chat-messages time { margin-right: 7px; color: var(--muted); font-family: ui-monospace, monospace; font-size: .68rem; }
.chat-messages strong { margin-right: 6px; color: var(--accent); }
.chat-form { display: flex; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; padding: 10px 12px; color: var(--text); background: #0e131b; border: 0; outline: none; }
.chat-form input:focus { box-shadow: inset 0 0 0 1px var(--accent); }
.chat-form button { padding: 8px 18px; border-radius: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

footer { display: flex; justify-content: center; gap: 24px; padding: 18px; color: var(--muted); border-top: 1px solid var(--line); font-size: .75rem; }

@media (max-width: 1050px) {
  .playing-fields { grid-template-columns: 460px; }
  .opponents { grid-template-columns: repeat(3, minmax(158px, 180px)); justify-content: start; }
}

@media (max-width: 560px) {
  .topbar { padding: 15px 18px; }
  main { width: min(100% - 20px, 1200px); }
  .game { padding-top: 18px; }
  .playing-fields { grid-template-columns: minmax(0, 1fr); }
  .match-toolbar { align-items: stretch; flex-direction: column; }
  .match-controls { flex-wrap: wrap; justify-content: flex-start; }
  #phase-label { width: 100%; }
  .local-zone { gap: 9px; }
  .side-panel { width: 112px; }
  .stat-card, .preview-card { padding: 9px; }
  .opponents { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .chat-heading span { display: none; }
  .join-card.lobby-card { padding: 20px 14px; }
  .lobby-heading { align-items: flex-start; }
  .lobby-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .join-card .lobby-tabs button:nth-child(2) { border-right: 0; }
  .join-card .lobby-tabs button:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .controls-grid { grid-template-columns: 1fr; }
  footer { gap: 10px; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
