@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');

*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  user-select: none; -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #e8e4dc;
  --ink: #111;
  --white: #fff;
  --red: #c03030;
  --muted: #999;
  --border: #ddd;
  --blue: #4a7fc1;
  --green: #1a9e5a;
  --sh: 0 4px 24px rgba(0,0,0,.14), 0 1px 4px rgba(0,0,0,.08);
}

html { height: 100%; height: -webkit-fill-available; }

body {
  background: var(--bg);
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  font-family: 'Space Mono', monospace;
  overflow: hidden;
  color: var(--ink);
}

/* ── Top bar ── */
#top {
  height: 44px; flex-shrink: 0;
  display: flex; align-items: center;
  padding: 0 10px; gap: 8px;
  background: var(--white);
  border-bottom: 2px solid var(--ink);
  font-size: 10px; color: var(--muted);
  z-index: 10; overflow: hidden;
}
.brand { font-size: 12px; font-weight: 700; color: var(--ink); letter-spacing: .1em; white-space: nowrap; }
.sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }
.stat b { color: var(--ink); font-size: 10px; }

/* PRO badge */
#tier-badge {
  font-size: 8px; font-weight: 700; letter-spacing: .1em;
  padding: 2px 6px; border-radius: 20px; white-space: nowrap; flex-shrink: 0;
}
.tier-free { background: #f0e8d0; color: #996600; border: 1px solid #ddb; }
.tier-pro  { background: var(--ink); color: #fff; border: 1px solid var(--ink); }
.upgrade-top-btn {
  padding: 3px 8px; border-radius: 20px; border: 1.5px solid var(--ink);
  background: none; font: 7px 'Space Mono', monospace; letter-spacing: .1em;
  cursor: pointer; color: var(--ink); white-space: nowrap; flex-shrink: 0;
}
.upgrade-top-btn.hidden { display: none; }

/* ── Main / Viewport ── */
#middle { flex: 1; min-height: 0; position: relative; }

#vp {
  position: absolute; inset: 0;
  overflow: hidden; background: var(--bg);
  touch-action: none;
}
#vp::before {
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(0,0,0,.12) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none; z-index: 0;
}

/* ── Paper ── */
#paper {
  position: absolute; left: 0; top: 0;
  background: var(--white);
  box-shadow: 0 4px 40px rgba(0,0,0,.22), 0 1px 6px rgba(0,0,0,.1);
  transform-origin: 0 0; z-index: 1;
  width: 600px; height: 420px;
}
#dc {
  display: block; position: absolute; top: 0; left: 0;
  touch-action: none; z-index: 2; cursor: crosshair;
  width: 600px; height: 420px;
}

/* ── Reference image overlay ── */
#ref-el {
  position: absolute; z-index: 4; display: none;
  touch-action: none; cursor: move; transform-origin: top left;
}
#ref-el img { display: block; pointer-events: none; max-width: none; }

/* ── Own-style ghost overlay ── */
#style-floatie {
  position: absolute; z-index: 3; display: none;
  touch-action: none; cursor: move;
}
#style-floatie img {
  display: block; pointer-events: none;
  opacity: 0.35;
  border: 1.5px dashed rgba(74,127,193,.5);
}

/* ── HUD ── */
#hud {
  position: absolute; bottom: 12px; left: 12px;
  z-index: 5; pointer-events: none;
}
#zlbl, #rdeg {
  font-size: 9px; color: rgba(0,0,0,.35);
  font-family: 'Space Mono', monospace; letter-spacing: .06em;
}

/* ── Part tabs ── */
#part-tabs {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex;
  background: var(--white); border: 1.5px solid var(--ink);
  border-radius: 4px; overflow: hidden; box-shadow: var(--sh);
}
.ptab {
  padding: 6px 16px; border: none; background: none;
  font: 8px 'Space Mono', monospace; letter-spacing: .12em;
  cursor: pointer; color: var(--muted);
  border-right: 1px solid var(--border);
}
.ptab:last-child { border-right: none; }
.ptab.on { background: var(--ink); color: var(--white); font-weight: 700; }

