:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #273549;
  --well: #0b1222;
  --line: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #fbbf24;
  --accent-hover: #fcd34d;
  --accent-ink: #1f1503;
  --loss: #fca5a5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(2, 6, 23, 0.35), 0 10px 28px rgba(2, 6, 23, 0.4);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --fast: 150ms;
  --slow: 250ms;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: radial-gradient(90rem 32rem at 50% -12rem, rgba(251, 191, 36, 0.07), transparent 70%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
}

/* Header */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.brand-mark {
  position: relative;
  flex: none;
  width: 30px;
  height: 30px;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  width: 19px;
  height: 19px;
  border-radius: 50%;
}

.brand-mark::before {
  left: 0;
  top: 0;
  background: radial-gradient(circle at 35% 30%, #6b7280, #1f2329 45%, #050608);
}

.brand-mark::after {
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 35% 30%, #ffffff, #ece8df 55%, #bdb4a2);
  box-shadow: 0 0 0 2px var(--bg);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease),
    color var(--fast) var(--ease),
    box-shadow var(--slow) var(--ease),
    transform var(--fast) var(--ease);
}

.btn:hover {
  background: var(--surface-hover);
  border-color: rgba(148, 163, 184, 0.32);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  border-color: transparent;
  background: var(--accent-hover);
}

.btn-primary.is-attention {
  animation: attention 2s ease-in-out infinite;
}

/* A soft glow that swells and fades, so any single frame still reads as light */
@keyframes attention {
  50% {
    box-shadow: 0 0 18px 2px rgba(251, 191, 36, 0.5);
  }
}

.btn[aria-pressed="true"] {
  border-color: rgba(251, 191, 36, 0.6);
  background: rgba(251, 191, 36, 0.14);
  color: var(--accent);
}

.lang-btn {
  padding: 0 10px;
  letter-spacing: 0.04em;
}

/* Layout: one column on phones, board plus side panel when there is room */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: min(100%, 600px, max(260px, 100vh - 205px));
  grid-template-columns: min(100%, 600px, max(260px, 100svh - 205px));
  grid-template-areas:
    "status"
    "board"
    "actions"
    "settings";
  justify-content: center;
  align-content: start;
  gap: 10px;
  width: 100%;
  padding: 4px 8px 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Status */

.status {
  grid-area: status;
  display: grid;
  gap: 4px;
  padding: 10px 14px;
  transition:
    border-color var(--slow) var(--ease),
    background-color var(--slow) var(--ease);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.status-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1.08rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hint {
  min-height: calc(2 * 1.35em);
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.status[data-tone="win"] {
  border-color: rgba(251, 191, 36, 0.65);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.16), rgba(251, 191, 36, 0.03)), var(--surface);
}

.status[data-tone="win"] .status-text {
  color: var(--accent);
}

.status[data-tone="loss"] .status-text {
  color: var(--loss);
}

.status[data-tone="thinking"] .status-text::after {
  content: "...";
  display: inline-block;
  width: 0;
  overflow: hidden;
  vertical-align: bottom;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  to {
    width: 1.1em;
  }
}

.stone-dot,
.chip-stone {
  flex: none;
  border-radius: 50%;
}

.stone-dot {
  width: 22px;
  height: 22px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.status[data-tone="thinking"] .stone-dot {
  animation: breathe 1.2s ease-in-out infinite;
}

@keyframes breathe {
  50% {
    transform: scale(0.82);
    opacity: 0.7;
  }
}

.chip-stone {
  width: 14px;
  height: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

[data-stone="black"] {
  background: radial-gradient(circle at 35% 30%, #6b7280, #1f2329 45%, #050608);
}

[data-stone="white"] {
  background: radial-gradient(circle at 35% 30%, #ffffff, #ece8df 55%, #bdb4a2);
}

[data-stone="none"] {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--muted);
}

/* Board */

.board-frame {
  grid-area: board;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: #dbad66;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35), 0 18px 42px rgba(2, 6, 23, 0.6);
}

.board {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board:focus {
  outline: none;
}

.board:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.board.is-waiting {
  cursor: progress;
}

/* Actions and settings */

.actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  container-type: inline-size;
}

.actions .btn {
  padding: 0 10px;
}

/*
 * The three-button row is 260-600 px wide depending on the layout, and the
 * longest label ("Numaralar") needs about 390 px at full size. Narrower rows
 * first tighten the buttons, then drop the icons, then shrink the text.
 */
@container (max-width: 389px) {
  .actions .btn {
    gap: 5px;
    padding: 0 6px;
    font-size: 0.875rem;
  }
}

@container (max-width: 337px) {
  .actions .btn svg {
    display: none;
  }
}

@container (max-width: 267px) {
  .actions .btn {
    padding: 0 4px;
    font-size: 0.8125rem;
  }
}

.settings {
  grid-area: settings;
  display: none;
  gap: 14px;
  padding: 14px;
}

.settings.is-open {
  display: grid;
}

.field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field legend {
  margin-bottom: 6px;
  padding: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--well);
}

.segmented label {
  position: relative;
  display: block;
  min-width: 0;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 4px 8px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease);
}

.segmented label:hover input:not(:checked):not(:disabled) + .seg {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
}

.segmented input:checked + .seg {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.segmented input:focus-visible + .seg {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field:disabled .segmented {
  opacity: 0.45;
}

.field:disabled input {
  cursor: not-allowed;
}

/* Footer */

.footer {
  display: flex;
  justify-content: center;
  padding: 0 12px 10px;
}

.footer a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.88rem;
  text-decoration: none;
  transition: color var(--fast) var(--ease);
}

.footer a:hover {
  color: var(--accent);
}

.footer a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Very narrow phones */

@media (max-width: 359px) {
  .topbar {
    padding-inline: 8px;
  }

  .brand h1 {
    font-size: 1.15rem;
  }

  #new-game svg {
    display: none;
  }
}

/* Landscape: board on the left, panel on the right */

@media (orientation: landscape) and (min-width: 640px), (orientation: landscape) and (min-width: 560px) and (max-height: 430px) {
  .layout {
    grid-template-columns: min(100vh - 136px, 100% - 344px, 860px) minmax(0, 320px);
    grid-template-columns: min(100svh - 136px, 100% - 344px, 860px) minmax(0, 320px);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "board status"
      "board actions"
      "board settings";
    column-gap: 24px;
    row-gap: 12px;
    padding: 8px 24px 16px;
  }

  .topbar {
    padding-inline: 24px;
  }

  .settings {
    align-self: start;
  }
}

/* Short landscape screens (phones): the footer may scroll, the board may not */

@media (orientation: landscape) and (min-width: 640px) and (max-height: 520px), (orientation: landscape) and (min-width: 560px) and (max-height: 430px) {
  .topbar {
    min-height: 48px;
    padding-block: 4px;
  }

  .layout {
    grid-template-columns: min(100vh - 64px, 100% - 300px, 860px) minmax(0, 300px);
    grid-template-columns: min(100svh - 64px, 100% - 300px, 860px) minmax(0, 300px);
    column-gap: 16px;
    row-gap: 8px;
    padding: 4px 16px 12px;
  }

  .hint {
    min-height: 0;
  }
}

/* Roomy screens show the settings all the time */

@media (orientation: landscape) and (min-width: 900px) and (min-height: 620px) {
  .settings {
    display: grid;
  }

  /* Two buttons share the row here, so the narrow-row steps above stay off */
  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    container-type: normal;
  }

  .settings-toggle {
    display: none;
  }

  .brand h1 {
    font-size: 1.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .status[data-tone="thinking"] .status-text::after {
    width: auto;
    animation: none;
  }
}
