:root {
  --bg0: #09040f;
  --bg1: #170817;
  --bg2: #2a0d22;
  --cream: #ffeef6;
  --wine: #4a1230;
  --wine2: #7a1f4b;
  --accent: #c2185b;
  --card: #fff3f7;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 55%, var(--bg2) 100%);
  color: var(--cream);
  font-family: var(--sans);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 45% 50% at 50% 48%, rgba(120, 30, 90, 0.22), transparent 70%),
    radial-gradient(ellipse 60% 25% at 50% 108%, rgba(194, 24, 91, 0.3), transparent 70%);
}

#ladybugs { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.ladybug { position: absolute; left: 0; top: 0; opacity: 0; transition: opacity 1.2s ease; filter: drop-shadow(0 1px 2px rgba(0,0,0,.55)); will-change: transform; transform-origin: 50% 65%; }
.ladybug .lb-legA, .ladybug .lb-legB { transform-box: fill-box; transform-origin: center; }
.ladybug.walk .lb-legA { animation: lbleg .28s linear infinite; }
.ladybug.walk .lb-legB { animation: lbleg .28s linear infinite reverse; }
@keyframes lbleg { 0%, 100% { transform: translateY(-1.1px); } 50% { transform: translateY(1.1px); } }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ince tarama çizgileri */
.scan {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  z-index: 5;
}
.topbar > * { pointer-events: auto; }
.actions { display: flex; gap: 8px; }

.brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  color: #ffb3d6;
  opacity: 0;
  transition: opacity 2.5s ease;
  padding-top: 6px;
}
.brand.show { opacity: 0.9; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 0.85rem var(--sans);
  color: var(--cream);
  background: rgba(40, 14, 38, 0.6);
  border: 1px solid rgba(255, 190, 225, 0.35);
  border-radius: 999px;
  padding: 9px 15px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  position: relative;
}
.pill[hidden] { display: none; }
.pill:hover { background: rgba(80, 24, 68, 0.8); border-color: #ffb3d6; }
.pill:active { transform: scale(0.97); }
.pill .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  position: absolute; top: -2px; right: -2px;
}

#caption {
  position: fixed;
  left: 0; right: 0;
  bottom: max(48px, env(safe-area-inset-bottom));
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(1.3rem, 3.4vw, 2rem);
  letter-spacing: 0.03em;
  color: var(--cream);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9), 0 0 24px rgba(255, 90, 170, 0.35);
  opacity: 0;
  transition: opacity 1.4s ease;
  pointer-events: none;
  padding: 0 24px;
  z-index: 4;
}
#caption.show { opacity: 1; }

.hint {
  position: fixed;
  left: 0; right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 230, 245, 0.6);
  opacity: 0;
  transition: opacity 1.5s ease;
  pointer-events: none;
  z-index: 4;
}
.hint.show { opacity: 1; }

