:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --bg: #080d0b;
  --panel: rgba(14, 22, 18, .96);
  --panel-soft: rgba(12, 19, 15, .9);
  --line: rgba(210, 233, 218, .14);
  --line-strong: rgba(210, 233, 218, .24);
  --text: #f3f6f2;
  --muted: #b2bdb5;
  --subtle: #84938a;
  --accent: #ffad45;
  --accent-bright: #ffc46f;
  --mint: #72d9b2;
  background: var(--bg);
  color: var(--text);
}

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

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: -30px;
  z-index: 0;
  background: linear-gradient(145deg, rgba(5, 16, 12, .68), rgba(5, 10, 8, .88)), url('/arena.svg') center / cover;
  filter: blur(12px) saturate(.78);
  transform: scale(1.04);
}

header {
  position: relative;
  z-index: 1;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(4vw, calc((100vw - 1360px) / 2));
  background: rgba(7, 12, 10, .88);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .16);
}

.brand {
  position: relative;
  padding-left: 47px;
  color: var(--text);
  text-decoration: none;
  font-size: 24px;
  line-height: 1;
  font-style: italic;
  font-weight: 950;
  letter-spacing: -1.15px;
  text-shadow: 0 2px 18px rgba(255, 173, 69, .12);
}

.brand::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 35px;
  height: 35px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 196, 111, .68);
  border-radius: 11px;
  background: url('/favicon.png?v=3') center / cover, #111a15;
  box-shadow: 0 0 20px rgba(255, 173, 69, .12), inset 0 0 12px rgba(255, 255, 255, .06);
}

.brand span { color: var(--accent); }
.brand small {
  display: block;
  margin-top: 6px;
  color: #a5b6aa;
  font-size: 8px;
  font-style: normal;
  letter-spacing: 4px;
}

.header-note {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .02em;
}
.header-note::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 12px rgba(114, 217, 178, .48);
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1360px, 94vw);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  align-items: start;
  gap: 22px;
  margin: 32px auto 54px;
  flex: 1;
}

.screen {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #020403;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 13px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .46), 0 0 0 1px rgba(255, 173, 69, .035);
}

canvas {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  outline: none;
  image-rendering: auto;
}
canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

#start-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 28px 20px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 43%, rgba(31, 58, 44, .78), transparent 49%),
    radial-gradient(ellipse at 50% 120%, rgba(255, 173, 69, .11), transparent 43%),
    linear-gradient(155deg, #09120e, #030605 66%);
}

#start-panel::before,
#start-panel::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
#start-panel::before {
  inset: 16px;
  border: 1px solid rgba(255, 255, 255, .055);
  border-radius: 10px;
  mask-image: linear-gradient(to bottom, #000, transparent 42%, transparent 68%, #000);
}
#start-panel::after {
  width: min(54vw, 540px);
  height: 1px;
  top: 25%;
  background: linear-gradient(90deg, transparent, rgba(255, 173, 69, .38), transparent);
  box-shadow: 0 0 30px rgba(255, 173, 69, .12);
}

#start-panel > * { position: relative; z-index: 1; }
#start-panel h1 {
  margin: 12px 0 0;
  color: #fff;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
  letter-spacing: -.8px;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .38);
}
#start-panel p {
  margin: 12px 0 23px;
  color: #c2cec5;
  font-size: 14px;
}
#start-panel button {
  width: min(360px, 90%);
  min-height: 49px;
  margin: 5px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 760;
}
#start-panel small {
  margin-top: 17px;
  color: #a2b0a6;
  font-size: 11px;
  letter-spacing: .04em;
}
.emblem {
  color: var(--accent-bright);
  font-size: 17px;
  letter-spacing: 9px;
  padding-left: 9px;
  text-shadow: 0 0 22px rgba(255, 173, 69, .4);
}

