: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;
  --o: #4f8dff;
  --o-dark: #7356ff;
}

[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, 520px);
  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;
  animation: rise 420ms ease both;
}

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

.brand-x {
  font-size: clamp(3rem, 11vw, 4rem);
  line-height: 0.8;
  font-weight: 900;
  color: var(--x);
  text-shadow:
    0 4px 0 var(--x-dark),
    0 10px 16px rgba(255, 64, 109, 0.28);
  transform: rotate(-6deg);
}

.panel,
.game-view {
  width: 100%;
  animation: rise 360ms ease both;
}

.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);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

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

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

.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);
  box-shadow: 0 12px 26px rgba(255, 64, 109, 0.2);
}

.join-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  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 20px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

#resetBtn {
  min-width: 176px;
}

#themeBtn {
  min-width: 116px;
}

#menuBtn {
  min-width: 104px;
}

.pill-btn span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.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-size: 0.94rem;
  font-weight: 800;
  background: linear-gradient(135deg, rgba(255, 64, 109, 0.14), var(--panel));
}

.copy-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--x);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy-btn.copied {
  border-color: rgba(74, 147, 255, 0.34);
  background: linear-gradient(135deg, rgba(74, 147, 255, 0.16), var(--panel));
}

.copy-btn.copied .copy-icon {
  stroke: #4a93ff;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: color-mix(in srgb, var(--text) 72%, transparent);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon {
  stroke: color-mix(in srgb, var(--x) 72%, var(--text));
}

button:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(15, 18, 25, 0.13);
}

button:not(:disabled):active {
  transform: translateY(0) scale(0.98);
}

.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);
}

.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);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.back-home-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(15, 18, 25, 0.13);
}

.back-home-btn:active {
  transform: translateY(0) scale(0.98);
}

.back-home-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: color-mix(in srgb, var(--text) 72%, transparent);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.error-text {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--x-dark);
  font-weight: 700;
}

.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%, 398px);
  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.15rem;
  letter-spacing: 0.08em;
}

.board {
  width: min(100%, 398px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.cell:not(:disabled):hover {
  transform: translateY(-2px);
  border-color: rgba(255, 64, 109, 0.32);
}

.mark {
  display: inline-block;
  font-size: clamp(3.8rem, 18vw, 6rem);
  line-height: 1;
  font-weight: 900;
  animation: pop 210ms cubic-bezier(0.2, 1.5, 0.45, 1) both;
}

.mark.no-pop {
  animation: none;
}

.mark-x {
  color: var(--x);
  text-shadow: 0 5px 0 var(--x-dark), 0 12px 18px rgba(255, 64, 109, 0.24);
  transform: rotate(-5deg);
}

.mark-o {
  color: var(--o);
  text-shadow: 0 5px 0 var(--o-dark), 0 12px 18px rgba(79, 141, 255, 0.22);
}

.cell.win {
  border-color: rgba(255, 64, 109, 0.78);
  background: linear-gradient(145deg, rgba(255, 64, 109, 0.12), var(--panel));
  animation: winPulse 900ms ease-in-out infinite alternate;
}

.status-text {
  min-height: 36px;
  margin: 26px 0 4px;
  font-size: clamp(1.45rem, 5.2vw, 1.8rem);
  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);
}

.footer small {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.hidden {
  display: none !important;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.55) rotate(-8deg);
  }
  to {
    opacity: 1;
  }
}

@keyframes winPulse {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-3px);
  }
}

@media (max-width: 440px) {
  .app-shell {
    width: min(100% - 20px, 420px);
    padding-top: 18px;
  }

  .top-actions {
    gap: 7px;
  }

  .pill-btn {
    padding: 0 10px;
    font-size: 0.92rem;
  }

  .room-strip {
    grid-template-columns: 1fr;
  }

  .copy-btn {
    width: 100%;
  }

  .join-row {
    grid-template-columns: 1fr;
  }

  .join-btn {
    width: 100%;
  }

  .back-home-btn {
    width: 100%;
  }
}
