:root {
  color-scheme: light dark;
  --bg: #f3f3f3;
  --panel: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.76);
  --text: #050505;
  --muted: #747781;
  --line: #dedede;
  --shadow: 0 18px 45px rgba(20, 24, 32, 0.1);
  --x: #ff406d;
  --x-dark: #d72d59;
  --blue: #4a93ff;
  --red: #ff406d;
  --yellow: #ffd166;
  --board: #2563eb;
}

[data-theme="dark"] {
  --bg: #13151b;
  --panel: #1c2029;
  --panel-soft: rgba(28, 32, 41, 0.82);
  --text: #f6f7fb;
  --muted: #a0a6b5;
  --line: #323846;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.34);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13151b;
    --panel: #1c2029;
    --panel-soft: rgba(28, 32, 41, 0.82);
    --text: #f6f7fb;
    --muted: #a0a6b5;
    --line: #323846;
    --shadow: 0 22px 55px rgba(0, 0, 0, 0.34);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 64, 109, 0.08), transparent 34rem),
    var(--bg);
}

button, input { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.app-shell {
  width: min(100% - 28px, 620px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 0 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 3.1rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-icon {
  width: clamp(3rem, 10vw, 4rem);
  height: clamp(3rem, 10vw, 4rem);
  display: grid;
  place-items: center;
  color: var(--x);
  filter: drop-shadow(0 8px 10px rgba(255, 64, 109, 0.25));
}

.brand-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel, .game-view { width: 100%; }

.menu-panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.menu-actions { display: grid; gap: 14px; }

.primary-btn, .secondary-btn, .pill-btn, .copy-btn {
  min-height: 42px;
  border-radius: 10px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(15, 18, 25, 0.08);
}

.primary-btn {
  min-height: 52px;
  color: #fff;
  font-weight: 900;
  background: linear-gradient(135deg, var(--x), #ff7a95);
}

.secondary-btn { padding: 0 16px; font-weight: 800; }

.join-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 138px;
  min-height: 46px;
  border: 1px solid rgba(255, 64, 109, 0.35);
  color: #fff;
  background: linear-gradient(135deg, #ff406d, #ff6d8b);
}

.join-icon, .btn-icon, .copy-icon, .back-home-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 52px;
  min-width: 108px;
  padding: 0 18px;
  font-weight: 850;
  white-space: nowrap;
}

#resetBtn { min-width: 176px; }
.theme-icon { stroke: color-mix(in srgb, var(--x) 72%, var(--text)); }

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(255, 64, 109, 0.24);
  border-radius: 11px;
  font-weight: 800;
  background: linear-gradient(135deg, rgba(255, 64, 109, 0.14), var(--panel));
}

.copy-icon { stroke: var(--x); }

.join-card { display: grid; gap: 7px; }
.join-card label, .muted-label { color: var(--muted); font-size: 0.88rem; }

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input {
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  color: var(--text);
  background: var(--panel);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  outline: none;
}

input:focus {
  border-color: rgba(255, 64, 109, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 64, 109, 0.12);
}

.hint, .error-text, .sync-text, .footer { text-align: center; }
.hint { margin: 16px 0 0; color: var(--muted); }
.error-text { min-height: 22px; margin: 12px 0 0; color: var(--x-dark); font-weight: 800; }

.back-home-btn {
  width: fit-content;
  min-height: 42px;
  margin: 18px auto 0;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: var(--panel);
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(15, 18, 25, 0.08);
}

.top-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.room-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  width: min(100%, 540px);
  margin: 0 auto 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}

.room-strip div { display: grid; gap: 2px; text-align: center; }
.room-strip strong { font-size: 1.05rem; letter-spacing: 0.08em; }

.column-buttons {
  width: min(100%, 540px);
  margin: 0 auto 8px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
}

.drop-btn {
  min-height: 34px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--x), #ff7a95);
  font-weight: 900;
}

.board {
  width: min(100%, 540px);
  aspect-ratio: 7 / 6;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 8px;
  padding: 10px;
  border: 4px solid color-mix(in srgb, var(--text) 34%, var(--board));
  border-radius: 20px;
  background: linear-gradient(135deg, var(--board), #4a93ff);
  box-shadow: 0 16px 34px rgba(15, 18, 25, 0.16);
}

.cell {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 92%, #fff);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.22);
}

.disc {
  width: 86%;
  height: 86%;
  border-radius: 999px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.34), 0 8px 14px rgba(0, 0, 0, 0.18);
}

.disc-R { background: linear-gradient(135deg, var(--red), #d72d59); }
.disc-Y { background: linear-gradient(135deg, #ffe082, var(--yellow)); }
.cell.win { outline: 4px solid #fff; outline-offset: -3px; }

.status-text {
  min-height: 36px;
  margin: 22px 0 4px;
  font-size: clamp(1.35rem, 4.8vw, 1.75rem);
  line-height: 1.15;
  text-align: center;
}

.sync-text {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
}

.footer {
  margin-top: auto;
  padding-top: 24px;
  color: var(--muted);
}

.hidden { display: none !important; }

@media (max-width: 520px) {
  .app-shell { width: min(100% - 20px, 420px); }
  .brand { gap: 10px; }
  .top-actions { display: grid; grid-template-columns: 1fr; }
  .pill-btn, #resetBtn { width: 100%; min-width: 0; }
  .room-strip { grid-template-columns: 1fr; }
  .copy-btn, .join-btn, .back-home-btn { width: 100%; }
  .join-row { grid-template-columns: 1fr; }
  .board { gap: 5px; padding: 7px; border-radius: 16px; }
  .column-buttons { gap: 5px; }
  .drop-btn { min-height: 31px; }
}