button, select, input, .file-button { font: inherit; }
button, .file-button {
  color: var(--text);
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .16s ease, background .16s ease, transform .16s ease, box-shadow .16s ease;
}
button:hover:not(:disabled), .file-button:hover {
  background: rgba(255, 255, 255, .09);
  border-color: rgba(255, 196, 111, .5);
}
button:active:not(:disabled) { transform: translateY(1px); }
button.primary {
  color: #17140f;
  background: linear-gradient(135deg, #ffc36b, #ffa53b);
  border: 1px solid #ffd18f;
  box-shadow: 0 7px 24px rgba(255, 155, 48, .2), inset 0 1px rgba(255, 255, 255, .45);
}
button.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ffd18a, #ffb253);
  box-shadow: 0 9px 30px rgba(255, 155, 48, .3), inset 0 1px rgba(255, 255, 255, .55);
}
button:disabled { opacity: .48; cursor: wait; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
summary:focus-visible, .file-button:focus-within {
  outline: 2px solid var(--accent-bright);
  outline-offset: 3px;
}

.player-status {
  min-height: 42px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 2px 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
#status { display: inline-flex; align-items: center; gap: 8px; }
#status::before {
  content: "";
  flex: 0 0 7px;
  width: 7px;
  height: 7px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 10px rgba(114, 217, 178, .32);
}
#fps { flex: 0 0 auto; color: #c8d2cb; white-space: nowrap; font-variant-numeric: tabular-nums; }

.player-actions { display: flex; gap: 10px; }
.player-actions button {
  flex: 1;
  min-height: 40px;
  background: rgba(10, 16, 12, .76);
}
.about {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}
.about summary { color: #e4eae5; text-align: center; cursor: pointer; font-weight: 650; }
.about p { margin: 13px 5px 0; color: var(--muted); line-height: 1.7; }

.settings-panel {
  position: sticky;
  top: 18px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .3), inset 0 1px rgba(255, 255, 255, .025);
  backdrop-filter: blur(16px);
}
.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .018);
}
.tabs button {
  min-height: 46px;
  padding: 12px 5px 10px;
  color: #9ba89f;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  text-transform: uppercase;
  letter-spacing: .8px;
  font-size: 10px;
  font-weight: 750;
}
.tabs button:hover { color: #e7eee8; background: rgba(255, 255, 255, .035); }
.tabs button[aria-selected="true"] {
  color: #fff;
  border-bottom-color: var(--accent);
  background: linear-gradient(180deg, transparent, rgba(255, 173, 69, .065));
}
.tab-panel { min-height: 300px; padding: 18px; }
h2 {
  margin: 23px 0 8px;
  color: #9bad9f;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.25px;
}
.tab-panel h2:first-child { margin-top: 4px; }
.save-backup { margin: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.save-backup summary { padding: 13px 0; color: #e4eae5; cursor: pointer; font-size: 12px; font-weight: 650; }
.save-backup[open] { padding-bottom: 8px; }
.hint { margin: 0 0 13px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.setting {
  min-height: 49px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: #e4eae5;
  font-size: 13px;
}
.setting > select { max-width: 190px; }
.range-control { display: flex; align-items: center; gap: 10px; }
.range-control input { width: 126px; accent-color: var(--accent); }
output { min-width: 34px; color: var(--muted); text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
select, input[type="text"], #room-code {
  padding: 8px 10px;
  color: var(--text);
  background: #18231c;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font-size: 12px;
}
.value { color: #c0d0c4; font-size: 12px; }
.wide { display: block; width: 100%; margin: 12px 0; text-align: center; }
.room-heading { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.room-heading h2 { margin: 0; }
.room-heading button { padding: 6px 10px; font-size: 11px; }
.room-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
#rooms { max-height: 180px; overflow: auto; }
#rooms p { color: var(--muted); font-size: 12px; line-height: 1.6; }
#join-form { margin-top: 20px; }
#join-form label { color: var(--muted); font-size: 12px; }
.join-row { display: flex; gap: 8px; margin-top: 8px; }
#room-code { width: 100%; letter-spacing: 3px; text-transform: uppercase; }
#room-label { color: var(--accent-bright); font-size: 13px; }
#loading-indicator {
  position: absolute;
  bottom: 24px;
  left: 50%;
  width: max-content;
  max-width: min(90%, 600px);
  transform: translateX(-50%);
  padding: 14px 20px;
  color: #f3f6f2;
  background: rgba(15, 24, 19, .96);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .42);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

pre {
  max-height: 460px;
  overflow: auto;
  margin: 16px 0;
  color: #c0cec4;
  font-size: 10px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
dialog {
  width: min(470px, 90vw);
  padding: 24px;
  color: var(--text);
  background: #111a15;
  border: 1px solid #536458;
  border-radius: 13px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .48);
}
dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; color: #fff; font-size: 16px; letter-spacing: 0; text-transform: none; }
dialog p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.keys { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 12px; font-size: 13px; }
kbd { display: inline-block; padding: 4px 7px; color: #edf3ee; background: #ffffff09; border: 1px solid var(--line-strong); border-radius: 5px; font-size: 12px; }
footer {
  position: relative;
  z-index: 1;
  padding: 22px max(4vw, calc((100vw - 1360px) / 2));
  color: #b8c3bb;
  background: rgba(5, 10, 7, .86);
  border-top: 1px solid var(--line-strong);
  text-align: center;
  font-size: 12px;
  line-height: 1.9;
}
footer a { color: #aabbb0; text-decoration: none; }
footer a:hover { color: var(--accent-bright); }
.footer-contact {
  width: min(900px, 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 auto 18px;
  padding: 15px 18px;
  text-align: left;
  background: linear-gradient(110deg, rgba(255, 173, 69, .08), rgba(255, 255, 255, .025));
  border: 1px solid var(--line-strong);
  border-radius: 11px;
}
.footer-contact-copy { flex: 1; display: grid; gap: 2px; }
.footer-contact-copy strong { color: #eef3ef; font-size: 13px; }
.footer-contact-copy span { color: var(--muted); font-size: 11px; }
a.footer-action {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  color: #20180e;
  background: var(--accent-bright);
  border: 1px solid #ffdaa0;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  transition: background .16s ease, transform .16s ease;
}
a.footer-action:hover { color: #20180e; background: #ffd18b; transform: translateY(-1px); }
a.footer-action-secondary { color: #e7eee8; background: rgba(255, 255, 255, .045); border-color: var(--line-strong); }
a.footer-action-secondary:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.footer-meta { color: #b8c3bb; }

@media (min-width: 1500px) { .layout { margin-top: 40px; } }
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; width: 96vw; }
  .tab-panel { padding: 15px; }
  .setting { gap: 9px; font-size: 12px; }
  .range-control input { width: 105px; }
  .setting > select { max-width: 160px; }
}
@media (max-width: 740px) {
  header { min-height: 64px; padding: 11px 5vw; }
  .brand { padding-left: 42px; font-size: 21px; }
  .brand::before { width: 32px; height: 32px; border-radius: 10px; }
  .header-note { display: none; }
  .layout { grid-template-columns: 1fr; width: 92vw; gap: 14px; margin: 20px auto 34px; }
  .screen { border-radius: 10px; }
  #start-panel { padding: 16px; }
  #start-panel h1 { font-size: clamp(20px, 6vw, 27px); }
  #start-panel p { margin: 8px 0 12px; font-size: 12px; }
  #start-panel button { min-height: 42px; padding: 10px; font-size: 13px; }
  #start-panel small, .emblem { display: none; }
  .player-actions { gap: 7px; }
  .player-actions button { min-height: 40px; padding: 8px 5px; font-size: 11px; }
  .settings-panel { position: static; }
  .tab-panel { min-height: unset; padding: 16px; }
  .tabs button { min-height: 44px; font-size: 9px; }
  footer { padding: 18px 4vw; }
  .footer-contact { flex-wrap: wrap; justify-content: flex-start; gap: 8px; padding: 13px; }
  .footer-contact-copy { flex: 1 1 100%; padding-bottom: 3px; }
  a.footer-action { flex: 1; }
}
@media (max-width: 420px) {
  .player-status { font-size: 11px; }
  .range-control { gap: 6px; }
  .range-control input { width: 90px; }
  .join-row { align-items: stretch; }
  .join-row button { flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
