:root {
  --bg: #f2f5fb;
  --ink: #1c2440;
  --muted: #68738f;
  --line: #e1e6f2;
  --card: #ffffff;
  --accent: #4f6bff;
  --accent-soft: #e8edff;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(28, 36, 64, 0.06), 0 10px 28px rgba(28, 36, 64, 0.09);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1100px 560px at 85% -10%, #e2e8ff 0, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #ffeedd 0, transparent 55%),
    var(--bg);
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- Üst çubuk ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(18px, 2.3vw, 26px);
  font-weight: 800;
  letter-spacing: -0.015em;
  white-space: nowrap;
}
.topbar h1 em { font-style: normal; color: var(--accent); }
.topbar h1 .logo { height: 1.5em; width: auto; vertical-align: middle; margin-inline-end: 8px; }   /* img/logo.png */

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 700;
}
#count { white-space: nowrap; }
.bar {
  width: clamp(90px, 16vw, 200px);
  height: 10px;
  border-radius: 99px;
  background: #dde3f2;
  overflow: hidden;
}
.bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #4f6bff, #7ba6ff);
  transition: width 0.5s ease;
}
.ghost-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(28, 36, 64, 0.06);
  transition: border-color 0.15s, color 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Ana yerleşim ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(172px, 21vw, 300px) 1fr;
  gap: 14px;
}

/* ---------- Sol: parça listesi ---------- */
.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 800; }
.panel-head span { font-size: 12px; font-weight: 600; color: var(--muted); }

#pieceList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c9d1e6 transparent;
}

.card {
  position: relative;
  flex: none;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.3s, filter 0.3s;
}
.card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: radial-gradient(circle at 50% 40%, #ffffff, #edf1fa);
  cursor: grab;
  touch-action: none;
}
.card canvas:active { cursor: grabbing; }
.card .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 12px 9px;
  font-size: 12.5px;
}
.card .meta b { font-weight: 800; }
.card .tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 99px;
  padding: 2px 9px;
  white-space: nowrap;
}
.card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(79, 107, 255, 0.2);
}
.card.done {
  opacity: 0.5;
  filter: saturate(0.35);
  pointer-events: none;
}
.card.leaving {
  pointer-events: none;
  margin-bottom: -10px;
  opacity: 0;
  transform: scale(0.92);
  border-width: 0;
  transition: height 0.5s cubic-bezier(.4, 0, .2, 1), margin 0.5s cubic-bezier(.4, 0, .2, 1),
    opacity 0.3s, transform 0.5s, border-width 0.5s;
}
.card.gone { display: none; }
.card.done .tag { color: #2f9e62; background: #e3f6ec; }

/* ---------- Sağ: model ---------- */
.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background:
    radial-gradient(rgba(120, 135, 175, 0.12) 1.5px, transparent 2px) 0 0 / 26px 26px,
    radial-gradient(ellipse at 50% 38%, #ffffff 0, #f2f5fc 55%, #e3e8f4 100%);
}
#stage { position: absolute; inset: 0; }
#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage canvas:active { cursor: grabbing; }

/* ---------- Araç çubuğu + ViewCube ---------- */
.tools {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}
.cube-wrap {
  width: 96px;
  height: 96px;
  perspective: 280px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}
.cube-wrap:active { cursor: grabbing; }
#cube {
  position: relative;
  width: 54px;
  height: 54px;
  transform-style: preserve-3d;
}
#cube .f {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 0 0 0.05em;
  line-height: 1;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #6c789a;
  background: linear-gradient(180deg, #ffffff, #edf1fa);
  border: 1px solid #cfd7ea;
  backface-visibility: hidden;
  transition: background 0.15s, color 0.15s;
}
#cube .f:hover { background: var(--accent-soft); color: var(--accent); }
#cube .f-front  { transform: translateZ(27px); }
#cube .f-back   { transform: rotateY(180deg) translateZ(27px); }
#cube .f-right  { transform: rotateY(90deg) translateZ(27px); }
#cube .f-left   { transform: rotateY(-90deg) translateZ(27px); }
#cube .f-top    { transform: rotateX(90deg) translateZ(27px); }
#cube .f-bottom { transform: rotateX(-90deg) translateZ(27px); }

