:root {
  --bg: #0a0b10;
  --bg-2: #11131b;
  --surface: rgba(22, 25, 36, 0.78);
  --surface-2: #1a1e2b;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f2f4f8;
  --muted: #8f97ab;
  --accent: #7c9cff;
  --accent-2: #a78bfa;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

/* ---------- Üst çubuk ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 6px;
  position: relative;
  z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand-mark {
  width: 26px; height: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  padding: 3px; border-radius: 8px; background: #000; box-shadow: 0 0 0 1px var(--line-2);
}
.brand-mark i { border-radius: 3px; display: block; }
.brand-mark i:nth-child(1) { background: #D62839; }
.brand-mark i:nth-child(2) { background: #F5F7FA; }
.brand-mark i:nth-child(3) { background: #2563EB; }
.brand-mark i:nth-child(4) { background: #FACC15; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; font-size: 17px; white-space: nowrap; }

.solver-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
  transition: color .3s, background .3s, border-color .3s;
}
.solver-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.solver-pill[data-state="ready"] { color: #bfeedd; border-color: rgba(52, 211, 153, .25); background: rgba(52, 211, 153, .08); }
.solver-pill[data-state="ready"] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: none; }
.solver-pill[data-state="error"] .dot { background: var(--bad); animation: none; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04); display: inline-grid; place-items: center; cursor: pointer;
  transition: background .2s, transform .15s var(--ease), opacity .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn.lg { width: 54px; height: 54px; border-radius: 16px; }

/* ---------- Sahne ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 200px;
  position: relative;
  overflow: hidden;
}
.stage-glow {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(55% 45% at 50% 50%, rgba(124, 156, 255, 0.16), transparent 70%),
    radial-gradient(40% 30% at 50% 85%, rgba(167, 139, 250, 0.10), transparent 70%);
}
.cube-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.cube-canvas.is-editable { cursor: crosshair; }
.stage-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 12.5px; color: var(--muted); background: rgba(10, 11, 16, .6); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

/* ---------- Panel ---------- */
.panel {
  position: relative; z-index: 2;
  margin: 0 10px calc(10px + var(--safe-b));
  padding: 18px 16px 16px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
.view { animation: viewIn .38s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.hero-title { margin: 0 0 6px; font-size: clamp(24px, 6.4vw, 32px); line-height: 1.12; letter-spacing: -0.025em; font-weight: 800; }
.hero-title span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { margin: 0 0 16px; color: var(--muted); font-size: 14.5px; }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.view-head h2 { margin: 0; font-size: 19px; letter-spacing: -0.015em; }
.muted { color: var(--muted); margin: 3px 0 0; font-size: 13.5px; }

/* ---------- Düğmeler ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 48px; padding: 0 16px; border-radius: 14px; border: 1px solid transparent;
  font-weight: 650; font-size: 15px; cursor: pointer; user-select: none;
  transition: transform .15s var(--ease), background .2s, opacity .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-xl { width: 100%; min-height: 58px; font-size: 17px; border-radius: 16px; }
.btn-primary {
  color: #0a0b10;
  background: linear-gradient(180deg, #f4f6ff, #c9d4ff);
  box-shadow: 0 8px 28px rgba(124, 156, 255, .28), inset 0 1px 0 #fff;
}
.btn-primary:hover { box-shadow: 0 10px 34px rgba(124, 156, 255, .4), inset 0 1px 0 #fff; }
.btn-primary svg { stroke-width: 2.4; }
.btn-ghost { background: rgba(255, 255, 255, .05); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, .09); }
.btn-chip { min-height: 36px; padding: 0 14px; border-radius: 999px; font-size: 13.5px; background: rgba(255, 255, 255, .06); border-color: var(--line); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1 1 0; min-width: 0; }
.btn.is-loading span::after { content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 10px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Geçerlilik rozeti ---------- */
.badge {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap;
  border: 1px solid; transition: all .25s;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge[data-state="ok"] { color: var(--ok); border-color: rgba(52, 211, 153, .3); background: rgba(52, 211, 153, .08); }
.badge[data-state="warn"] { color: var(--warn); border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .08); }
.badge[data-state="bad"] { color: var(--bad); border-color: rgba(248, 113, 113, .3); background: rgba(248, 113, 113, .08); }

/* ---------- Palet ---------- */
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px; }
.swatch {
  position: relative; aspect-ratio: 1; min-height: 44px; border-radius: 14px; cursor: pointer;
  border: 2px solid rgba(255, 255, 255, .1);
  box-shadow: inset 0 -6px 12px rgba(0, 0, 0, .18), inset 0 2px 0 rgba(255, 255, 255, .25);
  transition: transform .18s var(--ease), border-color .2s, box-shadow .2s;
}
.swatch:active { transform: scale(.93); }
.swatch[aria-checked="true"] { border-color: #fff; transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0, 0, 0, .4), 0 0 0 3px rgba(124, 156, 255, .5), inset 0 2px 0 rgba(255, 255, 255, .25); }
.swatch .count {
  position: absolute; right: -4px; bottom: -6px; min-width: 22px; padding: 1px 5px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-align: center; color: var(--text);
  background: #0d0f16; border: 1px solid var(--line-2);
}
.swatch .count.bad { color: var(--bad); border-color: rgba(248, 113, 113, .5); }

/* ---------- Çözüm ---------- */
.solve-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.counter { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.counter small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }

.chips {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; scroll-behavior: smooth;
  padding: 4px 2px 10px; margin: 0 -2px; scrollbar-width: none;
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; scroll-snap-align: center; min-width: 52px; height: 52px; padding: 0 12px; border-radius: 14px;
  display: grid; place-items: center; cursor: pointer;
  font-size: 19px; font-weight: 750; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line); color: var(--text);
  transition: background .25s, color .25s, transform .25s var(--ease), border-color .25s, box-shadow .25s, opacity .25s;
}
.chip.done { opacity: .38; }
.chip.current {
  background: linear-gradient(180deg, #eef2ff, #c3cffe); color: #0a0b10; border-color: transparent; opacity: 1;
  transform: translateY(-2px) scale(1.06); box-shadow: 0 8px 22px rgba(124, 156, 255, .35);
}
.explain { margin: 4px 0 12px; min-height: 1.45em; font-size: 16.5px; font-weight: 600; text-align: center; letter-spacing: -0.01em; }
.explain.done { color: var(--ok); }

.transport { display: flex; align-items: center; justify-content: center; gap: 12px; }
.transport-spacer { width: 54px; }
.play-btn {
  width: 72px; height: 72px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  color: #0a0b10; background: linear-gradient(180deg, #f4f6ff, #c3cffe);
  box-shadow: 0 10px 30px rgba(124, 156, 255, .35), inset 0 1px 0 #fff;
  transition: transform .15s var(--ease);
}
.play-btn svg { width: 30px; height: 30px; }
.play-btn:active { transform: scale(.93); }
.play-btn .i-pause { display: none; }
.play-btn.playing .i-pause { display: block; }
.play-btn.playing .i-play { display: none; }
.play-btn:disabled { opacity: .45; pointer-events: none; }

.speed { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13.5px; color: var(--muted); }
.speed output { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.speed input { flex: 1; appearance: none; -webkit-appearance: none; height: 28px; background: transparent; cursor: pointer; }
.speed input::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .12); }
.speed input::-moz-range-track { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .12); }
.speed input::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: #eef2ff; box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
.speed input::-moz-range-thumb { width: 24px; height: 24px; border: 0; border-radius: 50%; background: #eef2ff; }

/* ---------- Tarayıcı & bildirim ---------- */
#scanner { position: fixed; inset: 0; z-index: 50; background: #000; }
body.scanning { overflow: hidden; }

.toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); z-index: 60;
  transform: translateX(-50%); max-width: min(92vw, 520px);
  padding: 12px 16px; border-radius: 14px; font-size: 14.5px; font-weight: 550; text-align: center;
  background: rgba(24, 27, 38, .96); border: 1px solid var(--line-2); box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  animation: toastIn .3s var(--ease) both;
}
.toast.bad { border-color: rgba(248, 113, 113, .45); }
.toast.ok { border-color: rgba(52, 211, 153, .45); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (min-width: 760px) {
  .panel { margin-bottom: 20px; padding: 22px; }
}
@media (max-height: 640px) {
  .hero-sub { display: none; }
  .btn-xl { min-height: 52px; }
  .play-btn { width: 62px; height: 62px; }
}
@media (prefers-reduced-motion: reduce) {
  .view, .toast { animation: none; }
  .chips { scroll-behavior: auto; }
}

/* Düzenleme aracı seçici */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 12px; border-radius: 999px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); }
.seg-btn { min-height: 40px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-weight: 650; font-size: 14px; cursor: pointer; transition: background .2s, color .2s; }
.seg-btn[aria-selected="true"] { background: rgba(255, 255, 255, .12); color: var(--text); }
body[data-tool="twist"] .palette { opacity: .35; pointer-events: none; }
/* Bozuk küp yardım kartı */
.fix-card { margin: 0 0 12px; padding: 12px 14px; border-radius: 14px; border: 1px solid rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .08); }
.fix-card p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.45; color: var(--text); }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 14px; }

/* Ana sayfa: bozuk küp çağrısı */
.repair-cta { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 12px; padding: 12px 14px; text-align: left;
  border-radius: 14px; border: 1px dashed rgba(251, 191, 36, .45); background: rgba(251, 191, 36, .06); color: var(--text); font: inherit; cursor: pointer; }
.repair-cta:hover { background: rgba(251, 191, 36, .11); }
.repair-cta svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--warn); stroke-width: 1.8; stroke-linejoin: round; }
.repair-cta span { display: flex; flex-direction: column; gap: 2px; }
.repair-cta strong { font-size: 14.5px; }
.repair-cta small { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.fix-card[data-kind="ok"] { border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .08); }
