:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: rgba(255,255,255,0.07);
  --panel-strong: rgba(255,255,255,0.11);
  --line: rgba(255,255,255,0.13);
  --text: #f4f0e8;
  --muted: #b7b0a4;
  --accent: #ffb35c;
  --accent-strong: #ff8c2e;
  --danger: #ff6969;
  --ok: #76e6aa;
  --black-stone: #191a1e;
  --white-stone: #f8f0df;
  --cell: #d7a462;
  --cell-hover: #e2b777;
  --cell-selected: #f2c989;
  --shadow: 0 20px 60px rgba(0,0,0,0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255,179,92,0.22), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(107,136,255,0.16), transparent 30rem),
    var(--bg);
}

button, input { font: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }

.app-shell {
  width: min(1160px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 42px;
  padding-bottom: calc(42px + env(safe-area-inset-bottom));
}

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

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 5vw, 4rem); letter-spacing: -0.06em; }
h2 { margin-bottom: 10px; font-size: clamp(1.45rem, 3vw, 2.35rem); letter-spacing: -0.04em; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.74rem;
  font-weight: 800;
}

.muted { color: var(--muted); line-height: 1.6; }
.hidden { display: none !important; }

.card {
  background: linear-gradient(145deg, var(--panel), rgba(255,255,255,0.035));
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-card {
  min-height: 520px;
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  align-items: center;
  gap: 28px;
  padding: clamp(24px, 6vw, 64px);
  overflow: hidden;
  position: relative;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -90px;
  bottom: -120px;
  width: 420px;
  height: 420px;
  background:
    radial-gradient(circle at 33% 33%, var(--black-stone) 0 9%, transparent 10%),
    radial-gradient(circle at 66% 33%, var(--white-stone) 0 9%, transparent 10%),
    radial-gradient(circle at 33% 66%, var(--white-stone) 0 9%, transparent 10%),
    radial-gradient(circle at 66% 66%, var(--black-stone) 0 9%, transparent 10%),
    linear-gradient(135deg, rgba(255,179,92,0.42), rgba(255,255,255,0.08));
  border-radius: 48px;
  transform: rotate(-12deg);
  opacity: 0.28;
  pointer-events: none;
}

.hero-copy, .action-grid { position: relative; z-index: 1; }
.action-grid { display: grid; gap: 14px; }

.primary-btn, .secondary-btn, .ghost-btn, .tiny-btn, .text-btn {
  border: 0;
  border-radius: 18px;
  min-height: 48px;
  padding: 0 20px;
  font-weight: 800;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .tiny-btn:hover { transform: translateY(-1px); }

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #261409;
}
.secondary-btn {
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}
.ghost-btn {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}
.tiny-btn {
  min-height: 34px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}
.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: auto;
  padding: 0;
  margin-bottom: 18px;
  color: var(--muted);
  background: transparent;
}
.text-btn:hover { color: var(--text); }

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill-muted { color: var(--muted); background: rgba(255,255,255,0.06); }
.pill-ok { color: #052312; background: var(--ok); border-color: transparent; }
.pill-bad { color: #290606; background: var(--danger); border-color: transparent; }

#joinScreen, #lobbyScreen {
  padding: clamp(22px, 5vw, 44px);
}

.join-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.join-row input {
  flex: 1;
  min-width: 0;
  height: 56px;
  color: var(--text);
  background: rgba(0,0,0,0.24);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0 18px;
  font-size: 1.15rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.lobby-layout {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 28px;
}
.code-box {
  display: grid;
  gap: 12px;
  min-width: 230px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--line);
  text-align: center;
}
#roomCodeText {
  font-size: 2.6rem;
  font-weight: 1000;
  letter-spacing: 0.14em;
}
.waiting-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  color: var(--muted);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.game-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 20px;
  align-items: start;
}
.side-panel { padding: 22px; position: sticky; top: 18px; }
.panel-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.panel-actions { padding-top: 16px; }
.panel-actions button { width: 100%; }
.room-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-line strong { font-size: 1.5rem; letter-spacing: 0.12em; }

.player-list { display: grid; gap: 10px; }
.player-chip {
  display: grid;
  grid-template-columns: 22px 1fr;
  column-gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(0,0,0,0.16);
}
.player-chip span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 2px 6px rgba(255,255,255,0.16), 0 5px 10px rgba(0,0,0,0.18);
}
.player-chip small { grid-column: 2; color: var(--muted); }
.player-black span { background: var(--black-stone); border: 1px solid rgba(255,255,255,0.16); }
.player-white span { background: var(--white-stone); border: 1px solid rgba(0,0,0,0.18); }
.player-active { outline: 2px solid var(--accent); }
.rules-box ol { margin: 0 0 0 20px; padding: 0; color: var(--muted); line-height: 1.75; }

.board-area { display: grid; gap: 16px; }

