/* Dotify v2. One accent, the dot violet; photos carry the colour, the interface stays quiet. */
:root {
  --violet: #7b3ff2;
  --violet-ink: #5a24c9;
  --violet-soft: #efe8fe;
  --ink: #17142b;
  --mist: #6f6a86;
  --line: #e4e1ee;
  --paper: #f7f6fb;
  --surface: #ffffff;
  --danger: #c62f4b;
  --ok: #1f8a5b;
  --stage: #ebe9f2;
  --radius-s: 8px;
  --radius-m: 14px;
  --dot: 34px;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --violet: #9a6bff;
    --violet-ink: #b796ff;
    --violet-soft: #2a2148;
    --ink: #efedf7;
    --mist: #a39fba;
    --line: #2f2b45;
    --paper: #121020;
    --surface: #1b1830;
    --stage: #0c0b16;
    --danger: #ff6b86;
    --ok: #4cc58c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 750; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--violet-ink); }
.muted { color: var(--mist); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .grow { flex: 1; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font: 800 1.15rem var(--font-display); }
.brand-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--line); }
.title-button { all: unset; cursor: pointer; display: block; font: 700 1rem var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-button:focus-visible { outline: 3px solid var(--violet); border-radius: 4px; }

/* ---- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid transparent;
  font: 600 .95rem var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--violet); color: #fff; border-color: var(--violet); }
.btn-primary:not(:disabled):active { background: var(--violet-ink); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width: 100%; }
.icon-btn {
  all: unset; box-sizing: border-box; width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink); flex: none;
}
.icon-btn:active { background: var(--line); }
.icon-btn:focus-visible { outline: 3px solid var(--violet); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 46px; padding: 11px 14px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
textarea.input { resize: vertical; min-height: 84px; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
.form-error { color: var(--danger); font-size: .9rem; margin: 0 0 12px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.choice:last-child { border-bottom: 0; }
.choice input { margin-top: 4px; accent-color: var(--violet); width: 18px; height: 18px; flex: none; }
.choice b { display: block; font-weight: 650; }
.choice small { color: var(--mist); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--mist); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---- page layouts */
.page { width: 100%; max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; }
.narrow { max-width: 420px; }
.banner { background: var(--violet-soft); color: var(--ink); padding: 10px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner button { all: unset; cursor: pointer; font-weight: 650; color: var(--violet-ink); text-decoration: underline; }

/* ---- home */
.hero { padding: 44px 0 28px; display: grid; gap: 28px; align-items: center; }
@media (min-width: 820px) { .hero { grid-template-columns: 1.1fr 1fr; padding-top: 72px; } }
.hero h1 { font-size: clamp(2.1rem, 7vw, 3.4rem); max-width: 14ch; }
.hero p { font-size: 1.1rem; color: var(--mist); max-width: 36ch; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-art { position: relative; aspect-ratio: 4/3; border-radius: var(--radius-m); overflow: hidden;
  background:
    linear-gradient(180deg, transparent 62%, rgba(0,0,0,.18) 62.4%, rgba(0,0,0,.06) 100%),
    linear-gradient(90deg, #d9cfc2 0 18%, #e8e0d4 18% 70%, #cfc4b5 70%);
}
.hero-art .win { position: absolute; left: 30%; top: 16%; width: 26%; height: 36%; background: linear-gradient(#bfe0f4, #e7f4fb); border: 6px solid #f8f5ef; }
.hero-art .door { position: absolute; left: 75%; top: 24%; width: 14%; height: 38.5%; background: #9a7b5f; border: 5px solid #f8f5ef; border-bottom: 0; }
.hero-art .sofa { position: absolute; left: 8%; top: 52%; width: 40%; height: 18%; background: #5e6b7d; border-radius: 10px 10px 4px 4px; }
.steps-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 18px; counter-reset: s; }
@media (min-width: 720px) { .steps-list { grid-template-columns: repeat(3, 1fr); } }
.steps-list li { counter-increment: s; padding-left: 44px; position: relative; }
.steps-list li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--violet); color: #fff; display: grid; place-items: center; font: 700 .9rem var(--font-display); }
.footer { margin-top: auto; padding: 24px 16px calc(24px + var(--safe-b)); display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; font-size: .85rem; color: var(--mist); }
.footer a, .footer button { color: var(--mist); }
.footer select { background: transparent; color: var(--mist); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font: inherit; }

/* ---- my projects */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 .875rem var(--font-body); cursor: pointer; }
.tab[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.grid { display: grid; gap: 18px 14px; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }
.tile { text-decoration: none; color: inherit; display: block; min-width: 0; }
.tile-img { aspect-ratio: 4/3; border-radius: var(--radius-s); overflow: hidden; background: var(--stage); position: relative; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-img .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--mist); }
.tile-name { font-weight: 650; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { font-size: .8rem; color: var(--mist); display: flex; gap: 8px; flex-wrap: wrap; }
.status { display: inline-block; font-size: .75rem; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--violet-soft); color: var(--violet-ink); }
.status-draft { background: var(--line); color: var(--mist); }
.tile-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tile-actions .btn { min-height: 34px; padding: 0 12px; font-size: .8rem; }
.new-tile { aspect-ratio: 4/3; border-radius: var(--radius-s); border: 2px dashed var(--line); display: grid; place-items: center; color: var(--violet-ink); font-weight: 650; text-decoration: none; text-align: center; }
.empty { text-align: center; padding: 48px 16px; color: var(--mist); }

/* ---- the stage: one photo with its dots */
.stage-wrap { background: var(--stage); display: grid; place-items: center; padding: 0; position: relative; }
.stage {
  position: relative; width: min(100%, calc(var(--maxh) * var(--ar)));
  aspect-ratio: var(--ar); user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.stage > img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; -webkit-user-drag: none; }
.stage.fade-in > img { animation: fadeIn .28s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: scale(1.015); } to { opacity: 1; transform: none; } }
.stage.mode-add { cursor: crosshair; }
.stage-empty {
  width: 100%; min-height: min(62vh, 520px); display: grid; place-items: center; text-align: center; padding: 24px; color: var(--mist);
}
.stage-empty .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; width: min(280px, 100%); margin-inline: auto; }
.deleted-photo { position: absolute; inset: 0; display: grid; place-items: center; backdrop-filter: blur(16px); background: rgba(40,36,60,.45); color: #fff; font-weight: 650; }

.dot {
  position: absolute; width: var(--dot); height: var(--dot); margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2);
  border-radius: 50%; border: 3px solid #fff; padding: 0;
  background: rgba(123, 63, 242, .62); color: #fff; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.15);
  display: grid; place-items: center; font: 800 13px/1 var(--font-display);
  transition: opacity .25s, transform .15s;
  animation: pulse 2.2s ease-in-out infinite;
  touch-action: none;
}
.dot::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); opacity: 0; animation: halo 2.2s ease-out infinite; pointer-events: none; }
.dot svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.dot.empty { background: rgba(23, 20, 43, .45); border-style: dashed; }
.dot.dragging { animation: none; transform: scale(1.25); z-index: 5; }
.dot.mode-delete { background: rgba(198, 47, 75, .78); }
.dot:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.stage.faint .dot { opacity: .16; animation: none; }
.stage.faint .dot::after { display: none; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes halo { 0% { opacity: .8; transform: scale(.75); } 70%, 100% { opacity: 0; transform: scale(1.35); } }
@media (prefers-reduced-motion: reduce) {
  .dot, .dot::after, .stage.fade-in > img, dialog.sheet[open], .toast { animation: none !important; }
}

/* trail of steps: title photo > A > C */
.trail { display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 8px 16px; scrollbar-width: none; font-size: .85rem; }
.trail::-webkit-scrollbar { display: none; }
.trail button { all: unset; cursor: pointer; padding: 4px 8px; border-radius: 999px; color: var(--mist); white-space: nowrap; }
.trail button[aria-current="step"] { background: var(--violet-soft); color: var(--violet-ink); font-weight: 700; }
.trail .sep { width: 5px; height: 5px; border-radius: 50%; background: var(--line); flex: none; }

/* ---- editor */
.editor { display: flex; flex-direction: column; flex: 1; padding-bottom: calc(76px + var(--safe-b)); }
.editor .stage-wrap { --maxh: 62vh; }
.editor-body { padding: 4px 16px 24px; max-width: 760px; width: 100%; margin: 0 auto; }
.title-block { overflow: hidden; display: flex; flex-direction: column; line-height: 1.25; }
.title-block .title-button { max-width: 100%; }
.save-state { font-size: .75rem; color: var(--mist); min-height: 1em; }
.save-state.error { color: var(--danger); }
.hint { font-size: .875rem; color: var(--mist); padding: 10px 16px 0; text-align: center; min-height: 1.5em; }
.toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 2px;
  padding: 6px 8px calc(6px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line);
}
.tool {
  all: unset; box-sizing: border-box; cursor: pointer; flex: 1; max-width: 92px; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 12px; font-size: .72rem; font-weight: 600; color: var(--mist);
}
.tool svg { width: 24px; height: 24px; }
.tool[aria-pressed="true"] { color: var(--violet-ink); background: var(--violet-soft); }
.tool:disabled { opacity: .35; cursor: default; }
.tool:focus-visible { outline: 3px solid var(--violet); }

/* ---- viewer */
.viewer { display: flex; flex-direction: column; flex: 1; }
.viewer .stage-wrap { --maxh: 72vh; }
.viewer-head { padding: 14px 16px 0; max-width: 760px; margin: 0 auto; width: 100%; }
.viewer-head h1 { font-size: 1.45rem; margin-bottom: 4px; }
.viewer-controls { display: flex; align-items: center; gap: 4px; padding: 6px 8px; max-width: 760px; margin: 0 auto; width: 100%; }
.viewer-controls .grow { flex: 1; min-width: 0; }
.step-text { padding: 4px 16px 18px; max-width: 760px; margin: 0 auto; width: 100%; white-space: pre-wrap; }
.project-text { white-space: pre-wrap; color: var(--mist); margin: 0 0 6px; }
.embed { height: 100%; }
.embed .stage-wrap { --maxh: calc(100vh - 56px); flex: 1; }
.embed-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--line); }
.embed-bar .name { flex: 1; min-width: 0; font: 700 .95rem var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- bottom sheet / dialog */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 520px; margin: auto auto 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--ink); max-height: 92vh;
}
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 18px; } }
dialog.sheet::backdrop { background: rgba(14, 11, 30, .5); }
dialog.sheet[open] { animation: sheetIn .22s ease-out; }
@keyframes sheetIn { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { padding: 20px 20px calc(20px + var(--safe-b)); overflow-y: auto; max-height: 92vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.share-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 16px; }
.share-row .btn { flex-direction: column; min-height: 72px; border-radius: var(--radius-m); gap: 4px; font-size: .8rem; }
.code-box { font: .8rem/1.4 ui-monospace, Menlo, monospace; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px; width: 100%; min-height: 70px; color: var(--ink); }

/* ---- toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(86px + var(--safe-b)); z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: 440px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: sheetIn .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { all: unset; cursor: pointer; font-weight: 700; text-decoration: underline; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--violet); animation: spin .8s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.legal { max-width: 720px; }
.legal h2 { margin-top: 1.5em; }
