:root {
  color-scheme: light;
  --bg: #f3f6f0;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: #ffffff;
  --ink: #17211d;
  --muted: #66746b;
  --line: rgba(31, 45, 38, 0.16);
  --board: #d2a35b;
  --board-line: rgba(40, 24, 12, 0.72);
  --gold: #d9a92f;
  --red: #cf5145;
  --blue: #2f75b8;
  --green: #25885d;
  --black-disc: #111111;
  --white-disc: #f1ead9;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, #f8faf6 0%, #ecf4ef 54%, #f6f0df 100%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #121612;
  background: var(--gold);
  font-weight: 850;
  cursor: pointer;
  transition:
    transform 150ms ease,
    filter 150ms ease,
    background-color 150ms ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.52;
}

.cell:disabled {
  opacity: 1;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  outline: none;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 18px,
    calc(100% - 12px) 18px;
  background-size:
    6px 6px,
    6px 6px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(227, 184, 74, 0.18);
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

legend,
label,
.eyebrow {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li {
  margin-bottom: 8px;
}

.app {
  width: min(1160px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
}

.is-hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: 0 18px 45px rgba(27, 40, 32, 0.1);
}

.lobby {
  min-height: calc(100vh - 44px);
  display: grid;
  align-content: center;
  gap: 18px;
}

.lobby-header,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.lobby-header h1 {
  margin-top: 8px;
  font-size: clamp(2.2rem, 7vw, 5rem);
  line-height: 0.94;
}

.profile-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px 6px 12px;
  background: rgba(255, 255, 255, 0.72);
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--blue);
  background: transparent;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
  align-items: start;
}

.lobby.is-invite-mode .lobby-grid {
  grid-template-columns: minmax(320px, 720px);
}

.lobby.is-invite-mode .create-panel {
  display: none;
}

.lobby.is-invite-mode .invite-panel {
  width: 100%;
}

.create-panel,
.preview-form {
  display: grid;
  gap: 12px;
}

.create-panel h2,
.invite-panel h2 {
  font-size: 1.35rem;
}

.choice {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(31, 45, 38, 0.04);
  cursor: pointer;
}

.choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--gold);
  color: #151713;
  background: var(--gold);
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 8px;
}