.tool {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #2a3558;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(28, 36, 64, 0.1);
  transition: transform 0.12s, color 0.15s, border-color 0.15s, background 0.15s;
}
.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover { color: var(--accent); border-color: var(--accent); }
.tool:active { transform: scale(0.92); }
.tool.on { color: #fff; background: var(--accent); border-color: var(--accent); }

/* ---------- İpucu + bitiş mesajı ---------- */
#hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 7px 16px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

#toast {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translate(-50%, -16px) scale(0.9);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px 9px 20px;
  border-radius: 99px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(14px, 2.2vw, 18px);
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(28, 36, 64, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s, transform 0.5s cubic-bezier(.2, 1.6, .4, 1);
  z-index: 4;
}
#toast button.alt {
  color: var(--accent);
  background: var(--accent-soft);
}
#toast button.playing { background: #ff9a24; }
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  pointer-events: auto;
}
#toast button {
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 99px;
  padding: 7px 14px;
  cursor: pointer;
}

/* ---------- Alçak ekran (telefon yatay) ---------- */
@media (max-height: 520px) {
  .app { gap: 6px; padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .topbar h1 { font-size: 16px; }
  .progress { gap: 8px; font-size: 12px; }
  .bar { height: 8px; width: 90px; }
  .ghost-btn { padding: 4px 10px; font-size: 12px; }
  .layout { grid-template-columns: 138px 1fr; gap: 8px; }
  .panel-head { padding: 8px 10px 4px; }
  .panel-head h2 { font-size: 13px; }
  #pieceList { padding: 4px 6px 8px; gap: 6px; }
  .card .meta { padding: 4px 8px 6px; font-size: 11px; }
  .card .tag { font-size: 10px; padding: 1px 7px; }
  .tools { top: 6px; right: 8px; gap: 6px; }
  .cube-wrap { width: 76px; height: 76px; }
  #cube { width: 44px; height: 44px; }
  #cube .f { font-size: 8px; }
  #cube .f-front  { transform: translateZ(22px); }
  #cube .f-back   { transform: rotateY(180deg) translateZ(22px); }
  #cube .f-right  { transform: rotateY(90deg) translateZ(22px); }
  #cube .f-left   { transform: rotateY(-90deg) translateZ(22px); }
  #cube .f-top    { transform: rotateX(90deg) translateZ(22px); }
  #cube .f-bottom { transform: rotateX(-90deg) translateZ(22px); }
  .tool { width: 34px; height: 34px; }
  .tool svg { width: 18px; height: 18px; }
  #hint { bottom: 6px; font-size: 11px; padding: 4px 12px; }
  #toast { top: 8px; padding: 6px 8px 6px 14px; }
}

/* ---------- Dikey modda "telefonu çevir" uyarısı ---------- */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: var(--ink);
  background: var(--bg);
}
#rotate p { margin: 0; font-size: clamp(22px, 6vw, 30px); font-weight: 800; }
#rotate small { font-size: 15px; font-weight: 700; color: var(--muted); }
#rotate .phone {
  position: relative;
  width: 62px;
  height: 104px;
  margin-bottom: 18px;
  border: 6px solid var(--accent);
  border-radius: 14px;
  background: var(--accent-soft);
  animation: rotatePhone 2.4s ease-in-out infinite;
}
#rotate .phone::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: var(--accent);
}
@keyframes rotatePhone {
  0%, 15%  { transform: rotate(0deg); }
  55%, 85% { transform: rotate(-90deg); }
  100%     { transform: rotate(0deg); }
}
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) {
  #rotate { display: flex; }
}

/* ---------- Builder AI (sağ alt) ---------- */
#builder {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
#builder .av {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f6bff, #8a5cff);
}
#builder .av svg {
  width: 17px;
  height: 17px;
  fill: #fff;
  stroke: #fff;
  stroke-width: 1;
  stroke-linejoin: round;
}
.ai-fab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(28, 36, 64, 0.16);
  transition: transform 0.12s, border-color 0.15s;
}
.ai-fab:hover { border-color: var(--accent); }
.ai-fab:active { transform: scale(0.96); }
.ai-fab.open { border-color: var(--accent); }
.ai-fab.pulse { animation: aiPulse 2.2s ease-in-out infinite; }
@keyframes aiPulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(28, 36, 64, 0.16), 0 0 0 0 rgba(79, 107, 255, 0.45); }
  50%      { box-shadow: 0 6px 20px rgba(28, 36, 64, 0.16), 0 0 0 10px rgba(79, 107, 255, 0); }
}