.mobile-status {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 18px;
}
.mobile-back {
  margin: 0;
  font-size: 1.3rem;
  min-width: 34px;
  min-height: 34px;
  display: grid;
  place-items: center;
}
.mobile-status-copy { display: grid; min-width: 0; }
.mobile-status-copy strong { font-size: 1.02rem; letter-spacing: -0.02em; }
.mobile-status-copy small { line-height: 1.35; }
.turn-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: none;
}
.turn-dot.dot-black { background: var(--black-stone); border: 2px solid rgba(255,255,255,0.35); }
.turn-dot.dot-white { background: var(--white-stone); border: 2px solid rgba(0,0,0,0.3); }
.turn-dot.dot-idle { background: var(--muted); opacity: 0.4; }
.turn-dot.dot-pulse { animation: dotPulse 1.1s ease-in-out infinite; }
@keyframes dotPulse {
  50% { transform: scale(1.3); box-shadow: 0 0 12px rgba(255,179,92,0.8); }
}

.board {
  width: min(100%, 650px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: clamp(8px, 1.8vw, 13px);
  padding: clamp(10px, 2.2vw, 16px);
  border-radius: 32px;
  background: linear-gradient(135deg, #3b2310, #5b361b);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 30px 80px rgba(0,0,0,0.38), inset 0 3px 16px rgba(0,0,0,0.5);
  -webkit-user-select: none;
  user-select: none;
}
.quadrant {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  min-width: 0;
  min-height: 0;
  border-radius: clamp(10px, 2vw, 18px);
  overflow: hidden;
  background: linear-gradient(135deg, #7a4a1e, #bf7d35);
  box-shadow: inset 0 2px 12px rgba(255,255,255,0.14), 0 6px 18px rgba(0,0,0,0.28);
  transition: transform 0.52s cubic-bezier(0.25, 0.9, 0.3, 1.05), box-shadow 0.2s ease;
  will-change: transform;
}
.quadrant.spin-cw, .quadrant.spin-ccw { position: relative; z-index: 2; }
.quadrant.spin-cw { transform: rotate(90deg); }
.quadrant.spin-ccw { transform: rotate(-90deg); }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(64,30,6,0.26);
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.18), transparent 34%),
    var(--cell);
  min-width: 0;
  min-height: 0;
  padding: 0;
}
.cell:hover:not(:disabled) { background: var(--cell-hover); }
.cell.selected { background: var(--cell-selected); }
.cell.last-move::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 3px solid rgba(255,255,255,0.38);
  border-radius: 50%;
  pointer-events: none;
}
.cell.win-cell { background: var(--cell-selected); }
.cell.win-cell .marble {
  box-shadow: 0 0 0 3px var(--accent), 0 0 18px rgba(255,179,92,0.65), inset 0 9px 16px rgba(255,255,255,0.2);
  animation: winPulse 1.2s ease-in-out infinite;
}
@keyframes winPulse {
  50% { transform: scale(1.09); }
}
.marble, .ghost-marble {
  width: 68%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 9px 16px rgba(255,255,255,0.2), inset 0 -12px 16px rgba(0,0,0,0.24), 0 8px 14px rgba(0,0,0,0.28);
}
.marble.pop { animation: pop 0.26s cubic-bezier(0.34, 1.45, 0.5, 1); }
@keyframes pop {
  from { transform: scale(0.15); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}
.marble.black, .ghost-marble.black { background: var(--black-stone); border: 1px solid rgba(255,255,255,0.16); }
.marble.white, .ghost-marble.white { background: var(--white-stone); border: 1px solid rgba(0,0,0,0.24); }
.ghost-marble { opacity: 0.55; }

.move-helper {
  width: min(100%, 650px);
  margin: 0 auto;
  padding: 14px 18px;
  color: var(--muted);
  line-height: 1.45;
}
.quad-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3.4vw, 22px);
  pointer-events: none;
  z-index: 3;
  animation: overlayIn 0.18s ease;
}
@keyframes overlayIn {
  from { opacity: 0; transform: scale(0.88); }
}
.rot-btn {
  pointer-events: auto;
  width: clamp(44px, 12vw, 58px);
  height: clamp(44px, 12vw, 58px);
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(17, 19, 24, 0.84);
  color: var(--accent);
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  font-weight: 900;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(0,0,0,0.45);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.rot-btn:hover {
  background: var(--accent);
  color: #261409;
  transform: scale(1.1);
}
.rot-btn:active { transform: scale(0.96); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 28px));
  padding: 13px 16px;
  color: #250f0f;
  background: #ffd6d6;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 800;
  z-index: 10;
}

@media (max-width: 900px) {
  .hero-card, .lobby-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }

  /* Tahta en üstte: durum çubuğu + tahta + yardım metni, panel altta. */
  .game-layout { display: flex; flex-direction: column; }
  .board-area { order: -1; }
  .mobile-status { display: flex; }
  .side-panel .status-section { display: none; }
  .side-panel > .text-btn { display: none; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 16px, 1160px); padding-top: 12px; }
  .topbar { margin-bottom: 14px; }
  .topbar .eyebrow { display: none; }
  h1 { font-size: 1.45rem; letter-spacing: -0.03em; }
  .pill { padding: 6px 10px; font-size: 0.74rem; }
  .join-row { flex-direction: column; }
  .hero-card { min-height: auto; }
  #roomCodeText { font-size: 2rem; }
  .card { border-radius: 20px; }
  .side-panel { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .quadrant { transition: none; }
  .marble.pop { animation: none; }
  .cell.win-cell .marble { animation: none; }
  .turn-dot.dot-pulse { animation: none; }
  .quad-overlay { animation: none; }
  .spinner { animation-duration: 1.6s; }
}
