:root {
  --bg: #0d0b12;
  --bg2: #16131d;
  --panel: #1c1824;
  --line: #2c2636;
  --text: #f3eee6;
  --muted: #9b93a6;
  --p1: #ef4444;
  --p2: #3b82f6;
  --gold: #f5b942;
  --good: #34d399;
  --bad: #f87171;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; font-size: 16px; }
.hidden { display: none !important; }

.btn {
  display: block; width: 100%;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line);
  font-weight: 700; font-size: 16px;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--gold); color: #1b1305; border-color: transparent; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { width: auto; display: inline-block; padding: 10px 16px; font-size: 15px; }

/* ───────── LOBİ ───────── */
#lobby { height: 100dvh; overflow-y: auto; }
.lobby-inner {
  max-width: 440px; margin: 0 auto; padding: 28px 18px calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 18px;
}
.logo { text-align: center; }
.logo h1 { font-size: 30px; letter-spacing: 3px; font-weight: 900; margin-top: 12px; }
.logo p { color: var(--muted); margin-top: 4px; }
.logo-ring {
  width: 92px; height: 92px; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle, #c99a63 0 58%, #a5794a 70%);
  box-shadow: 0 0 0 5px #e8d7a2, 0 0 0 9px #3a2f22, 0 10px 30px #0008;
  position: relative;
}
.logo-ring .dot { position: absolute; top: 35px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; }
.logo-ring .dot.red { left: 18px; background: var(--p1); animation: bob 1.6s ease-in-out infinite; }
.logo-ring .dot.blue { right: 18px; background: var(--p2); animation: bob 1.6s ease-in-out infinite reverse; }
@keyframes bob { 50% { transform: translateX(8px); } }

