:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #d6d3d1;
  --unknown: #e7e5e4;
  --primary-bg: #1c1917;
  --primary-text: #ffffff;
  --icon-bg: #e7e5e4;
  --danger: #b91c1c;
  --present: #166534;
  --absent: #991b1b;
  --twin: #7c3aed;
  --twin-bg: #ede9fe;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1917;
    --surface: #292524;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #44403c;
    --unknown: #3a3532;
    --primary-bg: #f5f5f4;
    --primary-text: #1c1917;
    --icon-bg: #3a3532;
    --danger: #f87171;
    --present: #15803d;
    --absent: #b91c1c;
    --twin: #a78bfa;
    --twin-bg: #2e1065;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1917;
  --surface: #292524;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --border: #44403c;
  --unknown: #3a3532;
  --primary-bg: #f5f5f4;
  --primary-text: #1c1917;
  --icon-bg: #3a3532;
  --danger: #f87171;
  --present: #15803d;
  --absent: #b91c1c;
  --twin: #a78bfa;
  --twin-bg: #2e1065;
  color-scheme: dark;
}

/* Renk körü modu: kırmızı-yeşil ayrımı yerine mavi-gri. */
:root[data-colorblind] {
  --present: #0369a1;
  --absent: #57534e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

h1 { margin: 0; font-size: 1.9rem; letter-spacing: 0.04em; }
h2 { font-size: 1rem; margin: 0 0 8px; color: var(--muted); }

/* Üst çubuk */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.icon-buttons { display: flex; gap: 8px; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--icon-bg);
  color: var(--text);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mode-info { margin: 12px 0; text-align: center; font-weight: 600; }

/* Form ve düğmeler */
#guess-form { display: flex; gap: 8px; }
.guess-field { position: relative; flex: 1; min-width: 0; }
#guess-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
button {
  padding: 10px 16px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
button.primary { background: var(--primary-bg); color: var(--primary-text); }
button.secondary { background: var(--unknown); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; }

/* Segmentli seçiciler (zorluk, tema, istatistik sekmeleri) */
.difficulty, .segmented { display: flex; gap: 4px; padding: 4px; background: var(--unknown); border-radius: 10px; }
.difficulty button, .segmented button {
  flex: 1;
  padding: 8px 6px;
  font-size: 0.85rem;
  background: transparent;
  color: var(--muted);
}
.difficulty button[aria-pressed="true"], .segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.difficulty-info { margin: 6px 0 16px; font-size: 0.85rem; color: var(--muted); text-align: center; }

.message { min-height: 1.4em; margin: 8px 0; color: var(--danger); font-size: 0.9rem; }

/* Tahmin tahtası */
.board { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.row.empty { border-style: dashed; background: transparent; }
.row.twin { flex-wrap: wrap; border: 2px solid var(--twin); }
.twin-note {
  flex-basis: 100%;
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--twin-bg);
  font-size: 0.85rem;
  line-height: 1.4;
}
.row img {
  position: relative;
  width: 48px;
  height: 32px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  transform-origin: left center;
  transition: transform 0.15s ease;
  cursor: zoom-in;
}
/* Üzerine gelince (dokunmatik ekranda basılı tutunca) bayrağı büyüt; kare veya
   dikdörtgen olmayan bayraklar (İsviçre, Nepal) kırpılmadan tam görünsün. */
.row img:hover, .row img:active {
  z-index: 10;
  transform: scale(4);
  object-fit: contain;
  background: var(--surface);
  border-radius: 1px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.row .name { width: 110px; font-weight: 600; font-size: 0.9rem; flex-shrink: 0; }
.row .tiles { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.tile-group { display: flex; flex-wrap: wrap; gap: 6px; }
.tiles .tile-group + .tile-group { padding-top: 6px; border-top: 1px solid var(--border); }

.tile {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 5px;
  border-radius: 6px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}
.tile.feature { border-radius: 999px; padding: 4px 10px; cursor: help; }
.tile.present { background: var(--present); }
.tile.absent { background: var(--absent); }
.tile.unknown { background: var(--unknown); color: var(--text); }

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

/* Keşfedilen bayrak taslağı: boyanmamış (saydam) hücrelerde arkadaki tarama "bilinmiyor" demektir. */
.sketch { margin: 4px 0 20px; text-align: center; }
.sketch h2 { text-align: left; }
#sketch {
  display: block;
  width: min(100%, 300px);
  aspect-ratio: 3 / 2;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, var(--unknown) 0 6px, var(--bg) 6px 12px);
  image-rendering: pixelated;
}
.sketch-info { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }

.palette-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

/* Oyun sonu */
.result {
  margin: 0 0 20px;
  padding: 16px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.result img { width: 160px; border: 1px solid var(--border); border-radius: 4px; }
.result p { font-size: 1.1rem; margin: 12px 0; }
.result .tiles { display: flex; flex-direction: column; gap: 6px; margin: 0 auto 16px; max-width: 360px; }
.result .tile-group { justify-content: center; }
.result .countdown { font-size: 0.9rem; color: var(--muted); }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Pencereler */
.modal {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 20px 20px 24px;
  border: none;
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal h2 { font-size: 1.4rem; color: var(--text); margin: 0 0 12px; }
.modal h3 { font-size: 1rem; margin: 20px 0 8px; }
.modal p, .modal li { font-size: 0.92rem; line-height: 1.45; }
.modal ul { padding-inline-start: 20px; }
.modal-close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
}
.modal-action { display: block; width: 100%; margin-top: 16px; }

.help-legend { list-style: none; padding: 0 !important; }
.help-note { margin: 0 0 8px; }
.help-examples { display: flex; flex-direction: column; gap: 4px; }
.help-examples p { margin: 4px 2px 12px; color: var(--muted); font-size: 0.85rem; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.dot.present { background: var(--present); }
.dot.absent { background: var(--absent); }

/* İstatistikler */
.stats-numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; text-align: center; }
.stats-numbers strong { display: block; font-size: 1.8rem; }
.stats-numbers span { font-size: 0.75rem; color: var(--muted); }
.distribution { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.dist-row > span { width: 14px; text-align: right; }
.dist-bar {
  min-width: 24px;
  padding: 2px 8px;
  text-align: right;
  font-weight: 600;
  color: var(--bg);
  background: var(--muted);
  border-radius: 3px;
}
.dist-bar.highlight { background: var(--present); color: #fff; }
.history { list-style: none; padding: 0 !important; margin: 0; max-height: 240px; overflow-y: auto; }
.history li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.history img { width: 36px; height: 24px; object-fit: cover; border: 1px solid var(--border); border-radius: 2px; }
.history .history-name { flex: 1; font-weight: 600; }
.history .history-meta { font-size: 0.78rem; color: var(--muted); }
.history .history-result { font-weight: 700; }
.history .history-result.won { color: var(--present); }
.history .history-result.lost { color: var(--absent); }
.empty-note { color: var(--muted); font-size: 0.9rem; }

/* Ayarlar */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting:last-of-type { border-bottom: none; }
.setting p { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }
.setting .segmented { flex-shrink: 0; }
.switch {
  appearance: none;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch:checked { background: var(--present); }
.switch:checked::after { transform: translateX(20px); }

@media (max-width: 420px) {
  h1 { font-size: 1.5rem; }
  .icon-buttons { gap: 6px; }
  .icon-btn { width: 36px; height: 36px; }
  .difficulty button { padding: 8px 2px; font-size: 0.75rem; white-space: nowrap; }
  .row { flex-wrap: wrap; }
  .row .name { width: auto; flex: 1; }
  .row .tiles { width: 100%; }
  .stats-numbers strong { font-size: 1.4rem; }
  .setting { flex-wrap: wrap; }
}

/* Dil seçimi */
.language-current { flex-shrink: 0; font-size: 0.9rem; padding: 8px 14px; }
.language-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.language-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.95rem;
  text-align: start;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}
.language-option[aria-pressed="true"] { border-color: var(--present); box-shadow: inset 0 0 0 1px var(--present); }
.language-option[aria-pressed="true"]::after { content: "✓"; color: var(--present); margin-inline-start: 8px; }

/* Sağdan sola diller (Arapça): büyütülen bayrak satırın içine doğru açılsın. */
[dir="rtl"] .row img { transform-origin: right center; }

/* Telif notu */
.site-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
.site-footer a { color: inherit; }

/* Ülke önerileri (tahmin kutusunun altında açılan liste) */
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline: 0;
  z-index: 20;
  max-height: min(50vh, 340px);
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.suggestions li:hover, .suggestions li[aria-selected="true"] { background: var(--unknown); }
.suggestions li.used { opacity: 0.4; cursor: default; text-decoration: line-through; }
