@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&family=Noto+Sans+KR:wght@300;400;500;700&display=swap');

:root {
  --primary-color: #8b00c5;
  --primary-glow: rgba(139, 0, 197, 0.3);
  --bg-dark: #0f0a1c;
  --bg-card: rgba(25, 18, 41, 0.7);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f3effa;
  --text-muted: #a69bb8;
  --accent: #ff007f;
  
  --board-wood-light: #e4b971;
  --board-wood-dark: #c0924a;
  --board-border: #755222;
  --grid-line: rgba(74, 51, 25, 0.45);
  
  --font-family: 'Outfit', 'Noto Sans KR', sans-serif;
  
  /* Responsive Board Size Variables (responsive to both width and height) */
  --board-size: min(90vw, 68vh, 600px);
  --cell-size: calc(var(--board-size) / 15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 10% 20%, rgba(26, 12, 51, 0.8) 0px, transparent 50%),
    radial-gradient(at 90% 80%, rgba(13, 3, 26, 0.9) 0px, transparent 50%),
    radial-gradient(at 50% 50%, #0d0615 0px, transparent 100%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow-x: hidden;
}

header {
  width: 100%;
  max-width: 1200px;
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  text-shadow: 0 0 20px var(--primary-glow);
}

.logo span {
  color: var(--primary-color);
}

.header-controls {
  display: flex;
  gap: 0.8rem;
}

button.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 0.6rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  backdrop-filter: blur(10px);
}

button.btn-icon:hover {
  background: var(--primary-color);
  border-color: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-glow);
  transform: translateY(-2px);
}

button.btn-icon:active {
  transform: translateY(0);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  gap: 2rem;
  padding: 1rem 1.5rem 2rem 1.5rem;
}

@media (min-width: 992px) {
  main {
    grid-template-columns: 1.2fr 0.8fr;
    align-items: start;
    padding-top: 2rem;
  }
}

/* Left Section: Game Board Container */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  width: 100%;
}

.status-bar {
  width: var(--board-size);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  padding: 0.8rem 1.2rem;
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(10px);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 1.1rem;
}

.turn-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #000;
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
  transition: all 0.3s ease;
}

.turn-dot.white {
  background-color: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

.game-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* 3D Realistic Wooden Board */
.omok-board {
  width: var(--board-size);
  height: var(--board-size);
  background: radial-gradient(circle, var(--board-wood-light), var(--board-wood-dark));
  border: 10px solid var(--board-border);
  border-radius: 16px;
  box-shadow: 
    inset 0 0 15px rgba(0, 0, 0, 0.25),
    0 15px 35px rgba(0, 0, 0, 0.5),
    0 5px 15px rgba(0, 0, 0, 0.3);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  position: relative;
  touch-action: none;
  overflow: hidden;
}

.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Continuous Grid lines inside cells */
.board-cell::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: var(--grid-line);
  z-index: 1;
}

.board-cell::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  background-color: var(--grid-line);
  z-index: 1;
}

/* Edge Corrections for Grid Lines */
.board-cell.row-0::after { top: 50%; height: 50%; }
.board-cell.row-14::after { height: 50%; }
.board-cell.col-0::before { left: 50%; width: 50%; }
.board-cell.col-14::before { width: 50%; }

/* Star Points (화점) at 3, 7, 11 */
.board-cell.star-point::before,
.board-cell.star-point::after {
  /* Keep standard grid lines active */
}

.board-cell.star-point .star-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background-color: #3b250d;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* Board Keyboard Cursor Overlay */
.board-cell.keyboard-cursor {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: 0 0 10px var(--accent);
  z-index: 5;
}

/* Realistic Stones with Glossy 3D Gradients */
.stone {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  z-index: 3;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform: scale(0.95);
}

.stone.black {
  background: radial-gradient(circle at 35% 35%, #4f4f4f 0%, #151515 60%, #000000 100%);
  box-shadow: 
    1px 2px 4px rgba(0, 0, 0, 0.6),
    inset -1px -2px 3px rgba(0, 0, 0, 0.8),
    inset 1px 2px 2px rgba(255, 255, 255, 0.25);
}

.stone.white {
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, #f4f3f0 35%, #d1cfc7 75%, #b5b2a7 100%);
  box-shadow: 
    1px 2px 4px rgba(0, 0, 0, 0.4),
    inset -1px -2px 3px rgba(0, 0, 0, 0.2),
    inset 1px 2px 2px rgba(255, 255, 255, 0.9);
}

/* Highlight the last placed stone */
.stone.last-placed::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px var(--accent);
}

