/* Tema: miracdeprem.com "Gece Şehri" paleti. Renkler RGB üçlüsü; rgb(var(--c-accent) / 0.3) ile saydamlık verilebilir. */
:root {
  --c-bg: 11 15 21;
  --c-surface: 19 26 37;
  --c-elevated: 27 36 50;
  --c-line: 41 52 68;
  --c-ink: 236 239 244;
  --c-muted: 156 167 184;
  --c-subtle: 107 120 139;
  --c-accent: 245 199 126;
  --c-accent-strong: 255 217 154;
  --c-accent-ink: 26 19 5;
  --c-o: 130 170 255;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sky: radial-gradient(1200px 600px at 85% -10%, rgb(245 199 126 / 0.07), transparent 60%),
    radial-gradient(1.5px 1.5px at 12% 18%, rgb(236 239 244 / 0.7), transparent),
    radial-gradient(1px 1px at 28% 42%, rgb(236 239 244 / 0.5), transparent),
    radial-gradient(1.5px 1.5px at 47% 12%, rgb(236 239 244 / 0.6), transparent),
    radial-gradient(1px 1px at 66% 34%, rgb(236 239 244 / 0.5), transparent),
    radial-gradient(1.5px 1.5px at 78% 8%, rgb(236 239 244 / 0.7), transparent),
    radial-gradient(1px 1px at 91% 48%, rgb(236 239 244 / 0.4), transparent),
    radial-gradient(1px 1px at 7% 63%, rgb(236 239 244 / 0.4), transparent),
    rgb(var(--c-bg));
  color-scheme: dark;
}

[data-theme='light'] {
  /* Alacakaranlık: kırık beyaz ve gri-mavi tonlar, yıldız yok */
  --c-bg: 222 228 236;
  --c-surface: 236 240 245;
  --c-elevated: 229 234 241;
  --c-line: 196 205 217;
  --c-ink: 22 30 46;
  --c-muted: 72 84 104;
  --c-subtle: 104 117 138;
  --c-accent: 166 77 10;
  --c-accent-strong: 134 60 12;
  --c-accent-ink: 255 250 243;
  --c-o: 36 80 190;
  --sky: linear-gradient(180deg, #d3dce8 0%, #dde3eb 50%, #e4ddd4 100%);
  color-scheme: light;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sky) fixed;
  color: rgb(var(--c-ink));
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

a {
  color: rgb(var(--c-accent));
  text-decoration: none;
}
a:hover {
  color: rgb(var(--c-accent-strong));
  text-decoration: underline;
  text-underline-offset: 4px;
}

:focus-visible {
  outline: 2px solid rgb(var(--c-accent) / 0.7);
  outline-offset: 2px;
}

::selection {
  background: rgb(var(--c-accent) / 0.3);
}

/* ---------- Üst çubuk ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: rgb(var(--c-muted));
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.brand:hover {
  text-decoration: none;
  color: rgb(var(--c-ink));
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid rgb(var(--c-accent) / 0.6);
  border-radius: 0.6rem;
  color: rgb(var(--c-accent));
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-switch {
  display: flex;
  padding: 0.2rem;
  border: 1px solid rgb(var(--c-line) / 0.7);
  border-radius: 0.5rem;
  background: rgb(var(--c-surface) / 0.6);
}
.lang-switch button {
  padding: 0.25rem 0.55rem;
  border: 0;
  border-radius: 0.35rem;
  background: none;
  color: rgb(var(--c-subtle));
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
}
.lang-switch button[aria-pressed='true'] {
  background: rgb(var(--c-accent) / 0.15);
  color: rgb(var(--c-accent));
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 0.5rem;
  background: none;
  color: rgb(var(--c-muted));
  cursor: pointer;
}
.icon-button:hover {
  background: rgb(var(--c-ink) / 0.06);
  color: rgb(var(--c-ink));
}
.icon-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Koyu temada güneş (açığa geç), açık temada ay (koyuya geç) görünür */
.icon-moon,
[data-theme='light'] .icon-sun {
  display: none;
}
[data-theme='light'] .icon-moon {
  display: block;
}

/* ---------- Sayfa ---------- */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 0.5rem 1rem 1.5rem;
}

.intro {
  text-align: center;
}

h1 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.05;
  text-shadow: 0 0 40px rgb(var(--c-accent) / 0.15);
}

.tagline {
  margin: 0 0 1.25rem;
  color: rgb(var(--c-muted));
}

/* Dar ekranda alt alta; geniş ekranda solda panel, sağda tahta (bkz. en alttaki medya sorgusu) */
.game {
  display: grid;
  grid-template-areas: 'settings' 'rules' 'score' 'board' 'status' 'actions';
  justify-items: center;
  width: 100%;
  max-width: 30rem;
}
.settings { grid-area: settings; }
.rules { grid-area: rules; }
.scoreboard { grid-area: score; }
.board-wrap { grid-area: board; }
.status { grid-area: status; }
.actions { grid-area: actions; }