.invite-banner {
  text-align: center; padding: 12px; border-radius: var(--radius);
  background: #2a2140; border: 1px solid #4b3b73;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.field input, .join-row input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; outline: none; width: 100%;
}
.field input:focus, .join-row input:focus { border-color: var(--gold); }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset {
  text-align: left; padding: 12px; border-radius: var(--radius);
  background: var(--bg2); border: 1.5px solid var(--line);
}
.preset .pi { font-size: 22px; }
.preset .pn { font-weight: 800; margin-top: 2px; }
.preset .pd { font-size: 12.5px; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.preset.on { border-color: var(--gold); background: #2a2216; }

.lobby-actions { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
.join-row .btn { width: 40%; }
.err { color: var(--bad); text-align: center; min-height: 1.4em; }

/* ───────── OYUN (mobil: dikey) ───────── */
#game {
  height: 100dvh;
  display: flex; flex-direction: column;
}
.scorebar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--line);
  flex: none;
}
.side { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.side.p2 { align-items: flex-end; }
.side .nm { max-width: 100%; }
.side .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side.p1 .nm { color: var(--p1); }
.side.p2 .nm { color: var(--p2); }
.side.me .nm::after { content: var(--you, " (sen)"); color: var(--muted); font-weight: 500; font-size: 12px; }
.pips { display: flex; gap: 4px; flex: none; }
.pip { width: 9px; height: 9px; border-radius: 50%; background: #3a3344; }
.p1 .pip.on { background: var(--p1); box-shadow: 0 0 6px var(--p1); }
.p2 .pip.on { background: var(--p2); box-shadow: 0 0 6px var(--p2); }
.mid { text-align: center; }
.round { font-size: 11px; font-weight: 800; color: var(--gold); letter-spacing: 1px; }
.clock { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.clock.warn { color: var(--bad); font-weight: 700; }

.stage-wrap { flex: none; display: flex; flex-direction: column; align-items: center; }
.stage {
  position: relative;
  width: min(100vw, max(240px, calc(100dvh - 350px)));
  aspect-ratio: 1;
  transition: width .2s ease;
}
.stage canvas { width: 100%; height: 100%; display: block; touch-action: manipulation; }
.ticker {
  position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none;
  padding: 16px 12px 6px; font-size: 12.5px; color: #e8dfd0;
  background: linear-gradient(transparent, rgba(13, 11, 18, .85) 55%);
  text-align: center; line-height: 1.3;
}
.ticker:empty, .overlay:not(.hidden) ~ .ticker { display: none; }
.ticker.flash { animation: tick .5s; }
@keyframes tick { from { color: var(--gold); transform: scale(1.03); } }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  padding: 12px; pointer-events: none;
}
.ov-card {
  pointer-events: auto; width: 100%; max-width: 380px;
  background: #15111bee; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; text-align: center; backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px #000a;
}
.ov-title { font-weight: 900; font-size: 18px; }
.ov-sub { color: #d6ccbe; font-size: 13.5px; margin-top: 4px; }
.ov-sub:empty { display: none; }
.ov-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.ov-actions:empty { display: none; }
.ov-foot { color: var(--muted); font-size: 12px; margin-top: 8px; }
.ov-foot:empty { display: none; }
.code-big { font-size: 28px; font-weight: 900; letter-spacing: 6px; color: var(--gold); margin: 4px 0; }

/* koç paneli */
.coach {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg2); border-top: 1px solid var(--line);
}
.coach-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 8px 5px 12px; border-bottom: 1px solid var(--line); flex: none;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; flex: none; position: relative; }
.avatar::after {
  content: ""; position: absolute; width: 5px; height: 5px; background: #fff; border-radius: 50%;
  top: 6px; left: 12px; box-shadow: 0 6px 0 #fff; width: 4px; height: 4px;
}
.who-name { font-weight: 800; font-size: 14px; }
.who-sub { display: none; }
.head-btns { display: flex; gap: 4px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; font-size: 16px;
  display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line);
}
.icon-btn.off { opacity: .45; }
.icon-btn.rec { background: var(--bad); border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.chat {
  flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.msg {
  flex: none; /* alan dolunca balonlar ezilmesin, kaysın */
  max-width: 85%; padding: 7px 12px; border-radius: 16px; font-size: 14.5px; line-height: 1.35;
  overflow-wrap: anywhere; animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.msg.coach { align-self: flex-end; background: var(--gold); color: #1b1305; border-bottom-right-radius: 4px; font-weight: 600; }
.msg.fighter { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.fighter.nope { border-color: #7a2d36; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 12.5px; text-align: center; padding: 2px 8px; }
.msg.typing { color: var(--muted); letter-spacing: 3px; }
.deltas { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.3; }
.deltas .up { color: var(--good); }
.deltas .down { color: var(--bad); }

.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 0; flex: none;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 11px; border-radius: 999px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); white-space: nowrap;
}
.chip:active { background: #2a2216; border-color: var(--gold); }

.composer {
  display: flex; gap: 8px; padding: 6px 12px calc(8px + var(--safe-b)); flex: none;
}
.composer input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
.composer input:focus { border-color: var(--gold); }
.composer .mic { border-radius: 50%; }
.send {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--gold); color: #1b1305; font-size: 18px; font-weight: 900;
}
.send:disabled { opacity: .5; }

/* karakter sayfası */
.sheet-bg { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet {
  width: 100%; max-width: 520px; max-height: 85dvh; overflow-y: auto;
  background: var(--bg2); border-radius: 20px 20px 0 0; padding: 10px 16px calc(20px + var(--safe-b));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: #443c50; margin: 0 auto 12px; }
.sheet-title { font-weight: 900; font-size: 17px; }
.sheet-note { color: var(--muted); font-size: 13px; margin: 4px 0 14px; }
.trait { padding: 9px 0; border-bottom: 1px solid var(--line); }
.trait:last-child { border-bottom: 0; }
.trait-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.trait-name { font-weight: 700; }
.trait-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.trait-desc { font-size: 12.5px; color: var(--muted); margin: 2px 0 6px; }
.bar { height: 8px; border-radius: 4px; background: #2a2433; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #a77c2d, var(--gold)); transition: width .6s cubic-bezier(.2, .9, .3, 1.2); }
.trait.changed .bar > i { background: linear-gradient(90deg, #1e7f5c, var(--good)); }
.trait.changed.down .bar > i { background: linear-gradient(90deg, #8b2a35, var(--bad)); }

.toast {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 30;
  background: #2a2140; border: 1px solid #4b3b73; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; animation: pop .2s;
}

/* ───────── MASAÜSTÜ / YATAY ───────── */
@media (min-width: 900px) {
  #game {
    display: grid;
    grid-template-columns: 1fr 400px;
    grid-template-rows: auto 1fr;
  }
  .scorebar { grid-column: 1 / -1; padding: 10px 20px; }
  .side { flex-direction: row; align-items: center; gap: 10px; }
  .side.p2 { flex-direction: row-reverse; }
  .side .nm { font-size: 17px; }
  .chips { flex-wrap: wrap; }
  .clock { font-size: 15px; }
  .stage-wrap { justify-content: center; padding: 12px; min-height: 0; }
  .stage { width: min(calc(100vw - 440px), calc(100dvh - 120px)); }
  .coach { border-top: 0; border-left: 1px solid var(--line); }
}

/* ───────── PROTOTİP / YARDIM / GERİ BİLDİRİM ───────── */
.proto {
  display: inline-block; vertical-align: middle; margin-left: 6px;
  font-size: 11px; letter-spacing: 1px; padding: 3px 7px; border-radius: 6px;
  background: #2a2140; color: #c4b5fd; border: 1px solid #4b3b73;
}
.howto { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.howto summary { font-weight: 700; cursor: pointer; }
.howto ul { margin: 10px 0 2px 18px; display: flex; flex-direction: column; gap: 6px; color: #d6ccbe; font-size: 14px; }
.fineprint { color: var(--muted); font-size: 12px; text-align: center; }
.sheet-note.small { font-size: 12px; margin: 10px 0 0; }
#fbForm { display: flex; flex-direction: column; gap: 10px; }
#fbForm .sheet-note { margin: 0; }
.rate { display: flex; justify-content: space-between; gap: 6px; }
.rate button {
  flex: 1; font-size: 28px; padding: 8px 0; border-radius: 12px;
  background: var(--panel); border: 1.5px solid var(--line); filter: grayscale(.7); opacity: .7;
}
.rate button.on { filter: none; opacity: 1; border-color: var(--gold); background: #2a2216; }
#fbForm textarea, #fbForm input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; outline: none; font: inherit; font-size: 16px; color: inherit; resize: vertical;
}
#fbForm textarea:focus, #fbForm input:focus { border-color: var(--gold); }
.toast.warn { background: #3e1820; border-color: #7a2d36; }

/* eşleşme */
.online { text-align: center; color: var(--muted); font-size: 13px; margin: -2px 0 2px; min-height: 1.2em; }
.search-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none;
  padding: 7px 12px; background: #2a2140; border-bottom: 1px solid #4b3b73; font-size: 13.5px;
}
.search-bar span { animation: pulse 1.6s infinite; }
.search-bar button { padding: 5px 12px; border-radius: 999px; border: 1px solid #4b3b73; font-size: 13px; }
@media (min-width: 900px) { .search-bar { grid-column: 1 / -1; } }
@media (min-width: 900px) { #game:has(.search-bar:not(.hidden)) { grid-template-rows: auto auto 1fr; } }

/* yazarken: klavye açıkken arena küçülür, başlık ve hazır mesajlar gizlenir */
body.typing .chips, body.typing .coach-head { display: none; }
body.typing .stage { width: min(100vw, max(150px, calc(100dvh - 300px))); }
@media (min-width: 900px) {
  body.typing .chips, body.typing .coach-head { display: flex; }
  body.typing .stage { width: min(calc(100vw - 440px), calc(100dvh - 120px)); }
}
body.typing .ticker { display: none; }
@media (min-width: 900px) { body.typing .ticker:not(:empty) { display: block; } }

/* dil değiştirici */
.lang-switch { display: flex; justify-content: flex-end; gap: 6px; margin-bottom: -6px; }
.lang-switch a { font-size: 13px; padding: 5px 10px; border-radius: 999px; color: var(--muted); text-decoration: none; border: 1px solid transparent; }
.lang-switch a.on { color: var(--text); border-color: var(--line); background: var(--bg2); }