.hud {
  position: fixed;
  left: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
}
.ghost {
  font: 600 0.8rem var(--sans);
  color: var(--cream);
  background: rgba(40, 14, 38, 0.45);
  border: 1px solid rgba(255, 190, 225, 0.3);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.ghost:hover { background: rgba(80, 24, 68, 0.8); border-color: #ffb3d6; }
.ghost[hidden] { display: none; }

/* ---------- Süzülen fotoğraflar ---------- */
#polaroids { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.drifter {
  position: absolute;
  left: 0; top: 0;
  padding: 3px 3px 8px;
  background: #fff7fa;
  border: 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  will-change: transform, opacity;
}
.drifter img { display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: #3a1530; }

/* ---------- Ortak katman ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 12px; }
.overlay[hidden] { display: none; }
.backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 3, 10, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade 0.25s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Anılar (lightbox) ---------- */
.lb figure { position: relative; margin: 0; max-width: min(92vw, 720px); text-align: center; animation: rise 0.3s ease; }
.lb img { max-width: 100%; max-height: 78vh; border: 10px solid #fffaf8; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); background: #f6d3df; }
.lb-cap { margin-top: 10px; font: italic 1.2rem var(--serif); color: #fff; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4); min-height: 1.4em; }
.lb-prev, .lb-next {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255, 243, 247, 0.85); color: var(--wine);
  font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.lb-prev { left: 12px; } .lb-next { right: 12px; }
.lb-close { position: absolute; top: 14px; right: 14px; background: rgba(255, 243, 247, 0.85); color: var(--wine); border: 0; }

/* ---------- Sudoku ---------- */
.sudoku-card {
  position: relative;
  width: min(100%, 460px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  background: var(--card);
  color: var(--wine);
  border: 1px solid rgba(194, 24, 91, 0.3);
  border-radius: 22px;
  padding: 16px 16px 18px;
  box-shadow: 0 30px 80px rgba(74, 18, 48, 0.45);
  animation: rise 0.3s ease;
}

.sd-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sd-title { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; line-height: 1; }
.sd-sub { font-size: 0.74rem; color: rgba(74, 18, 48, 0.65); margin-top: 4px; }
.sd-right { display: flex; align-items: center; gap: 10px; }
.sd-timer { font-variant-numeric: tabular-nums; font-size: 0.95rem; color: var(--accent); font-weight: 600; }
.sd-x {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid rgba(74, 18, 48, 0.3);
  background: transparent; color: var(--wine);
  font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.sd-x:hover { background: rgba(194, 24, 91, 0.1); }

.sd-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1;
  border: 2px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  user-select: none;
}
.sd-cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--wine);
  font: 500 clamp(1.05rem, 5.2vw, 1.6rem) var(--sans);
  border-right: 1px solid rgba(74, 18, 48, 0.16);
  border-bottom: 1px solid rgba(74, 18, 48, 0.16);
  cursor: pointer;
  min-width: 0;
  transition: background 0.12s;
}
.sd-cell:nth-child(9n) { border-right: 0; }
.sd-cell:nth-child(n+73) { border-bottom: 0; }
.sd-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid rgba(194, 24, 91, 0.6); }
.sd-cell:nth-child(n+19):nth-child(-n+27),
.sd-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid rgba(194, 24, 91, 0.6); }

.sd-cell.given { font-weight: 700; color: #3a0d26; }
.sd-cell.user { color: var(--accent); }
.sd-cell.peer { background: rgba(244, 143, 177, 0.16); }
.sd-cell.same { background: rgba(244, 143, 177, 0.4); }
.sd-cell.sel { background: rgba(240, 98, 146, 0.45); }
.sd-cell.conflict { color: #d32f2f; }
.sd-cell.wrong { background: rgba(211, 47, 47, 0.3); }
.sd-cell.hinted { color: #2e7d32; }

.sd-notes {
  position: absolute; inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.5rem, 2.2vw, 0.7rem);
  color: rgba(74, 18, 48, 0.55);
  line-height: 1;
  pointer-events: none;
}
.sd-notes span { display: grid; place-items: center; }

.sd-tools { display: flex; gap: 8px; margin: 12px 0 8px; }
.sd-tool {
  flex: 1;
  font: 600 0.78rem var(--sans);
  color: var(--wine);
  background: rgba(194, 24, 91, 0.07);
  border: 1px solid rgba(74, 18, 48, 0.2);
  border-radius: 12px;
  padding: 9px 4px;
  cursor: pointer;
}
.sd-tool:hover { background: rgba(194, 24, 91, 0.15); }
.sd-tool.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.sd-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.sd-num {
  font: 600 1.25rem var(--sans);
  color: var(--wine);
  background: #fff;
  border: 1px solid rgba(74, 18, 48, 0.2);
  border-radius: 10px;
  padding: 10px 0 8px;
  cursor: pointer;
  position: relative;
}
.sd-num:hover { background: rgba(244, 143, 177, 0.3); }
.sd-num:disabled { opacity: 0.25; cursor: default; }
.sd-num small { display: block; font-size: 0.55rem; color: rgba(74, 18, 48, 0.55); margin-top: 2px; font-weight: 500; }

.sd-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 0.74rem; color: rgba(74, 18, 48, 0.6); }

.sd-win {
  position: absolute; inset: 0;
  display: grid; place-items: center; text-align: center;
  background: rgba(255, 243, 247, 0.94);
  border-radius: 22px;
  padding: 24px;
  animation: fade 0.5s ease;
}
.sd-win .big { font-family: var(--serif); font-size: 2.2rem; color: var(--accent); margin: 6px 0 10px; }
.sd-win p { margin: 0 0 6px; }
.sd-win .streak { color: rgba(74, 18, 48, 0.65); font-size: 0.85rem; margin-bottom: 18px; }
.sd-win button { font: 600 0.9rem var(--sans); color: #fff; background: var(--accent); border: 0; border-radius: 999px; padding: 10px 22px; cursor: pointer; }

@media (max-width: 520px) {
  .pill span { display: none; }
  .pill { padding: 10px 12px; }
  .sudoku-card { padding: 12px; border-radius: 18px; }
  .sd-num { font-size: 1.1rem; padding: 9px 0 7px; }
}

/* Telefon yatay: kısa ekran. Sudoku iki sütun (sol tahta, sağ tuşlar), üst çubuk küçük */
@media (max-height: 520px) and (orientation: landscape) {
  .overlay { padding: 6px; }
  .sudoku-card {
    width: min(100%, 760px);
    max-height: calc(100dvh - 12px);
    display: grid;
    grid-template-columns: min(calc(100dvh - 92px), 330px) 1fr;
    column-gap: 16px;
    align-content: start;
    padding: 8px 14px 10px;
    border-radius: 16px;
  }
  .sd-head { grid-column: 1 / -1; margin-bottom: 6px; }
  .sd-title { font-size: 1.2rem; }
  .sd-cell { font-size: 1.15rem; }
  .sd-notes { font-size: 0.5rem; }
  .sd-grid { grid-column: 1; grid-row: 2 / span 3; }
  .sd-tools { grid-column: 2; margin: 0 0 8px; }
  .sd-pad { grid-column: 2; grid-template-columns: repeat(5, 1fr); align-self: start; }
  .sd-foot { grid-column: 2; margin-top: 8px; flex-direction: column; align-items: flex-start; gap: 2px; }
  .sd-num { padding: 7px 0 5px; font-size: 1.05rem; }
  .sd-tool { padding: 7px 4px; }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
  .pill { padding: 7px 11px; }
  #caption { bottom: max(34px, env(safe-area-inset-bottom)); font-size: 1.1rem; }
  .hint { display: none; }
  .hud { bottom: max(8px, env(safe-area-inset-bottom)); }
  .lb img { max-height: 70vh; border-width: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .brand, #caption, .hint { transition-duration: 0.01s; }
}