/* ---------- Ayarlar ---------- */
.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.75rem;
}

.segmented {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  border: 0;
}
.segmented[hidden] {
  display: none;
}
.segmented legend {
  float: left;
  margin-right: 0.5rem;
  color: rgb(var(--c-subtle));
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: lowercase;
}
.segmented legend::before {
  content: '// ';
}
.segmented label {
  position: relative;
}
/* Radyo düğmesi görünmez ama klavyeyle (ok tuşları) ve ekran okuyucuyla çalışmaya devam eder */
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: block;
  padding: 0.35rem 0.7rem;
  border: 1px solid rgb(var(--c-line) / 0.8);
  border-radius: 0.5rem;
  background: rgb(var(--c-surface) / 0.7);
  color: rgb(var(--c-muted));
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.segmented span:hover {
  border-color: rgb(var(--c-accent) / 0.6);
  color: rgb(var(--c-ink));
}
.segmented input:checked + span {
  border-color: rgb(var(--c-accent) / 0.8);
  background: rgb(var(--c-accent) / 0.12);
  color: rgb(var(--c-accent));
}
.segmented input:focus-visible + span {
  outline: 2px solid rgb(var(--c-accent) / 0.7);
  outline-offset: 2px;
}

.rules {
  min-height: 3em;
  margin: 0 0 0.5rem;
  color: rgb(var(--c-subtle));
  font-size: 0.875rem;
  text-align: center;
}
/* ---------- Skor tablosu ---------- */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  width: 100%;
  margin-bottom: 0.75rem;
}

.score-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0 0.6rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid rgb(var(--c-line) / 0.7);
  border-radius: 0.75rem;
  background: rgb(var(--c-surface) / 0.8);
  backdrop-filter: blur(4px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* Sırası gelen oyuncunun kartı pencere ışığı gibi yanar */
.score-card.active {
  border-color: rgb(var(--c-accent) / 0.7);
  box-shadow: 0 0 24px rgb(var(--c-accent) / 0.12);
}

.score-mark {
  grid-row: span 3;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
}
.score-name {
  overflow: hidden;
  color: rgb(var(--c-muted));
  font-size: 0.8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.score-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 500;
}
.score-points {
  color: rgb(var(--c-subtle));
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.score-points:empty {
  display: none;
}

.score-draws {
  grid-template-columns: auto;
  justify-items: center;
  text-align: center;
}

/* ---------- Tahta ---------- */
.board-wrap {
  position: relative;
  width: 100%;
  min-width: 15rem;
  aspect-ratio: 1;
  padding: 0.5rem;
  border: 1px solid rgb(var(--c-line) / 0.7);
  border-radius: 1rem;
  background: rgb(var(--c-surface) / 0.55);
  backdrop-filter: blur(4px);
  container-type: inline-size;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 3), 1fr);
  grid-template-rows: repeat(var(--size, 3), 1fr);
  width: 100%;
  height: 100%;
}

/* Hücre tam kare kaplar; görünen kutu ::before ile içeriden çizilir.
   Böylece hücre merkezleri tam hesaplanır ve 3'lü çizgileri tam ortadan geçer. */
.cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--font-display);
  font-size: calc(55cqi / var(--size, 3));
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.cell::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgb(var(--c-line) / 0.6);
  border-radius: 0.6rem;
  background: rgb(var(--c-elevated) / 0.7);
  transition: border-color 0.15s, background 0.15s;
}
.cell span {
  position: relative;
}
.cell:not([aria-disabled='true']):hover::before {
  border-color: rgb(var(--c-accent) / 0.6);
  background: rgb(var(--c-accent) / 0.06);
}
.cell[aria-disabled='true'] {
  cursor: default;
}
.cell:focus-visible {
  outline: none;
}
.cell:focus-visible::before {
  outline: 2px solid rgb(var(--c-accent) / 0.8);
  outline-offset: 1px;
}

.mark-x {
  color: rgb(var(--c-accent));
  text-shadow: 0 0 18px rgb(var(--c-accent) / 0.35);
}
.mark-o {
  color: rgb(var(--c-o));
  text-shadow: 0 0 18px rgb(var(--c-o) / 0.35);
}
.cell .placed {
  animation: pop 0.25s ease-out;
}

/* 3'lü çizgileri: hücrelerin üstünde, tıklamayı engellemez */
.lines {
  position: absolute;
  inset: 0.5rem;
  width: calc(100% - 1rem);
  height: calc(100% - 1rem);
  overflow: visible;
  pointer-events: none;
}
.lines line {
  stroke-width: 0.07;
  stroke-linecap: round;
  opacity: 0.9;
}
.lines .line-x {
  stroke: rgb(var(--c-accent));
  filter: drop-shadow(0 0 0.08px rgb(var(--c-accent)));
}
.lines .line-o {
  stroke: rgb(var(--c-o));
  filter: drop-shadow(0 0 0.08px rgb(var(--c-o)));
}
.lines .new {
  stroke-dasharray: 3;
  animation: draw 0.4s ease-out both;
}