.ai-panel {
  width: min(310px, calc(100vw - 48px));
  max-height: min(400px, calc(100dvh - 200px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 16px 40px rgba(28, 36, 64, 0.22);
  overflow: hidden;
  animation: aiIn 0.28s cubic-bezier(.2, 1.3, .4, 1);
  transform-origin: 100% 100%;
}
.ai-panel[hidden] { display: none; }
@keyframes aiIn { from { opacity: 0; transform: scale(0.88) translateY(10px); } }

.ai-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--line);
}
.ai-title { flex: 1; line-height: 1.2; }
.ai-title b { display: block; font-size: 14px; font-weight: 800; }
.ai-title small { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.ai-x {
  width: 28px;
  height: 28px;
  padding: 0;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.ai-x:hover { background: #eef1f9; color: var(--ink); }

.ai-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.msg {
  max-width: 86%;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 16px;
  animation: msgIn 0.2s ease-out;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg.bot { align-self: flex-start; background: #f1f4fb; border-bottom-left-radius: 5px; }
.msg.me  { align-self: flex-end; color: #fff; background: var(--accent); border-bottom-right-radius: 5px; }
.msg.typing { display: flex; gap: 4px; padding: 12px 14px; }
.msg.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa6c6;
  animation: dot 1s infinite ease-in-out;
}
.msg.typing i:nth-child(2) { animation-delay: 0.15s; }
.msg.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.chips { align-self: flex-end; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; animation: msgIn 0.25s ease-out; }
.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  background: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 99px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chip:hover { color: #fff; background: var(--accent); }

#hint { max-width: calc(100% - 340px); }

@media (max-height: 520px) {
  #builder { right: 8px; bottom: 6px; gap: 6px; }
  .ai-fab { font-size: 12px; padding: 4px 12px 4px 4px; }
  #builder .av { width: 26px; height: 26px; }
  .ai-panel { max-height: calc(100dvh - 130px); }
  .msg, .chip { font-size: 12px; }
  #hint { max-width: calc(100% - 200px); }
}

/* ======================================================================
   YENİ: üst çubuk menüleri, mod anahtarı, kart durumları, AI giriş, RTL
   ====================================================================== */

/* ---------- Üst çubuk ---------- */
.topbar { position: relative; z-index: 20; }
.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.progress { flex: none; }
.dd { position: relative; }
.dd-btn { display: flex; align-items: center; gap: 7px; }
.dd-btn svg {
  width: 17px; height: 17px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.dd-btn .chev { width: 14px; height: 14px; opacity: 0.6; }
.dd-label { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 50;
  min-width: 190px;
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(28, 36, 64, 0.22);
  animation: aiIn 0.18s ease-out;
  transform-origin: 100% 0;
}
.dd-menu[hidden] { display: none; }
.dd-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  text-align: start;
  background: transparent;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
}
.dd-item:hover { background: var(--accent-soft); }
.dd-item.on { color: var(--accent); }
.dd-item .chk { width: 16px; flex: none; font-size: 14px; text-align: center; }
.dd-item.on .chk::before { content: '✓'; }
.dd-item .nm { flex: 1; }
.dd-item .badge {
  font-size: 10px; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); border-radius: 99px; padding: 2px 7px;
}

/* ---------- Sıralı / Serbest anahtarı ---------- */
.seg {
  display: flex;
  gap: 2px;
  margin: 0 12px 6px;
  padding: 3px;
  background: #e8ecf7;
  border-radius: 99px;
}
.seg button {
  flex: 1;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 99px;
  padding: 5px 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg button.on { color: var(--accent); background: #fff; box-shadow: 0 1px 4px rgba(28, 36, 64, 0.15); }

/* ---------- Panel başlığı + AI paneli: sıkışmasın ---------- */
.panel-head { gap: 8px; }
.panel-head h2 { white-space: nowrap; }
.panel-head span { text-align: end; }
.ai-head, .ai-quick, .ai-form { flex: none; }

/* ---------- Parça kartı durumları ---------- */
.card .meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.next {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 107, 255, 0.16), 0 6px 18px rgba(79, 107, 255, 0.18);
}
.card.next .tag { color: #fff; background: var(--accent); }
.card.locked { opacity: 0.55; filter: saturate(0.6); }
.card.locked:hover { border-color: var(--line); box-shadow: none; }
.card.locked .tag { color: var(--muted); background: #eef1f9; }
.card.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.card.blink { animation: blink 0.7s ease-in-out 3; }
@keyframes blink {
  50% { border-color: var(--accent); box-shadow: 0 0 0 6px rgba(79, 107, 255, 0.28); }
}

/* ---------- Bitiş mesajı: sığmazsa alta kayar ---------- */
#toast {
  flex-wrap: wrap;
  justify-content: center;
  white-space: normal;
  border-radius: 28px;
  max-width: calc(100% - 250px);
}
#toast button[hidden] { display: none; }

/* ---------- Builder AI: giriş alanı, hızlı butonlar, okunmamış noktası ---------- */
.ai-quick {
  display: flex;
  gap: 6px;
  padding: 6px 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.ai-quick::-webkit-scrollbar { display: none; }
.qbtn {
  flex: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: #f1f4fb;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 11px;
  cursor: pointer;
}
.qbtn:hover { color: var(--accent); border-color: var(--accent); }
.ai-form { display: flex; align-items: center; gap: 6px; padding: 8px 10px 10px; }
.ai-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: #f5f7fc;
  border: 1.5px solid var(--line);
  border-radius: 99px;
  padding: 8px 14px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.ai-form input:focus { border-color: var(--accent); background: #fff; }
.ai-send {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  padding: 0;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.ai-send svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
html[dir="rtl"] .ai-send svg { transform: scaleX(-1); }
.ai-fab { position: relative; }
.ai-fab.unread::after {
  content: '';
  position: absolute;
  top: 2px;
  inset-inline-end: 2px;
  width: 11px; height: 11px;
  background: #ff5a5f;
  border: 2px solid #fff;
  border-radius: 50%;
}

/* ---------- Sağdan sola diller (Arapça): yerleşim sabit, metinler sağdan sola ---------- */
html[dir="rtl"] .layout { direction: ltr; }
html[dir="rtl"] .panel,
html[dir="rtl"] .ai-panel,
html[dir="rtl"] #toast,
html[dir="rtl"] #hint { direction: rtl; }
html[dir="rtl"] body,
html[dir="rtl"] .bar { font-family: 'Noto Sans Arabic', 'Plus Jakarta Sans', system-ui, sans-serif; }
html[dir="rtl"] .bar { direction: ltr; }
html[dir="rtl"] #cube .f { letter-spacing: 0; padding: 0; }   /* Arapça harfler birleşik yazılır */

/* ---------- Alçak ekran (telefon yatay) ---------- */
@media (max-height: 520px) {
  .layout { grid-template-columns: 150px 1fr; }
  .panel-head { padding: 8px 10px 4px; gap: 4px; }
  .panel-head h2 { font-size: 12.5px; }
  .panel-head span { font-size: 10.5px; }
  .ai-panel { max-height: calc(100dvh - 112px); }
  .ai-head { padding: 6px 8px 6px 10px; }
  .dd-label { display: none; }
  .dd-btn .chev { display: none; }
  .dd-btn { padding: 4px 9px; }
  .dd-menu { min-width: 160px; }
  .dd-item { padding: 6px 10px; font-size: 13px; }
  .seg { margin: 0 6px 4px; }
  .seg button { font-size: 11px; padding: 3px 4px; }
  #toast { max-width: calc(100% - 150px); gap: 8px; font-size: 14px; }
  #toast button { font-size: 12px; padding: 5px 10px; }
  .ai-quick { padding: 4px 8px 0; }
  .qbtn { font-size: 11px; padding: 3px 9px; }
  .ai-form { padding: 6px 8px 8px; }
  .ai-form input { font-size: 12px; padding: 6px 12px; }
  .ai-send { width: 30px; height: 30px; }
}


/* ---------- Uyarı kutusu (models.json okunamadı vb.) ---------- */
#notice {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 6;
  max-width: 560px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  color: #7a2b00;
  background: #fff3e0;
  border: 1px solid #ffc27a;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(28, 36, 64, 0.15);
  user-select: text;
}
#notice[hidden] { display: none; }
@media (max-height: 520px) { #notice { font-size: 11.5px; padding: 6px 10px; max-width: calc(100% - 130px); } }

/* ---------- Telefon yatay: bitiş mesajı küçük tek satırlık şerit olsun (modelin üstünü kapatmasın) ---------- */
@media (max-height: 520px) {
  #toast {
    top: 6px;
    max-width: calc(100% - 124px);       /* sağdaki araç sütunu için yer bırak */
    flex-wrap: wrap;
    row-gap: 4px;
    gap: 6px;
    padding: 4px 6px 4px 10px;
    border-radius: 18px;
    font-size: 13px;
  }
  #toastMsg { font-size: 0; line-height: 1; }          /* uzun cümle yerine sadece 🎉 */
  #toastMsg::before { content: '🎉'; font-size: 16px; }
  #toast button { font-size: 11px; padding: 5px 9px; white-space: nowrap; }
}

/* Bitiş mesajı: left:50% yüzünden alanın yalnızca yarısı kadar genişleyip alt alta diziliyordu; içeriğe göre genişlesin */
#toast { width: max-content; max-width: calc(100% - 140px); }
@media (max-height: 520px) { #toast { max-width: calc(100% - 124px); } }

/* Telefon yatay: "Tekrar oyna" üstteki "↺ Baştan" ile aynı işi yapar, yer açmak için gizle */
@media (max-height: 520px) {
  #toast #again { display: none; }
  #toast button { padding: 5px 8px; }
}

/* ---------- Telefon yatay: sağ araç sütunu ve alt ipucu daha kompakt ---------- */
@media (max-height: 520px) {
  .tools { top: 4px; right: 6px; gap: 4px; }
  .cube-wrap { width: 62px; height: 62px; }
  .tool { width: 30px; height: 30px; }
  .tool svg { width: 16px; height: 16px; }
  #hint { font-size: 10.5px; line-height: 1.25; padding: 3px 10px; }
  /* bitiş şeridi görünürken ipucu gereksiz (aynı bilgiyi zaten veriyor) */
  .viewer:has(#toast.show) #hint { display: none; }
}

/* ---------- Model seçici (açılır pencere) ---------- */
.mp {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(20, 28, 56, 0.45);
  backdrop-filter: blur(4px);
  animation: mpFade 0.15s ease-out;
}
.mp[hidden] { display: none; }
.mp-box {
  width: min(900px, 100%); max-height: 100%;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 22px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(28, 36, 64, 0.35);
  animation: mpPop 0.2s ease-out;
}
.mp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.mp-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.mp-x {
  width: 36px; height: 36px; padding: 0; font-size: 24px; line-height: 1;
  color: var(--accent); background: var(--accent-soft); border: 0; border-radius: 50%; cursor: pointer;
}
.mp-grid {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
  padding: 16px 18px 20px;
}
.mp-card {
  position: relative; display: flex; flex-direction: column; gap: 8px;
  padding: 8px 8px 10px; font: inherit; color: var(--ink); text-align: center;
  background: #fff; border: 2px solid var(--line); border-radius: 16px; cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.mp-card:hover { border-color: var(--accent); box-shadow: 0 8px 20px rgba(79, 107, 255, 0.18); transform: translateY(-2px); }
.mp-card.on { border-color: var(--accent); background: var(--accent-soft); }
.mp-img { display: block; aspect-ratio: 4 / 3; border-radius: 11px; background: #eef1f8 center / contain no-repeat; }
.mp-img:not(.ready) {
  background-image: linear-gradient(100deg, #eef1f8 30%, #f8faff 50%, #eef1f8 70%);
  background-size: 200% 100%; animation: mpShimmer 1.2s linear infinite;
}
.mp-nm { min-height: 2.5em; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; line-height: 1.25; }
.mp-badge {
  position: absolute; top: 12px; inset-inline-end: 12px;
  font-size: 10px; font-style: normal; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); border-radius: 99px; padding: 2px 7px;
}
@keyframes mpFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mpPop { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes mpShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (max-height: 520px) {
  .mp-head { padding: 8px 14px; }
  .mp-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; padding: 10px 12px 14px; }
  .mp-nm { font-size: 12px; }
}

/* ---------- Telefon yatay: bitişte yalnızca "Animasyonu başlat" butonu, sol altta ---------- */
@media (max-height: 520px) {
  #toast {
    top: auto; bottom: 8px; left: max(8px, env(safe-area-inset-left)); right: auto;
    width: auto; max-width: none; padding: 0;
    background: transparent; box-shadow: none; border-radius: 99px;
    transform: translateY(12px) scale(0.9); transform-origin: left bottom;
  }
  #toast.show { transform: none; }
  #toast #toastMsg, #toast #nextModel, #toast #again { display: none; }         /* tebrik mesajı ve diğer butonlar mobilde gösterilmez */
  #toast:has(#animBtn[hidden]) { display: none; }                                 /* animasyonu olmayan modelde boş şerit kalmasın */
  #toast #animBtn { padding: 8px 16px; font-size: 13px; box-shadow: 0 6px 18px rgba(28, 36, 64, 0.25); }
}