:root {
  --bg-deep: #141210;
  --bg-warm: #1c1916;
  --surface: rgba(34, 30, 26, 0.86);
  --surface-strong: #26221e;
  --surface-hover: #322c26;
  --border: rgba(235, 210, 175, 0.11);
  --border-strong: rgba(235, 210, 175, 0.22);

  --text-primary: #f5efe6;
  --text-secondary: #b7aa99;
  --text-muted: #7f7466;

  --accent: #e0a958;
  --accent-bright: #f2be72;
  --accent-soft: rgba(224, 169, 88, 0.16);
  --danger: #e0635a;
  --danger-soft: rgba(224, 99, 90, 0.14);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-lg: 0 22px 54px rgba(0, 0, 0, 0.55);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background:
    radial-gradient(circle at 25% 18%, rgba(224, 169, 88, 0.08), transparent 48%),
    radial-gradient(circle at 82% 82%, rgba(168, 118, 62, 0.07), transparent 46%),
    linear-gradient(160deg, var(--bg-warm) 0%, var(--bg-deep) 100%);
  color: var(--text-primary);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

.hidden {
  display: none !important;
}

/* 전체 레이아웃 */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px 20px;
  gap: 14px;
}

/* 상단 바 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-emblem {
  position: relative;
  width: 36px;
  height: 36px;
}

.emblem-stone {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

.emblem-stone.black {
  top: 2px;
  left: 2px;
  background: radial-gradient(circle at 35% 30%, #555961, #191a1e 60%, #09090b);
  border: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 2;
}

.emblem-stone.white {
  bottom: 2px;
  right: 2px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #ebe4d8 65%, #bfb6a6);
  z-index: 1;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-accent {
  color: var(--accent);
}

.brand-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 11px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  transition: all 0.16s ease;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: rgba(224, 169, 88, 0.42);
  color: var(--accent-bright);
}

.icon-glyph {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

.forbidden-glyph {
  color: var(--danger);
}

.icon-svg {
  width: 16px;
  height: 16px;
}

.icon-btn.muted .sound-waves {
  opacity: 0.2;
}

/* 메인 스테이지 */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 22px;
  align-items: center;
}

/* 보드 영역 */
.board-section {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.board-frame {
  position: relative;
  width: min(76vh, 660px, 100%);
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  padding: 10px;
  background: linear-gradient(145deg, #c79552 0%, #9b6b33 52%, #764e21 100%);
  box-shadow:
    0 28px 65px rgba(0, 0, 0, 0.62),
    0 6px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 1px rgba(255, 238, 205, 0.42),
    inset 0 -2px 4px rgba(45, 25, 8, 0.55);
}

#gomoku-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px rgba(64, 38, 14, 0.38);
}

#gomoku-canvas.busy {
  cursor: wait;
}

/* 토스트 알림 */
.toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(20, 17, 14, 0.9);
  border: 1px solid rgba(240, 212, 168, 0.25);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.warn {
  border-color: rgba(224, 99, 90, 0.55);
  color: #ffd5d1;
}

/* 바둑판 중앙 게임 시작 오버레이 */
.start-overlay {
  position: absolute;
  inset: 10px;
  border-radius: 7px;
  background: rgba(18, 15, 12, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 15;
  animation: fadeIn 0.2s ease;
}

.start-card {
  width: 100%;
  max-width: 340px;
  background: rgba(28, 24, 20, 0.94);
  border: 1px solid rgba(235, 210, 175, 0.24);
  border-radius: 20px;
  padding: 24px 22px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.start-heading {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.color-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.color-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(235, 210, 175, 0.14);
  transition: all 0.16s ease;
}

.color-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(235, 210, 175, 0.3);
}

.color-option.active {
  background: rgba(224, 169, 88, 0.14);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(224, 169, 88, 0.32), 0 8px 20px rgba(0, 0, 0, 0.3);
}

.pick-stone {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.48);
  margin-bottom: 2px;
}

