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

html, body { height: 100%; margin: 0; }

body {
  --accent: var(--color-mine);
  --accent-deep: var(--color-mine-deep);
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 100dvh;
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  isolation: isolate;
}

body[data-turn="partner"] {
  --accent: var(--color-partner);
  --accent-deep: var(--color-partner-deep);
}

/* Kâğıt dokusu */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Arkada sıcak bir ışık lekesi: hangi dil dinleniyorsa o renge kayar */
body::after {
  content: "";
  position: fixed;
  inset: -20% -20% auto;
  height: 80%;
  z-index: -2;
  pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in oklch, var(--accent) 22%, transparent), transparent);
  transition: background var(--duration-normal) var(--ease-out-expo);
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--accent) 70%, var(--color-ink));
  outline-offset: 4px;
}

/* ---------- Sahne ---------- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 6vh, 56px);
  padding: max(24px, env(safe-area-inset-top)) var(--space-gutter) 5.5em;
}

.title {
  margin: 0;
  font-size: var(--text-title);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-align: center;
  text-wrap: balance;
  text-transform: uppercase;
  color: var(--color-ink);
}

.title:lang(ar) { letter-spacing: 0; }

.talk-wrap { display: grid; }

.talk,
.halo {
  grid-area: 1 / 1;
  width: var(--talk-size);
  aspect-ratio: 1;
  border-radius: 50%;
}

.talk {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 32% 28%, color-mix(in oklch, var(--accent) 70%, white) 0%, transparent 55%),
    var(--accent);
  color: var(--color-on-accent);
  box-shadow:
    0 2px 0 color-mix(in oklch, white 30%, transparent) inset,
    0 -10px 30px color-mix(in oklch, var(--accent-deep) 60%, transparent) inset,
    0 30px 60px -20px color-mix(in oklch, var(--accent-deep) 70%, transparent),
    0 12px 24px -12px oklch(0% 0 0 / 0.35);
  transition:
    transform var(--duration-fast) var(--ease-out-expo),
    background-color var(--duration-normal) var(--ease-out-expo),
    filter var(--duration-normal);
}

.talk svg {
  width: 34%;
  stroke-width: 1.6;
  transition: transform var(--duration-normal) var(--ease-out-expo);
}

.talk:hover { filter: brightness(1.04) saturate(1.05); }
.talk:active { transform: scale(0.96); }

body[data-state="live"] .talk svg { transform: scale(0.9); }
body[data-state="live"] .talk { background-color: var(--accent-deep); }

/* Dinlerken nefes alan halkalar */
.halo { position: relative; pointer-events: none; }

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  will-change: transform, opacity;
}

body[data-state="live"] .ring { animation: ripple 2.8s var(--ease-out-expo) infinite; }
body[data-state="live"] .ring--2 { animation-delay: 0.93s; }
body[data-state="live"] .ring--3 { animation-delay: 1.86s; }
body[data-hearing="1"] .ring { animation-duration: 1.3s; border-width: 3px; }
body[data-hearing="1"] .ring--2 { animation-delay: 0.43s; }
body[data-hearing="1"] .ring--3 { animation-delay: 0.86s; }

@keyframes ripple {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* Karşı tarafın çevirisi okunurken: içte mavi dalga */
body[data-speaking="1"] .talk {
  animation: incoming 0.9s ease-in-out infinite alternate;
}

@keyframes incoming {
  from { box-shadow: 0 0 0 0 color-mix(in oklch, var(--color-partner) 55%, transparent), 0 30px 60px -20px color-mix(in oklch, var(--accent-deep) 70%, transparent); }
  to { box-shadow: 0 0 0 18px color-mix(in oklch, var(--color-partner) 0%, transparent), 0 30px 60px -20px color-mix(in oklch, var(--accent-deep) 70%, transparent); }
}


/* Sıra kimde: bayrak + o dilde "sıra sende, konuş" */
.turn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 20px 10px 12px;
  border-radius: var(--radius-chip);
  background: var(--accent);
  color: var(--color-on-accent);
  font-size: var(--text-turn);
  font-weight: 700;
  box-shadow: 0 12px 28px -12px color-mix(in oklch, var(--accent-deep) 80%, transparent);
}