.preview-content {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.preview-box,
.rules-copy,
.empty-state {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(31, 45, 38, 0.04);
}

.preview-row,
.seat-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.preview-row strong,
.seat-grid span {
  color: var(--ink);
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.topbar {
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: clamp(1.8rem, 5vw, 3.1rem);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
}

.danger-button {
  color: #fff7f2;
  background: var(--red);
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.board-section {
  display: grid;
  gap: 12px;
}

.turn-banner {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(217, 169, 47, 0.42);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.board {
  width: min(100%, 78vh);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  justify-self: center;
  border: clamp(8px, 1.3vw, 14px) solid #6f4421;
  border-radius: 8px;
  background: var(--board);
  box-shadow:
    0 20px 40px rgba(80, 56, 28, 0.22),
    inset 0 0 0 2px rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  border-radius: 0;
  border-right: 1px solid var(--board-line);
  border-bottom: 1px solid var(--board-line);
  color: var(--ink);
  background: var(--board);
  display: grid;
  place-items: center;
  padding: 0;
  perspective: 800px;
}

.cell:hover:not(:disabled) {
  background: #dcaf68;
}

.cell.is-last::after {
  content: "";
  position: absolute;
  inset: 9%;
  border: 2px solid #2f77d8;
  border-radius: 50%;
  pointer-events: none;
}

.disc,
.player-disc {
  border-radius: 50%;
  aspect-ratio: 1;
}

.disc {
  position: relative;
  width: 76%;
  display: block;
  box-shadow:
    0 6px 12px rgba(0, 0, 0, 0.36),
    inset 0 -8px 14px rgba(0, 0, 0, 0.24);
  transform-style: preserve-3d;
  will-change: transform;
}

.disc::after,
.disc-face::after {
  content: "";
  position: absolute;
  inset: 12% 14% auto auto;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  filter: blur(1px);
}

.disc.black,
.player-disc.black,
.disc.black .disc-front,
.disc.from-black .disc-back {
  background:
    radial-gradient(circle at 34% 28%, #555555, #202020 34%, #080808 72%),
    var(--black-disc);
}

.disc.white,
.player-disc.white,
.disc.white .disc-front,
.disc.from-white .disc-back {
  background:
    radial-gradient(circle at 34% 28%, #fffaf0, #dfd4bf 48%, #b8a991 100%),
    var(--white-disc);
}

.disc-face {
  position: absolute;
  inset: 0;
  display: none;
  border-radius: inherit;
  backface-visibility: hidden;
  box-shadow:
    0 6px 12px rgba(0, 0, 0, 0.36),
    inset 0 -8px 14px rgba(0, 0, 0, 0.24);
}

.disc-back {
  transform: rotateY(180deg);
}

.disc.is-placed {
  animation: disc-place 320ms cubic-bezier(0.2, 0.9, 0.22, 1.14) both;
}

.disc.is-flipping {
  animation: disc-flip 620ms cubic-bezier(0.2, 0.72, 0.22, 1) both;
  background: transparent;
  box-shadow: none;
}

.disc.is-flipping::after {
  display: none;
}

.disc.is-flipping .disc-face {
  display: block;
}

.move-hint {
  width: 28%;
  aspect-ratio: 1;
  border: 2px solid rgba(20, 22, 19, 0.72);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}

.cell.can-place .move-hint {
  box-shadow: 0 0 0 5px rgba(47, 119, 216, 0.14);
}

@keyframes disc-place {
  0% {
    opacity: 0;
    transform: translateY(-18%) scale(1.18);
  }

  62% {
    opacity: 1;
    transform: translateY(2%) scale(0.96);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes disc-flip {
  0% {
    transform: rotateY(180deg) scale(1.02);
  }

  48% {
    transform: rotateY(88deg) scale(1.08);
  }

  100% {
    transform: rotateY(0deg) scale(1);
  }
}

.side-panel {
  display: grid;
  gap: 12px;
}

.score-panel {
  display: grid;
  gap: 10px;
}

.player-card {
  min-height: 92px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(31, 45, 38, 0.04);
}

.player-card.is-turn {
  border-color: rgba(217, 169, 47, 0.86);
  box-shadow: inset 0 0 0 1px rgba(217, 169, 47, 0.32);
}

.player-card.is-dim {
  opacity: 0.72;
}

.player-disc {
  width: 42px;
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.28);
}

.player-main {
  min-width: 0;
}

.player-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-line strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-main span,
.room-meta,
.rules-panel,
.waiting-panel,
.result-stats,
.rematch-prompt {
  color: var(--muted);
  font-size: 0.9rem;
}

.self-mark {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 2px 7px;
  color: #ffffff;
  background: var(--blue);
  font-size: 0.75rem;
  font-weight: 900;
}

.clock-track {
  height: 6px;
  margin-top: 9px;
  border-radius: 999px;
  background: rgba(31, 45, 38, 0.12);
  overflow: hidden;
}

.clock-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.player-side-stat {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.clock {
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 950;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.score {
  min-width: 38px;
  text-align: right;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 850;
}

.waiting-panel,
.action-panel,
.result-panel,
.rematch-prompt {
  display: grid;
  gap: 12px;
}

.result-panel {
  gap: 14px;
}

.waiting-panel input {
  font-size: 0.86rem;
}

.room-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.room-meta span,
.stat-grid span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  background: rgba(31, 45, 38, 0.04);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-hero {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: rgba(31, 45, 38, 0.04);
}

.result-hero.is-win {
  border-color: rgba(47, 176, 115, 0.7);
}

.result-hero strong {
  font-size: 1.5rem;
}

.result-stats {
  display: grid;
  gap: 10px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-grid span {
  display: grid;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  min-height: 68px;
}

.stat-grid strong {
  color: var(--ink);
  font-size: 1.1rem;
}

.result-panel > button {
  min-height: 50px;
}

.prompt-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.name-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(238, 244, 239, 0.78);
  backdrop-filter: blur(10px);
}

.name-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface-strong);
  box-shadow: 0 24px 70px rgba(27, 40, 32, 0.18);
}

.name-card h2 {
  font-size: 2rem;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(238, 244, 239, 0.72);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
  border: 1px solid rgba(217, 169, 47, 0.38);
  border-radius: 8px;
  padding: 20px;
  background: var(--surface-strong);
  box-shadow: 0 24px 70px rgba(27, 40, 32, 0.18);
}

.modal-card h2 {
  font-size: 1.8rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 40;
  min-width: min(320px, calc(100% - 32px));
  max-width: calc(100% - 32px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 45px rgba(27, 40, 32, 0.16);
  text-align: center;
  transform: translate(-50%, 120%);
  opacity: 0;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast[data-tone="error"] {
  border-color: rgba(224, 104, 88, 0.78);
}

.toast[data-tone="success"] {
  border-color: rgba(47, 176, 115, 0.78);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confetti-fall 3.2s cubic-bezier(0.18, 0.78, 0.32, 1) forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -30px, 0) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translate3d(calc((50vw - 100%) * 0.25), 105vh, 0) rotate(720deg);
    opacity: 0;
  }
}

@media (max-width: 940px) {
  .lobby-grid,
  .game-grid {
    grid-template-columns: 1fr;
  }

  .board {
    width: min(100%, 92vw);
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-panel,
  .rules-panel {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .app {
    width: min(100% - 16px, 1160px);
    padding: 8px 0 14px;
  }

  .lobby-header,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-pill,
  .topbar-actions {
    justify-content: space-between;
  }

  .game .topbar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .game .topbar > div:first-child {
    min-width: 0;
  }

  .game .topbar .eyebrow {
    display: none;
  }

  .game .topbar h2 {
    overflow: hidden;
    font-size: clamp(1.5rem, 8vw, 1.85rem);
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .game .topbar-actions {
    flex: 0 0 auto;
    gap: 6px;
    justify-content: flex-end;
  }

  .game .topbar-actions button {
    min-height: 34px;
    padding: 0 9px;
    font-size: 0;
  }

  #copyLinkBtn::before {
    content: "Copy";
    font-size: 0.8rem;
  }

  #leaveBtn::before {
    content: "Leave";
    font-size: 0.8rem;
  }

  .game-grid {
    gap: 8px;
  }

  .board-section {
    gap: 8px;
    order: 2;
  }

  .turn-banner {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.92rem;
  }

  .topbar-actions,
  .side-panel,
  .room-meta,
  .stat-grid,
  .seat-grid {
    grid-template-columns: 1fr;
  }

  .score-panel,
  .rules-panel {
    grid-column: auto;
  }

  .side-panel {
    display: contents;
  }

  .score-panel {
    order: 1;
    gap: 6px;
    padding: 8px;
  }

  .waiting-panel,
  .rules-panel,
  .action-panel,
  .result-panel,
  .rematch-prompt {
    order: 3;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .player-card {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    min-height: 62px;
    gap: 8px;
    padding: 8px;
  }

  .player-disc {
    width: 30px;
  }

  .player-side-stat {
    grid-column: auto;
    justify-items: end;
  }

  .player-main span {
    font-size: 0.78rem;
  }

  .self-mark {
    padding: 1px 6px;
    font-size: 0.68rem;
  }

  .clock-track {
    height: 4px;
    margin-top: 5px;
  }

  .clock {
    font-size: 1.18rem;
    text-align: right;
  }

  .score {
    min-width: 26px;
    font-size: 0.9rem;
    text-align: right;
  }
}