.pick-stone.black {
  background: radial-gradient(circle at 34% 28%, #5b5f69, #1b1c20 58%, #070709);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.pick-stone.white {
  background: radial-gradient(circle at 34% 28%, #ffffff, #ece5d8 64%, #bab09f);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.pick-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-primary);
}

.pick-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.color-option.active .pick-sub {
  color: var(--accent-bright);
}

.start-game-btn {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f0be6e 0%, #c98a35 100%);
  color: #19120b;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  box-shadow: 0 10px 26px rgba(224, 169, 88, 0.36);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.start-game-btn:hover:not(:disabled) {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.start-game-btn:active:not(:disabled) {
  transform: translateY(0);
}

.start-game-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* 우측 HUD 패널 */
.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 플레이어 카드 */
.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
  transition: border-color 0.24s ease, box-shadow 0.24s ease;
}

.player-card.active-turn {
  border-color: rgba(224, 169, 88, 0.58);
  box-shadow: 0 0 0 1px rgba(224, 169, 88, 0.2), 0 12px 30px rgba(0, 0, 0, 0.36);
}

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stone-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
}

.black-avatar {
  background: radial-gradient(circle at 34% 28%, #5b5f69, #1b1c20 58%, #070709);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.white-avatar {
  background: radial-gradient(circle at 34% 28%, #ffffff, #ece5d8 64%, #bab09f);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.player-meta {
  flex: 1;
  min-width: 0;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.player-name {
  font-size: 0.96rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.role-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}

.black-badge {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.white-badge {
  background: rgba(245, 239, 230, 0.14);
  color: #f0e8dc;
}

.player-status {
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.player-status.accent {
  color: var(--accent-bright);
  font-weight: 500;
}

.player-status.thinking {
  color: var(--accent-bright);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.player-status.thinking::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseDot 1s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(0.8); opacity: 0.45; }
  50% { transform: scale(1.25); opacity: 1; }
}

.timer-pill {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 8px;
}

/* 형세 판단 바 */
.eval-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.eval-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.eval-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.eval-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.eval-bar-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ede5d8, #d8cfc1);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.eval-bar-black {
  height: 100%;
  background: linear-gradient(90deg, #27292e, #121316);
  border-right: 2px solid var(--accent);
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.eval-scores {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.black-pct {
  color: var(--text-primary);
}

.white-pct {
  color: var(--text-secondary);
}

/* 액션 버튼 그리드 */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-btn {
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.16s ease;
}

.action-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.action-btn:active:not(:disabled) {
  transform: translateY(0);
}

.action-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.action-btn.primary {
  background: linear-gradient(135deg, #e7b364 0%, #c88a36 100%);
  border-color: transparent;
  color: #19120b;
  box-shadow: 0 6px 16px rgba(214, 152, 66, 0.25);
}

.action-btn.primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.action-btn.danger {
  color: #f1a099;
  border-color: rgba(224, 99, 90, 0.24);
  background: var(--danger-soft);
}

.action-btn.danger:hover:not(:disabled) {
  background: rgba(224, 99, 90, 0.24);
  border-color: rgba(224, 99, 90, 0.45);
}

/* 모달 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 6, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 390px;
  background: #231f1b;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.result-card {
  text-align: center;
}

.result-emblem {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.result-emblem.win {
  background: radial-gradient(circle at 35% 30%, #f5cb86, #c68731);
  color: #1b130a;
}

.result-emblem.lose {
  background: radial-gradient(circle at 35% 30%, #ffffff, #ccc3b4);
  color: #211d18;
}

.result-emblem.draw {
  background: linear-gradient(135deg, #4b4742, #2b2723);
  color: var(--text-primary);
}

.result-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.result-subtitle {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 20px 0;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--border);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.rules-card .modal-actions {
  grid-template-columns: 1fr;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.close-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.rules-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rule-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rule-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
}

.rule-dot.black {
  background: radial-gradient(circle at 35% 30%, #555961, #141518);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.rule-dot.white {
  background: radial-gradient(circle at 35% 30%, #ffffff, #cfc6b8);
}

.rule-dot.forbidden {
  background: var(--danger-soft);
  border: 1px solid rgba(224, 99, 90, 0.45);
  color: var(--danger);
}

.rule-item strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.rule-item p {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* 반응형 (태블릿 & 모바일) */
@media (max-width: 920px) {
  .app-shell {
    padding: 10px 12px 24px;
  }

  .stage {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .board-frame {
    width: min(94vw, 600px);
    padding: 7px;
  }

  .hud-panel {
    width: min(94vw, 600px);
    margin: 0 auto;
  }

  .btn-label {
    display: none;
  }

  .icon-btn {
    padding: 0 9px;
  }
}
