:root {
  /* Beyaz, minimalist tema. Yüzeyler gölgeyle değil ince çizgi ve açık griyle ayrılır. */
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f5; /* kartlar, kareler gibi hafif ayrışan alanlar */
  --text: #111113;
  --muted: #71717a;
  --line: #e7e7ea;
  --p0: #ff5a5f; /* host (mercan) */
  --p0-soft: #ffeded;
  --p1: #14b8a6; /* misafir (turkuaz) */
  --p1-soft: #e2f7f4;
  --accent: #111113;
  --accent-text: #ffffff;
  --ok: #22c55e;
  --code: #16a34a; /* davet linkindeki oda kodu */
  --radius: 18px;
  --shadow: 0 1px 2px rgba(17, 17, 19, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.screen { flex: 1; display: flex; flex-direction: column; animation: enter 0.25s ease-out; }
.screen[hidden] { display: none; }

@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

/* --- Üst bar --- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 20px; }
.logo { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.logo span { color: var(--p0); }
.me { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; }
.me:empty { display: none; }

/* --- Metin --- */
.hero { font-size: clamp(34px, 10vw, 44px); line-height: 1.05; letter-spacing: -0.03em; margin: 12px 0 10px; font-weight: 800; }
.hero em { font-style: normal; color: var(--p1); }
.lead { color: var(--muted); margin: 0 0 28px; font-size: 16px; }
.title { font-size: 26px; letter-spacing: -0.02em; margin: 4px 0 18px; font-weight: 800; }
.muted { color: var(--muted); font-size: 15px; margin: 0 0 10px; }
.center { text-align: center; }

/* --- Katalog --- */
.catalog { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  all: unset;
  box-sizing: border-box;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s, background-color 0.15s;
  min-height: 150px;
}
@media (hover: hover) {
  button.card:hover { background: var(--surface); border-color: var(--line); }
}
button.card:active { transform: scale(0.96); }
button.card:focus-visible { outline: 3px solid var(--p1); outline-offset: 2px; }
button.card:disabled { opacity: 0.6; }
.card-art { font-size: 38px; flex: 1; display: flex; align-items: center; gap: 4px; }
.card-name { font-weight: 800; font-size: 18px; }
.card-meta { font-size: 13px; color: var(--muted); }

/* --- Butonlar --- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 18px;
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  flex: 1;
  transition: transform 0.12s ease, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn-big { width: 100%; padding: 18px; font-size: 19px; border-radius: 18px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.row { display: flex; gap: 10px; }

/* --- Lobi --- */
.invite { margin-bottom: 22px; }
.invite[hidden] { display: none; }
.link-box {
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 16px;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
  word-break: break-all;
  user-select: all;
}
.link-code { color: var(--code); }
/* Davet QR kodu (linkin üstünde) */
.qr { margin-bottom: 18px; }
.qr[hidden] { display: none; }
.qr-code svg {
  display: block;
  width: 168px;
  height: 168px;
  margin: 0 auto 8px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.qr .muted { font-size: 13px; }

.players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}
.player.empty { border-style: dashed; background: transparent; color: var(--muted); }
.player .mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 900; font-size: 18px;
}
.player.p0 .mark { background: var(--p0-soft); color: var(--p0); }
.player.p1 .mark { background: var(--p1-soft); color: var(--p1); }
.player .name { flex: 1; font-weight: 600; }
.player .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.player.online .dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.player.empty .dot { display: none; }
.player.empty .name { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.bottom { margin-top: auto; padding-top: 24px; }
.bottom .muted { margin-top: 12px; }

/* --- Oyun --- */
.players.compact { flex-direction: row; }
.players.compact .player { flex: 1; padding: 8px 10px; gap: 8px; min-width: 0; }
.players.compact .mark { width: 28px; height: 28px; font-size: 14px; border-radius: 8px; }
.players.compact .name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sırası gelen oyuncunun kartı: kendi renginde çerçeve, hafif nabız ve "Sırada" etiketi. */
.player { position: relative; transition: border-color 0.25s, box-shadow 0.25s; }
.player.active.p0 { --pc: var(--p0); }
.player.active.p1 { --pc: var(--p1); }
.player.active { border-color: var(--pc); box-shadow: 0 0 0 2px var(--pc); animation: turn-pulse 1.6s ease-in-out infinite; }
.player .badge {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: var(--pc); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
@keyframes turn-pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--pc) 25%, transparent); } }

.turn { text-align: center; font-weight: 800; font-size: 20px; min-height: 28px; margin: 22px 0 14px; }
.turn.mine { color: var(--text); }
.turn.mine.p0 { color: var(--p0); }
.turn.mine.p1 { color: var(--p1); }
.turn-mark { font-weight: 900; }
.turn.theirs { color: var(--muted); font-weight: 600; }
/* "düşünüyor..." noktaları sırayla belirir. */
.turn .dots { display: inline-block; width: 1.2em; text-align: left; overflow: hidden; vertical-align: bottom; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }

.game-area { width: 100%; }
/* Gerçek zamanlı oyunlar kalan tüm yüksekliği kullanır; oyun kendini bu kutuya sığdırır. */
.game-area.fill { flex: 1; min-height: 240px; position: relative; }
/* Gerçek zamanlı oyunda "sıra" satırı çoğu zaman boştur; boşken masaya yer açsın. */
#screen-game:has(.game-area.fill) .turn:empty { min-height: 0; margin: 10px 0 0; }

.result { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; animation: enter 0.3s ease-out; }
.result[hidden] { display: none; }
.result-text { text-align: center; font-size: 30px; font-weight: 900; letter-spacing: -0.02em; margin: 0 0 6px; }
.result .muted:empty { display: none; }

/* --- Tam ekran oyun modu (gerçek zamanlı oyun sürerken) --- */
body.immersive { overflow: hidden; }
body.immersive #app {
  height: 100dvh;
  min-height: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}
body.immersive .topbar,
body.immersive #game-players { display: none; }
body.immersive #screen-game { animation: none; min-height: 0; }
/* Duraklama uyarısı gibi mesajlar oyunun üstünde küçük bir kapsül olarak görünür. */
body.immersive #screen-game .turn {
  position: fixed;
  z-index: 5;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  min-height: 0;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(17, 17, 19, 0.85);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}
body.immersive #screen-game .turn:empty { display: none; }

/* --- Mesaj ekranı --- */
.message { margin: auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.message-emoji { font-size: 64px; margin: 0; }
.message .btn { flex: none; min-width: 220px; }

/* --- Oyun tanıtımı (alttan açılan pencere) --- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(17, 17, 19, 0.35);
  animation: fade 0.2s ease-out;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: sheet-up 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-emoji { font-size: 44px; line-height: 1; }
.sheet-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.sheet-meta { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.sheet-list { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.sheet-list li { font-size: 16px; line-height: 1.35; }
.sheet-list li::marker { color: var(--p1); }
.sheet .btn-ghost { margin-top: 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* --- Bildirimler --- */
.conn {
  position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%);
  background: #f5a524; color: #1d1b22; font-size: 14px; font-weight: 700;
  padding: 8px 14px; border-radius: 999px; z-index: 10; white-space: nowrap;
}
.conn[hidden] { display: none; }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--accent); color: var(--accent-text); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

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