* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --panel: rgba(14, 17, 34, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eceef8;
  --dim: #8890b0;
  --accent: #ffd27a;
  --accent2: #7aa2ff;
  --font-ui: "Manrope", -apple-system, "Segoe UI", sans-serif;
  --font-display: "Unbounded", "Manrope", sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  font: 14px/1.45 var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1.2px 1.2px at 12% 22%, #fff9 0%, transparent 100%),
    radial-gradient(1.6px 1.6px at 34% 68%, #fff7 0%, transparent 100%),
    radial-gradient(1px 1px at 58% 15%, #fff8 0%, transparent 100%),
    radial-gradient(1.4px 1.4px at 73% 44%, #fff6 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 76%, #fff8 0%, transparent 100%),
    radial-gradient(1.8px 1.8px at 45% 88%, #fff5 0%, transparent 100%),
    radial-gradient(1px 1px at 92% 12%, #fff7 0%, transparent 100%),
    radial-gradient(900px 700px at 78% 15%, #251a4a 0%, transparent 55%),
    radial-gradient(800px 700px at 15% 90%, #0e2a45 0%, transparent 55%),
    linear-gradient(165deg, #0a0c1c, #131028);
  display: grid;
  grid-template-rows: 58px 1fr auto auto;
  grid-template-columns: 330px minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "side view"
    "side stats"
    "side credits";
}

/* ---------- top bar ---------- */
header {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: rgba(8, 10, 22, 0.65);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--panel-border);
  z-index: 5;
  min-width: 0;
}
header h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}
header h1 span {
  background: linear-gradient(90deg, var(--accent), #ff9d6c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header .tagline { color: var(--dim); font-size: 12px; white-space: nowrap; }
header .spacer { flex: 1; }

button {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
button:hover { background: rgba(255, 255, 255, 0.14); transform: translateY(-1px); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
button.primary {
  background: linear-gradient(135deg, #ffb24a, #ff7a5d);
  border: none;
  color: #241505;
  box-shadow: 0 4px 18px rgba(255, 160, 80, 0.35);
}
button.primary:hover { box-shadow: 0 6px 24px rgba(255, 160, 80, 0.5); }

/* ---------- side panel ---------- */
aside {
  grid-area: side;
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--panel-border);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
aside section {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}
aside h3 {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}
aside label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin: 8px 0 2px;
}
aside label.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  margin-top: 10px;
  cursor: pointer;
}
input, select {
  width: 100%;
  margin-top: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-ui);
  outline: none;
  color-scheme: dark;
}
input:focus, select:focus { border-color: var(--accent2); }
input.unknown { border-color: #e2564a; box-shadow: 0 0 8px rgba(226, 86, 74, 0.3); }

/* ---------- city autocomplete ---------- */
.citywrap { position: relative; }
#citysug {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #171a30;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  max-height: 230px;
  overflow-y: auto;
  z-index: 30;
  display: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#citysug.show { display: block; }
.sug {
  padding: 8px 11px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.sug:hover, .sug.active { background: rgba(255, 255, 255, 0.08); }
.sug small { color: var(--dim); margin-left: 6px; font-size: 11.5px; }
select option { background: #171a30; }
.cityhint { font-size: 11.5px; color: var(--dim); margin-top: 5px; min-height: 16px; }
.cityhint.bad { color: #ff8a7a; }
input[type="checkbox"] {
  width: 17px; height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 0.7fr; gap: 8px; }
aside details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--dim);
  margin-top: 8px;
  user-select: none;
}
.hint { font-size: 11.5px; color: var(--dim); margin-top: 8px; line-height: 1.4; }

.seg { display: flex; gap: 4px; background: rgba(255,255,255,0.05); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: none; background: transparent; padding: 7px; border-radius: 8px; transform: none; }
.seg button:hover { transform: none; }
.seg button.on { background: linear-gradient(135deg, rgba(255, 178, 74, 0.3), rgba(255, 122, 93, 0.2)); }

.sizes { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.sizes button { flex: 1; padding: 7px 6px; font-size: 12px; }
.sizes button.on { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 210, 122, 0.25); }

#pairs { display: flex; gap: 9px; flex-wrap: wrap; }
.pair {
  width: 34px; height: 34px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.18);
}
.pair:hover { transform: scale(1.12); }
.pair.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2); }

/* ---------- viewport ---------- */
#viewport { grid-area: view; position: relative; min-width: 0; min-height: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; }
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--dim);
  letter-spacing: 1px;
}

/* ---------- stats ---------- */
#stats {
  grid-area: stats;
  padding: 9px 18px;
  font-size: 12.5px;
  color: var(--dim);
  border-top: 1px solid var(--panel-border);
  background: rgba(8, 10, 22, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  overflow-x: auto;
}
#stats b { color: var(--text); }
#stats .sep { margin: 0 10px; opacity: 0.4; }
#stats .dim { opacity: 0.9; }
#stats .warn { color: #ffb48a; }

/* ---------- credits ---------- */
#credits {
  grid-area: credits;
  padding: 4px 18px 6px;
  font-size: 11px;
  color: var(--dim);
  opacity: 0.75;
  white-space: nowrap;
  overflow-x: auto;
}
#credits a { color: inherit; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: 70px;
  right: 18px;
  padding: 11px 16px;
  background: linear-gradient(135deg, #1d2b45, #232042);
  border: 1px solid var(--accent2);
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.25s;
  pointer-events: none;
  z-index: 20;
  max-width: 380px;
}
#toast.show { opacity: 1; transform: none; }

@media (max-width: 1150px) {
  header .tagline { display: none; }
}
@media (max-width: 860px) {
  html, body { height: auto; min-height: 100%; overflow-x: hidden; overflow-y: auto; }
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 46vh auto auto auto;
    grid-template-areas: "top" "view" "stats" "side" "credits";
  }
  header { flex-wrap: wrap; row-gap: 6px; padding: 8px 12px; }
  header .spacer { flex-basis: 100%; height: 0; }
  header button { padding: 7px 10px; font-size: 12px; }
  aside { overflow: visible; border-right: none; border-top: 1px solid var(--panel-border); }
  #stats { white-space: normal; }
  #credits { white-space: normal; }
}

/* ---------- access code ---------- */
body.locked .gated::after { content: " 🔒"; font-size: 0.85em; }
#btn-key.unlocked { color: var(--accent); }
#licdlg {
  margin: auto;
  width: min(440px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  color: var(--text);
  background: linear-gradient(160deg, #161a33, #1d1838);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
#licdlg::backdrop { background: rgba(5, 6, 16, 0.65); }
#licdlg h2 { font: 800 17px var(--font-display); margin-bottom: 10px; }
#licdlg p { font-size: 13px; color: var(--dim); margin-bottom: 12px; }
#licdlg #lic-info { color: var(--text); font-size: 14px; }
#lic-code {
  width: 100%;
  padding: 11px 12px;
  font: 600 17px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  margin-bottom: 8px;
}
#lic-code:focus { outline: 2px solid var(--accent2); outline-offset: 1px; }
#licdlg .lic-err { color: #ff8a8a; min-height: 1.2em; margin-bottom: 6px; }
#licdlg .lic-note a { color: var(--accent2); }
.lic-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.lic-actions .spacer { flex: 1; }

/* ---------- preview (no licence): a server-rendered picture instead of the 3D model ---------- */
#preview { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#preview[hidden] { display: none; }
#preview-img:not([src]) { visibility: hidden; }
#preview-img { max-width: 100%; max-height: calc(100% - 76px); object-fit: contain; transition: opacity 0.2s; user-select: none; -webkit-user-drag: none; }
#preview.busy #preview-img { opacity: 0.55; }
.pv-bar { position: absolute; top: 12px; left: 12px; display: flex; gap: 10px; align-items: center; }
.pv-views { width: auto; }
.pv-views button { padding: 6px 12px; font-size: 12px; }
.pv-state { font-size: 12px; color: var(--dim); }
.pv-note { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--dim); padding: 0 16px; }
.pv-note a { color: var(--accent); }

#demo-bar { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 30; padding: 8px 14px;
  font-size: 13px; background: #3a2a0c; border: 1px solid var(--accent); border-radius: 10px; color: var(--text); }
#demo-bar a { color: var(--accent); }

.moonstyle { margin: 0 0 8px 26px; width: calc(100% - 26px); font-size: 12px; }

.printer { margin-top: 10px; }
.sizes button.nofit { opacity: 0.4; text-decoration: line-through; }
.sizehint { margin-top: 6px; font-size: 11.5px; color: var(--dim); }
.sizehint.bad { color: #ff8a8a; }
aside label.chk.sub { margin-left: 26px; margin-top: -2px; }
.clock { margin: 8px 0 4px; font-size: 12px; }
.font { margin: 6px 0 2px; font-size: 12px; }
aside .chkrow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 10px; font-size: 13px; }
aside .chkrow label.chk { margin-top: 0; }