/* ---------- Durum ve butonlar ---------- */
.status {
  min-height: 1.5em;
  margin: 0.75rem 0;
  color: rgb(var(--c-ink));
  font-family: var(--font-mono);
  font-size: 0.95rem;
  text-align: center;
}
.status::before {
  content: '$ ';
  color: rgb(var(--c-accent));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.btn {
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-primary {
  background: rgb(var(--c-accent));
  color: rgb(var(--c-accent-ink));
  font-weight: 600;
}
.btn-primary:hover {
  background: rgb(var(--c-accent-strong));
}
.btn-ghost {
  background: none;
  color: rgb(var(--c-muted));
}
.btn-ghost:hover {
  background: rgb(var(--c-ink) / 0.06);
  color: rgb(var(--c-ink));
}

/* ---------- Alt bilgi ---------- */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1rem;
  border-top: 1px solid rgb(var(--c-line) / 0.5);
  color: rgb(var(--c-subtle));
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.footer-projects,
.footer-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.25rem;
}
/* Şu an açık olan proje link gibi değil, vurgulu metin gibi görünür */
.footer-projects [aria-current='page'] {
  color: rgb(var(--c-ink));
  pointer-events: none;
}
.noscript {
  text-align: center;
}

/* ---------- Animasyonlar ---------- */
@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
@keyframes draw {
  from {
    stroke-dashoffset: 3;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }
}

[data-theme='light'] h1,
[data-theme='light'] .mark-x,
[data-theme='light'] .mark-o,
[data-theme='light'] .lines line {
  text-shadow: none;
  filter: none;
}

/* ---------- Geniş ekran: iki sütun ---------- */
@media (min-width: 860px) {
  .game {
    grid-template-columns: 22rem minmax(0, 1fr);
    grid-template-rows: auto auto auto auto 1fr;
    grid-template-areas:
      'settings board'
      'rules board'
      'score board'
      'status board'
      'actions board';
    gap: 0 3rem;
    justify-items: stretch;
    max-width: 60rem;
  }
  .settings {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .segmented legend {
    width: 6.75rem;
  }
  .rules,
  .status {
    text-align: left;
  }
  .actions {
    justify-content: flex-start;
    align-self: start;
  }
  /* Tahta ekran yüksekliğine sığar */
  .board-wrap {
    width: min(100%, 100svh - 12rem, 34rem);
    justify-self: center;
  }
}

/* ---------- Dar ekran ---------- */
@media (max-width: 480px) {
  .brand-path {
    display: none;
  }
  .score-card {
    padding: 0.5rem 0.6rem;
  }
  .score-mark {
    font-size: 1.4rem;
  }
}

/* ---------- Geri bildirim penceresi ---------- */
/* Düğme alt bilginin içinde durur; geniş ekranda sağ alt köşeye sabitlenir.
   Telefonda sabitlenmez ki oyun düğmelerinin üstüne binmesin. */
.fb-open {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid rgb(var(--c-line) / 0.8);
  border-radius: 999px;
  background: rgb(var(--c-surface) / 0.85);
  color: rgb(var(--c-muted));
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, opacity 0.15s;
}
.fb-open:hover,
.fb-open:focus-visible {
  border-color: rgb(var(--c-accent) / 0.6);
  color: rgb(var(--c-accent));
  opacity: 1;
}
.fb-open svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}
@media (min-width: 641px) {
  .fb-open {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 20;
    backdrop-filter: blur(6px);
    opacity: 0.7;
  }
}

.fb-dialog {
  width: min(26rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid rgb(var(--c-line));
  border-radius: 1rem;
  background: rgb(var(--c-surface));
  color: rgb(var(--c-ink));
}
.fb-dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(2px);
}
.fb-form {
  display: grid;
  gap: 0.35rem;
}
.fb-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.fb-intro {
  margin: 0 0 0.4rem;
  color: rgb(var(--c-muted));
  font-size: 0.9rem;
}
.fb-label {
  margin-top: 0.4rem;
  color: rgb(var(--c-subtle));
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.fb-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgb(var(--c-line) / 0.8);
  border-radius: 0.5rem;
  background: rgb(var(--c-elevated));
  color: rgb(var(--c-ink));
  font: inherit;
}
.fb-input:hover {
  border-color: rgb(var(--c-accent) / 0.6);
}
textarea.fb-input {
  min-height: 6rem;
  resize: vertical;
}
/* Botlar için tuzak alan: ekranda ve ekran okuyucuda görünmez */
.fb-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.fb-status {
  min-height: 1.4em;
  margin: 0.4rem 0 0;
  color: rgb(var(--c-muted));
  font-size: 0.85rem;
}
.fb-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.3rem;
}
.fb-actions .btn:disabled {
  opacity: 0.6;
  cursor: wait;
}
