:root {
  --bg: #f4ead5;
  --panel: #d9b77a;
  --board: #d99f45;
  --line: #5c3714;
  --black: #111111;
  --white: #f7f7f7;
  --shadow: rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #efe7d5, #d9c9a3);
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: #2d1f10;
}

.page-shell {
  width: min(98vw, 1268px);
  display: grid;
  grid-template-columns: 160px minmax(0, 900px) 160px;
  align-items: start;
  gap: 24px;
}

.ad-rail {
  position: sticky;
  top: 24px;
  display: flex;
  justify-content: center;
}

.ad-slot {
  width: 160px;
  height: 600px;
  display: grid;
  place-content: center;
  gap: 7px;
  border: 1px dashed rgba(92, 55, 20, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: rgba(45, 31, 16, 0.42);
  text-align: center;
}

.ad-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.ad-slot strong {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.app {
  width: min(94vw, 900px);
  background: rgba(255, 255, 255, 0.2);
  border: 3px solid rgba(92, 55, 20, 0.45);
  border-radius: 20px;
  box-shadow: 0 18px 45px var(--shadow);
  padding: 24px;
}

[hidden] {
  display: none !important;
}

.connection-pill,
.rule-pill {
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(92, 55, 20, 0.12);
  font-size: 0.82rem;
  font-weight: 800;
}

.connection-pill.connected {
  color: #176b3a;
  background: rgba(35, 145, 81, 0.12);
}

.intro h2 {
  margin: 0 0 8px;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.intro p,
.action-card p {
  margin: 0;
  color: rgba(45, 31, 16, 0.68);
  line-height: 1.55;
}

.nickname-field {
  max-width: 420px;
  margin: 24px 0 18px;
}

.field {
  display: grid;
  gap: 7px;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid rgba(92, 55, 20, 0.35);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.64);
  color: inherit;
  font: inherit;
  padding: 12px 13px;
}

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

.action-card {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid rgba(92, 55, 20, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.3);
}

.action-card h3 { margin: 0; font-size: 1.25rem; }
.card-number { font-size: 0.75rem; font-weight: 900; letter-spacing: 0.15em; opacity: 0.55; }

.primary-button,
.secondary-button,
.small-button,
.text-button {
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  padding: 12px 16px;
}

.primary-button { background: #2d1f10; color: white; }
.secondary-button { background: #b16a24; color: white; }
.small-button { padding: 8px 11px; background: rgba(45, 31, 16, 0.12); }
.text-button { margin-left: auto; padding: 8px 10px; background: transparent; color: #74411b; }
button:disabled { cursor: not-allowed; }

.message {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: #a33b25;
  font-weight: 800;
}

.timer-display {
  min-width: 64px;
  margin-left: auto;
  color: #2d1f10;
  font-size: 1.25rem;
  text-align: right;
}

.timer-display.urgent {
  color: #c52f24;
  animation: timer-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes timer-pulse {
  to { transform: scale(1.08); }
}

.room-bar,
.players {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.meta-label { display: block; font-size: 0.72rem; font-weight: 800; opacity: 0.62; }
.room-code { font-size: 1.35rem; letter-spacing: 0.12em; }
.players { display: grid; grid-template-columns: 1fr 1fr; }
.player-card { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 11px; background: rgba(255,255,255,.3); font-weight: 800; }
.stone-sample { width: 22px; height: 22px; border-radius: 50%; }
.stone-sample.black { background: #111; }
.stone-sample.white { background: #f7f7f7; border: 1px solid #aaa; }

.cell.last-move::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: #d84b35;
  transform: translate(-50%, -50%);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 20px;
}

.label {
  margin: 0 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(45, 31, 16, 0.72);
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2vw, 2.6rem);
}

.reset-button {
  border: none;
  border-radius: 12px;
  background: #2d1f10;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.reset-button:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(92, 55, 20, 0.2);
}

.turn-wrap,
.record-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.turn-label,
.record-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: rgba(45, 31, 16, 0.76);
}

.turn-display,
.record-display {
  font-weight: 800;
}

.turn-display.black {
  color: var(--black);
}

.turn-display.white {
  color: #5e5e5e;
}

.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  background: var(--board);
  border: 5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 1;
  box-shadow: inset 0 0 0 2px rgba(92, 55, 20, 0.18);
}

.cell {
  position: relative;
  border: none;
  background:
    linear-gradient(
      to right,
      transparent calc(50% - 0.5px),
      rgba(92, 55, 20, 0.78) calc(50% - 0.5px),
      rgba(92, 55, 20, 0.78) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    ),
    linear-gradient(
      to bottom,
      transparent calc(50% - 0.5px),
      rgba(92, 55, 20, 0.78) calc(50% - 0.5px),
      rgba(92, 55, 20, 0.78) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    );
  cursor: pointer;
  aspect-ratio: 1;
  transition: filter 0.08s ease;
}

.cell:hover {
  filter: brightness(1.08);
}

.cell:focus-visible {
  outline: 2px solid #1d3d7a;
  outline-offset: -2px;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 68%;
  height: 68%;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.cell.black::before {
  opacity: 1;
  background: radial-gradient(circle at 35% 35%, #4a4a4a 0%, #111111 38%, #000000 100%);
  box-shadow: inset -5px -5px 12px rgba(255, 255, 255, 0.1);
}

.cell.white::before {
  opacity: 1;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #ebeaea 38%, #d7d7d7 100%);
  box-shadow: inset -5px -5px 12px rgba(0, 0, 0, 0.08);
}

@media (max-width: 560px) {
  .app {
    padding: 16px;
  }

  .header,
  .status-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .reset-button {
    width: 100%;
  }

  .lobby-actions,
  .players {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1299px) {
  .page-shell {
    width: min(94vw, 900px);
    display: block;
  }

  .ad-rail {
    display: none;
  }
}