/* ── Floatie layer ── */
#floatie-layer { position: absolute; inset: 0; z-index: 50; pointer-events: none; }

.floatie {
  position: absolute;
  background: rgba(255,255,255,.97);
  border: 1.5px solid var(--ink); border-radius: 6px;
  box-shadow: var(--sh); pointer-events: all;
}
.floatie.drag { box-shadow: 0 12px 48px rgba(0,0,0,.28); }

.fh {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px 4px; border-bottom: 1px solid var(--border);
  cursor: grab; background: rgba(0,0,0,.025); border-radius: 4px 4px 0 0;
}
.fh.col { border-bottom: none; border-radius: 4px; }
.fh:active { cursor: grabbing; }
.ftitle { font-size: 7.5px; letter-spacing: .18em; color: var(--muted); font-weight: 700; pointer-events: none; }
.ftog {
  width: 18px; height: 18px; background: none;
  border: 1px solid var(--border); border-radius: 3px;
  cursor: pointer; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ftog:hover { background: var(--ink); color: var(--white); border-color: var(--ink); }

.fb { padding: 8px; }
.fb.hidden { display: none; }

/* Floatie default positions */
#fq   { top: 12px; left: 12px; width: 164px; }
#ft   { top: 12px; right: 12px; width: 142px; }
#fref { top: 60px; left: 12px; width: 164px; display: none; }
#fref.show { display: block; }

/* ── Floatie internals ── */
.sec { font-size: 7px; letter-spacing: .18em; color: var(--muted); font-weight: 700; margin: 6px 0 4px; }
.sdiv { height: 1px; background: var(--border); margin: 6px 0; }

.pill {
  padding: 4px 7px; border: 1.5px solid var(--border); border-radius: 3px;
  background: none; font: 7.5px 'Space Mono', monospace; letter-spacing: .08em;
  cursor: pointer; color: var(--muted); text-align: left;
  width: 100%; display: block; margin-bottom: 3px;
}
.pill:last-child { margin-bottom: 0; }
.pill:hover { border-color: var(--ink); color: var(--ink); }
.pill.on { background: var(--ink); color: var(--white); border-color: var(--ink); }

.upbox-lbl {
  display: block; font-size: 7.5px; letter-spacing: .06em;
  color: var(--muted); line-height: 1.8; cursor: pointer; text-align: center;
}
.upbox-lbl input[type=file] { display: none; }
.upbtn {
  display: block; width: 100%; margin-top: 5px; padding: 5px 0;
  background: var(--ink); color: var(--white); border: none;
  font: 7.5px 'Space Mono', monospace; letter-spacing: .1em;
  cursor: pointer; border-radius: 2px; text-align: center;
}
.ref-thumb {
  width: 100%; height: 54px; object-fit: contain; display: none;
  margin-top: 6px; border: 1px solid var(--border);
  background: #f5f5f5; border-radius: 2px;
}
.szrow { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.szlbl { font-size: 7px; letter-spacing: .1em; color: var(--muted); white-space: nowrap; }

.swatches { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.sw {
  width: 18px; height: 18px; border-radius: 50%;
  cursor: pointer; border: 2px solid rgba(0,0,0,.12); flex-shrink: 0;
}
.sw.on { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ── Modals ── */
.modal-overlay {
  position: absolute; inset: 0; z-index: 55;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  pointer-events: all;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--white); border: 2px solid var(--ink); border-radius: 6px;
  padding: 22px 26px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 300px; width: 90%; text-align: center;
}
.modal-title { font-size: 11px; font-weight: 700; letter-spacing: .1em; }
.modal-sub   { font-size: 8px; letter-spacing: .05em; color: var(--muted); line-height: 1.7; }
.modal-btns  { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.modal-btns button {
  padding: 7px 18px; border-radius: 3px; border: none;
  font: 9px 'Space Mono', monospace; letter-spacing: .1em; cursor: pointer;
}
.btn-ink  { background: var(--ink); color: #fff; }
.btn-red  { background: var(--red); color: #fff; }
.btn-grey { background: #eee; color: var(--ink); }

/* ── PRO modal extras ── */
.pro-box { max-height: 90vh; overflow-y: auto; position: relative; gap: 8px; }
.pro-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; font-size: 15px; cursor: pointer; color: var(--muted);
}
.pro-logo  { font-size: 28px; line-height: 1; }
.pro-title { font-size: 14px; font-weight: 700; letter-spacing: .18em; }
.pro-price { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.pro-price span { font-size: 11px; font-weight: 400; color: var(--muted); }
.pro-perks {
  list-style: none; text-align: left; width: 100%;
  font-size: 9px; letter-spacing: .06em; line-height: 2.1;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 10px 0; margin: 4px 0;
}
.upgrade-cta {
  display: block; width: 100%; padding: 12px 0;
  background: var(--ink); color: #fff; border: none; border-radius: 5px;
  font: 11px 'Space Mono', monospace; letter-spacing: .12em;
  cursor: pointer; text-decoration: none; text-align: center;
}
.upgrade-cta:hover { background: #333; }
.pro-fine { font-size: 8px; color: var(--muted); letter-spacing: .06em; }
.license-hint { font-size: 8.5px; letter-spacing: .06em; color: var(--muted); line-height: 1.6; }
#licenseInput {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 4px;
  font: 12px 'Space Mono', monospace; letter-spacing: .12em;
  text-align: center; text-transform: uppercase; outline: none;
  color: var(--ink); pointer-events: all; touch-action: auto;
  user-select: text; -webkit-user-select: text;
}
#licenseInput:focus { border-color: var(--ink); }
#licenseInput::placeholder { text-transform: none; color: #ccc; letter-spacing: .06em; }
.license-error { font-size: 8.5px; color: var(--red); letter-spacing: .06em; line-height: 1.5; }
.license-link {
  background: none; border: none; font: 8.5px 'Space Mono', monospace;
  color: var(--muted); cursor: pointer; letter-spacing: .08em; text-decoration: underline;
}
.hidden { display: none !important; }

/* PRO tag inline badge */
.pro-tag {
  font-size: 6px; font-weight: 700; letter-spacing: .12em;
  background: var(--ink); color: #fff;
  padding: 1px 4px; border-radius: 3px;
  vertical-align: middle; margin-left: 3px;
}
.pill.on .pro-tag { background: rgba(255,255,255,.25); color: #fff; }
#bar {
  flex-shrink: 0; background: var(--white);
  border-top: 2px solid var(--ink);
  display: flex; height: 46px;
  z-index: 100;
}
#bar button {
  flex: 1; border: none; border-right: 1px solid var(--border);
  background: none; font: 7.5px 'Space Mono', monospace; letter-spacing: .03em;
  cursor: pointer; color: var(--muted); padding: 0; height: 100%;
  display: flex; align-items: center; justify-content: center;
  min-width: 0; overflow: hidden; white-space: nowrap;
}
#bar button:last-child { border-right: none; }
#bar button:active { background: #f0f0f0; color: var(--ink); }
#bar button.at  { background: var(--ink); color: var(--white); }
#bar button.ck  { background: var(--ink); color: var(--white); font-weight: 700; }
#bar button.hidden { display: none; }

#btn-own-style {
  background: var(--blue); color: #fff; font-weight: 700;
  border-right: 1px solid var(--border);
}
#btn-own-style:active  { background: #3a6fa1; color: #fff; }
#btn-own-style.hidden  { display: none; }

#btn-style-done {
  background: var(--green); color: #fff; font-weight: 700;
}
#btn-style-done:active { background: #157a46; color: #fff; }
#btn-style-done.hidden { display: none; }