/* Stone Hover Previews */
.board-cell:hover:not(.has-stone) .stone-preview {
  opacity: 0.4;
  transform: scale(0.85);
}

.stone-preview {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  opacity: 0;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.stone-preview.black {
  background: #000;
  border: 1px dashed rgba(255,255,255,0.5);
}

.stone-preview.white {
  background: #fff;
  border: 1px dashed rgba(0,0,0,0.5);
}

/* Thinking & Progress Indicator */
.thinking-bar-container {
  width: var(--board-size);
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.thinking-bar-container.active {
  opacity: 1;
}

.thinking-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-color), var(--accent));
  box-shadow: 0 0 10px var(--primary-color);
  transition: width 0.1s linear;
}

/* Right Section: Control Panel & Leaderboard */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
  max-width: var(--board-size);
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: 20px;
  padding: 1.5rem;
  backdrop-filter: blur(15px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.card-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Difficulty Selection Tab */
.difficulty-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.3rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.05);
}

.diff-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.6rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.diff-btn.active {
  background: var(--primary-color);
  color: var(--text-main);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.diff-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.diff-btn:disabled::after {
  content: '🔒';
  position: absolute;
  font-size: 0.65rem;
  top: 2px;
  right: 2px;
}

/* Action Control Buttons */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 1.2rem;
}

button.btn-action {
  padding: 0.8rem;
  border-radius: 12px;
  border: none;
  font-family: var(--font-family);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
}

button.btn-action.btn-undo {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

button.btn-action.btn-undo:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

button.btn-action.btn-reset {
  background: linear-gradient(135deg, var(--primary-color), #500096);
  color: var(--text-main);
  box-shadow: 0 4px 15px var(--primary-glow);
}

button.btn-action.btn-reset:hover {
  filter: brightness(1.15);
  transform: translateY(-2px);
}

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

button.btn-action:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none !important;
}

/* Leaderboard Glass Table */
.leaderboard-container {
  max-height: 250px;
  overflow-y: auto;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255,255,255,0.05);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.leaderboard-table th, 
.leaderboard-table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.leaderboard-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1;
}

.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.leaderboard-table td.rank-highlight {
  font-weight: 700;
  color: var(--accent);
}

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  color: var(--text-muted);
  gap: 0.8rem;
}

.loader-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Shortcuts Info Help Grid */
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.shortcut-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0,0,0,0.15);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
}

.shortcut-key {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.75rem;
  border-bottom: 2px solid rgba(0,0,0,0.3);
}

/* Overlay & Modal Design */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(6, 4, 12, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: radial-gradient(circle at 0% 0%, #1e1533, #0d0615);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: min(90vw, 420px);
  padding: 2rem;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 700;
}

.modal-title.win {
  color: #ffb700;
  text-shadow: 0 0 15px rgba(255, 183, 0, 0.3);
}

.modal-title.lose {
  color: var(--text-muted);
}

.score-stats {
  background: rgba(0,0,0,0.25);
  padding: 1rem;
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

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

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.name-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.name-input-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

input.name-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.8rem;
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 1rem;
  outline: none;
  transition: all 0.3s ease;
}

input.name-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 10px var(--primary-glow);
  background: rgba(255, 255, 255, 0.08);
}

.modal-buttons {
  display: flex;
  gap: 0.8rem;
  margin-top: 0.5rem;
}

button.btn-modal {
  flex: 1;
  padding: 0.8rem;
  border-radius: 12px;
  border: none;
  font-family: var(--font-family);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
}

button.btn-modal.primary {
  background: linear-gradient(135deg, var(--primary-color), #500096);
  color: var(--text-main);
  box-shadow: 0 4px 15px var(--primary-glow);
}

button.btn-modal.primary:hover {
  filter: brightness(1.15);
}

button.btn-modal.secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

button.btn-modal.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

footer {
  width: 100%;
  padding: 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(255,255,255,0.03);
}

/* Animations */
@keyframes popIn {
  from { transform: scale(0.8) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.board-cell.has-stone .stone {
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
}