.turn[hidden] { display: inline-flex; visibility: hidden; } /* yer tutsun, düzen zıplamasın */
.turn__flag { font-family: var(--font-flag); font-size: 1.6em; line-height: 1; }
.turn--pop { animation: turn-pop 0.6s var(--ease-out-expo); }

@keyframes turn-pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* Test için soluk altyazı */
.caption {
  position: absolute;
  inset: auto var(--space-gutter) 12px;
  margin: 0;
  display: grid;
  gap: 4px;
  text-align: center;
  font-size: var(--text-caption);
  line-height: 1.35;
  min-height: 2.8em;
}

.caption__heard { color: var(--color-ink-soft); }
.caption__said { color: var(--color-ink); font-weight: 700; }

/* ---------- Alt bar ---------- */
.dock {
  display: grid;
  justify-content: center;
  padding: 14px var(--space-gutter) max(18px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-line);
}

.pair {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip {
  min-width: 56px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-chip);
  font-family: var(--font-flag);
  font-size: var(--text-flag);
  line-height: 1;
  background: var(--color-surface-2);
  transition: transform var(--duration-fast) var(--ease-out-expo), background var(--duration-normal), color var(--duration-normal);
}

.chip:active { transform: scale(0.94); }
.chip--mine { box-shadow: inset 0 0 0 2px var(--color-mine); }
.chip--partner { box-shadow: inset 0 0 0 2px var(--color-partner); }

/* Tek telefonda o an hangi dil dinleniyor */
body[data-state="live"][data-turn="mine"] .chip--mine,
body[data-state="live"][data-turn="partner"] .chip--partner {
  background: var(--accent);
  color: var(--color-on-accent);
}

.swap {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--color-ink-soft);
  transition: transform var(--duration-normal) var(--ease-out-expo), color var(--duration-fast);
}

.swap svg { width: 22px; }
.swap:hover { color: var(--color-ink); }
.swap:active { transform: rotate(180deg); }

/* Katalonya bayrağı (senyera): emojisi olmadığı için çizilir */
.flag-cat {
  display: inline-block;
  width: 1.4em;
  height: 0.95em;
  border-radius: 0.12em;
  vertical-align: -0.1em;
  background: repeating-linear-gradient(to bottom, #fcdd09 0 11.111%, #da121a 11.111% 22.222%);
  box-shadow: 0 0 0 1px oklch(0% 0 0 / 0.08);
}

/* ---------- Pencereler ---------- */
.sheet {
  border: 0;
  padding: 28px;
  border-radius: 28px;
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: 0 40px 80px -30px oklch(0% 0 0 / 0.5);
  max-width: calc(100vw - 2 * var(--space-gutter));
}

.sheet::backdrop {
  background: oklch(20% 0.02 55 / 0.45);
  backdrop-filter: blur(6px);
}

.sheet[open] { animation: sheet-in var(--duration-normal) var(--ease-out-expo); }

@keyframes sheet-in {
  from { transform: translateY(16px) scale(0.98); opacity: 0; }
}

.lang-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.lang-list button {
  width: 100%;
  min-height: 64px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--color-surface-2);
  display: grid;
  gap: 2px;
}

.lang-list b { font-family: var(--font-flag); font-size: 1.9rem; line-height: 1.1; }
.lang-list small { color: var(--color-ink-soft); font-size: 0.75rem; }
.lang-list button[aria-current="true"] { background: var(--color-ink); color: var(--color-surface); }
.lang-list button[aria-current="true"] small { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  body[data-state="live"] .ring { opacity: 0.35; transform: scale(1.12); }
  body[data-hearing="1"] .ring { opacity: 0.7; }
}
