:root {
  --bg: #f4efe4;
  --bg-accent: #e8dcc0;
  --panel: rgba(255, 251, 244, 0.82);
  --panel-border: rgba(73, 48, 20, 0.14);
  --text: #2d1f12;
  --muted: #736352;
  --primary: #b85c38;
  --primary-dark: #8f4225;
  --shadow: 0 28px 60px rgba(68, 43, 20, 0.18);
  --board-light: #deb878;
  --board-dark: #c79b56;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.5), transparent 30%),
    radial-gradient(circle at bottom right, rgba(184, 92, 56, 0.12), transparent 25%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 90%);
}

.layout {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.hero h1,
.status-row h2,
.result-card h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: -0.04em;
}

.hero h1 {
  font-size: clamp(2.5rem, 6vw, 4.4rem);
  line-height: 0.94;
  max-width: 8ch;
}

.eyebrow,
.subtitle,
.status-label,
.control-label,
.result-kicker,
.room-meta,
.room-code {
  margin: 0;
}

.eyebrow,
.status-label,
.control-label,
.result-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  color: var(--muted);
}

.subtitle {
  margin-top: 14px;
  font-size: 1rem;
  line-height: 1.7;
  max-width: 30ch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.controls {
  margin-top: 28px;
  padding: 20px;
  display: grid;
  gap: 18px;
}

.control-group {
  display: grid;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.segmented-3 {
  grid-template-columns: repeat(3, 1fr);
}

.segment,
.action-button,
.room-input {
  border: 0;
  border-radius: 16px;
  padding: 13px 14px;
  font: inherit;
}

.segment,
.action-button {
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.segment {
  background: rgba(73, 48, 20, 0.08);
  color: var(--text);
}

.segment.active {
  background: var(--text);
  color: #fff7ef;
  box-shadow: 0 10px 24px rgba(45, 31, 18, 0.24);
}

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

.action-button {
  background: rgba(73, 48, 20, 0.08);
  color: var(--text);
}

.action-button.primary {
  background: var(--primary);
  color: #fff8f2;
}

.action-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.segment:hover,
.action-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.online-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.room-meta {
  margin-top: 6px;
  font-size: 0.96rem;
  color: var(--text);
}

.room-code {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.05rem;
  color: var(--primary-dark);
}

.room-list-wrap {
  display: grid;
  gap: 10px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.room-list {
  display: grid;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
}

.room-list-card,
.room-list-empty {
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(73, 48, 20, 0.08);
}

.room-list-card {
  display: grid;
  gap: 10px;
}

.room-list-top,
.room-list-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-list-empty,
.room-mini {
  color: var(--muted);
  font-size: 0.92rem;
}

.room-id {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.1rem;
}

.room-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.room-tag {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(73, 48, 20, 0.08);
  color: var(--muted);
}

.room-badge {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  white-space: nowrap;
}

.room-badge.online {
  background: rgba(45, 135, 88, 0.12);
  color: #23684b;
}

.room-badge.waiting {
  background: rgba(184, 92, 56, 0.12);
  color: var(--primary-dark);
}

.room-badge.offline {
  background: rgba(45, 31, 18, 0.09);
  color: var(--muted);
}

.room-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.62);
  color: var(--text);
  outline: 1px solid rgba(73, 48, 20, 0.08);
}

.room-input:focus {
  outline: 2px solid rgba(184, 92, 56, 0.35);
}

.board-area {
  min-width: 0;
}

.game-panel {
  padding: 20px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.status-row h2 {
  margin-top: 6px;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.95rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stone {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid rgba(45, 31, 18, 0.18);
}

.stone.black {
  background: linear-gradient(135deg, #555, #050505 70%);
}

.stone.white {
  background: linear-gradient(135deg, #ffffff, #ddd7cf 70%);
}

.board-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 28px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, var(--board-light), var(--board-dark));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.result-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: radial-gradient(circle at center, rgba(255, 248, 239, 0.08), rgba(45, 31, 18, 0.58));
  backdrop-filter: blur(4px);
  animation: fade-in 240ms ease;
}

.result-card {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  padding: 26px 22px;
  text-align: center;
  border-radius: 24px;
  background: rgba(255, 248, 239, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 22px 60px rgba(45, 31, 18, 0.3);
}

.result-card h3 {
  margin-top: 8px;
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 0.95;
}

.result-subtitle {
  margin: 10px 0 18px;
  color: var(--muted);
}

.result-rings {
  position: absolute;
  inset: 0;
}

.result-rings span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 999px;
  border: 1px solid rgba(255, 248, 239, 0.26);
  transform: translate(-50%, -50%) scale(0.72);
  animation: ring-pulse 2.3s ease-out infinite;
}

.result-rings span:nth-child(2) {
  animation-delay: 0.35s;
}

.result-rings span:nth-child(3) {
  animation-delay: 0.7s;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(45, 31, 18, 0.92);
  color: #fff8f2;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 0.95rem;
  box-shadow: 0 18px 40px rgba(45, 31, 18, 0.28);
  animation: toast-in 180ms ease forwards;
}

.hidden {
  display: none !important;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes ring-pulse {
  0% {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(0.55);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.4);
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .hero h1,
  .subtitle {
    max-width: none;
  }
}

@media (max-width: 680px) {
  .layout {
    width: min(100% - 20px, 100%);
    padding-top: 20px;
    gap: 20px;
  }

  .controls,
  .game-panel {
    padding: 16px;
  }

  .segmented,
  .segmented-3,
  .actions,
  .room-actions,
  .join-row {
    grid-template-columns: 1fr;
  }

  .status-row,
  .online-summary {
    align-items: flex-start;
    flex-direction: column;
  }
}
