:root {
  --bg: #f6f3ee; --card: #ffffff; --ink: #1f1c18; --muted: #7a7268; --line: #e5dfd6;
  --accent: #b8643a; --accent-ink: #fff; --warn: #c98a12; --ok: #3d8b5a;
  --panel-h: auto;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141210; --card: #1f1c19; --ink: #f2ede6; --muted: #a39b90; --line: #36302a; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Katalog ---------- */
#catalog { min-height: 100%; padding: calc(16px + env(safe-area-inset-top)) 16px 32px; max-width: 1100px; margin: 0 auto; }
.cat-head .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; }
.cat-head .brand img { width: 36px; height: 36px; border-radius: 10px; }
.cat-head p { color: var(--muted); margin: 6px 0 18px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  text-align: left; display: flex; flex-direction: column; gap: 8px;
}
.card .thumb { aspect-ratio: 1; display: grid; place-items: center; background: var(--bg); border-radius: 10px; padding: 14px; }
.card .thumb img { max-width: 100%; max-height: 100%; }
.card b { font-size: 15px; }
.card .meta { font-size: 12px; color: var(--muted); }
.card .dots { display: flex; gap: 4px; }
.card .dots i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line); }

/* ---------- Stüdyo ---------- */
#studio { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; background: #000; }
.topbar {
  display: flex; align-items: center; gap: 8px; background: var(--card); color: var(--ink);
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px; border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; font-size: 22px; border-radius: 10px; }

#stage { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; min-height: 0; }
#bgImg, #bgVid { position: absolute; max-width: none; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#prodCv { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#dimChip {
  position: absolute; transform: translate(-50%, 6px); pointer-events: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
#badge {
  position: absolute; left: 10px; top: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
#badge span, #badge button {
  pointer-events: auto; border: 0; font-size: 12px; padding: 5px 10px; border-radius: 99px;
  background: rgba(20,18,16,.72); color: #fff; backdrop-filter: blur(6px);
}
#badge .est { background: rgba(201,138,18,.9); }
#badge .ok { background: rgba(61,139,90,.9); }
#hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: rgba(20,18,16,.8); color: #fff; padding: 10px 14px; border-radius: 12px; text-align: center;
  font-size: 14px; pointer-events: none;
}
#stageBtns { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 10px; }
.pill { border: 0; padding: 11px 18px; border-radius: 99px; background: rgba(255,255,255,.92); color: #1f1c18; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.pill-accent { background: var(--accent); color: var(--accent-ink); }

.chooser {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; background: var(--bg); color: var(--ink); text-align: center;
}
.chooser img { max-width: 60%; max-height: 28%; }
.chooser h2 { margin: 6px 0; font-size: 19px; }
.chooser p { max-width: 320px; }
.big-btn {
  width: min(320px, 100%); display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; border-radius: 14px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16px;
}
.big-btn-ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); cursor: pointer; }

#spinner {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); color: #fff;
}
.spin { width: 38px; height: 38px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: sp 0.9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- Panel ---------- */
#panel {
  background: var(--card); color: var(--ink); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  max-height: 42vh; overflow-y: auto;
}
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row .label { flex: 0 0 64px; font-size: 12px; color: var(--muted); }
.row .label b { display: block; color: var(--ink); font-weight: 600; }
.swatches, .chips { display: flex; gap: 6px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.swatch { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg); padding: 6px 11px; border-radius: 99px; font-size: 13px; white-space: nowrap; }
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
#light, #angle { flex: 1; accent-color: var(--accent); min-width: 0; }
.replace-tip { background: var(--bg); border: 1px dashed var(--accent); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin: 8px 0 0; }
.ref-replace { width: 100%; margin-top: 10px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.btn { border: 1px solid var(--line); background: var(--bg); padding: 9px 6px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; }

@media (min-width: 820px) and (orientation: landscape) {
  #studio { grid-template-columns: 1fr 320px; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  #panel { max-height: none; border-top: 0; border-left: 1px solid var(--line); gap: 16px; padding: 16px; }
  .row { flex-direction: column; align-items: stretch; }
  .row .label { flex: none; }
  .swatches, .chips { flex-wrap: wrap; }
  .actions { grid-template-columns: 1fr 1fr; margin-top: auto; }
  .actions .btn-accent { grid-column: 1 / -1; padding: 12px; }
}

/* ---------- Referans sayfası ---------- */
.sheet { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; z-index: 20; }
.sheet-card {
  pointer-events: auto; background: var(--card); color: var(--ink); width: min(560px, 100%);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(14px + env(safe-area-inset-bottom));
  max-height: 58vh; overflow-y: auto; box-shadow: 0 -8px 30px rgba(0,0,0,.3);
}
@media (min-width: 820px) { .sheet { align-items: center; justify-content: flex-end; padding-right: 336px; } .sheet-card { border-radius: 18px; max-height: 80vh; } }
.sheet-card h3 { margin: 0 0 4px; font-size: 17px; }
.ref { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 10px; }
.ref.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ref-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.ref-num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; flex: 0 0 22px; }
.ref-q { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.ref-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.ref-fields label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.ref-fields input[type=number] {
  font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 100%;
}
.ref-fields .chk { flex-direction: row; align-items: center; gap: 6px; grid-column: 1 / -1; }
.ref-more { font-size: 12px; margin-top: 6px; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 10px 0 0; font-weight: 600; font-size: 14px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { padding: 12px 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1f1c18; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); font-size: 14px;
}
