@font-face { font-family: 'Pacifico'; src: url(../fonts/pacifico.woff) format('woff'); font-display: swap; }
@font-face { font-family: 'Lobster'; src: url(../fonts/lobster.woff) format('woff'); font-display: swap; }
@font-face { font-family: 'Mountains of Christmas'; font-weight: 700; src: url(../fonts/mountains-of-christmas.woff) format('woff'); font-display: swap; }
@font-face { font-family: 'Luckiest Guy'; src: url(../fonts/luckiest-guy.woff) format('woff'); font-display: swap; }
@font-face { font-family: 'Rubik'; font-weight: 700; src: url(../fonts/rubik-bold.woff) format('woff'); font-display: swap; }

:root {
  --pine: #0f2b20;
  --pine-2: #163a2b;
  --pine-3: #1f4d39;
  --cream: #fbf6ec;
  --paper: #fffdf8;
  --ink: #2a2420;
  --muted: #7a6f66;
  --line: #e8dfd0;
  --berry: #c8102e;
  --berry-dark: #a00d25;
  --gold: #d4af37;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--pine);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }

/* ---------- top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: linear-gradient(180deg, #0b2219, var(--pine));
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  color: var(--cream); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--cream); text-decoration: none; }
.brand svg { width: 30px; height: 30px; }
.brand span { font-family: 'Mountains of Christmas', cursive; font-weight: 700; font-size: 1.75rem; letter-spacing: .5px; }
.top-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.seg { display: inline-flex; background: rgba(255, 255, 255, .08); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: inherit; padding: 6px 14px; border-radius: 999px; font-weight: 600;
}
.seg button.on { background: var(--cream); color: var(--pine); }
.seg.small button { padding: 4px 10px; font-size: .85rem; }

.btn {
  border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 8px 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap;
}
.btn:hover { border-color: #cdbfa8; }
.btn.primary { background: var(--berry); border-color: var(--berry); color: #fff; }
.btn.primary:hover { background: var(--berry-dark); }
.btn.ghost { background: transparent; border-color: rgba(255, 255, 255, .18); color: var(--cream); }
.btn.ghost:hover { background: rgba(255, 255, 255, .08); }
.btn.icon { width: 38px; padding: 8px 0; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.tiny { padding: 2px 8px; font-size: .8rem; border-radius: 8px; }
.btn[aria-pressed="false"] { opacity: .6; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- layout */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 360px 1fr 250px; gap: 0;
}
.panel, .library { background: var(--cream); overflow-y: auto; }
.panel { border-right: 1px solid var(--line); padding: 12px 14px 40px; }
.library { border-left: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewport {
  position: relative; flex: 1; min-height: 280px; overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 196, 92, .22) 0 3px, transparent 26px),
    radial-gradient(circle at 82% 30%, rgba(255, 90, 90, .18) 0 3px, transparent 30px),
    radial-gradient(circle at 70% 78%, rgba(130, 200, 255, .16) 0 3px, transparent 28px),
    radial-gradient(circle at 30% 85%, rgba(255, 220, 140, .18) 0 3px, transparent 24px),
    radial-gradient(ellipse at 50% 40%, #24533f 0%, #143527 45%, #0a1f17 100%);
}
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.viewport canvas#snow { pointer-events: none; }
.view-tools { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; z-index: 2; color: var(--cream); flex-wrap: wrap; }
.stats {
  position: absolute; left: 12px; bottom: 12px; z-index: 2; display: flex; gap: 6px; flex-wrap: wrap;
}
.stats span {
  background: rgba(10, 30, 22, .72); color: var(--cream); padding: 4px 10px; border-radius: 999px; font-size: .82rem;
  backdrop-filter: blur(4px);
}
.warnings { position: absolute; right: 12px; top: 12px; z-index: 2; max-width: 300px; display: flex; flex-direction: column; gap: 6px; }
.warnings div { background: #fff4d6; color: #6b4b00; border-radius: 10px; padding: 8px 10px; font-size: .85rem; box-shadow: var(--shadow); }
.building, .loading {
  position: absolute; z-index: 3; display: flex; align-items: center; gap: 8px; color: var(--cream); font-weight: 600;
}
.building { right: 12px; bottom: 12px; background: rgba(10, 30, 22, .72); padding: 6px 12px; border-radius: 999px; font-size: .85rem; }
.loading { inset: 0; justify-content: center; font-size: 1.1rem; background: rgba(10, 31, 23, .6); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .3); border-top-color: var(--gold);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.downloadbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--paper); border-top: 1px solid var(--line); padding: 10px 14px;
}
.slots { display: flex; gap: 10px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.slots .slot { display: inline-flex; align-items: center; gap: 6px; }
.slots .slot i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .15); display: inline-block; }
.dl { display: flex; gap: 8px; align-items: center; }
.dl-more { position: relative; }
.menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 250px; z-index: 10; overflow: hidden;
}
.menu button { border: 0; background: none; text-align: left; padding: 10px 14px; }
.menu button:hover { background: var(--cream); }

/* ---------- panel controls */
.section { border-bottom: 1px solid var(--line); padding: 4px 0 12px; }
.section > summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 0 6px; cursor: pointer;
  font-weight: 700; font-size: 1rem;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: '▾'; color: var(--muted); transition: transform .15s; }
.section:not([open]) > summary::after { transform: rotate(-90deg); }
.section .num {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--berry); color: #fff;
  font-size: .78rem; margin-right: 8px;
}
.section .title { display: flex; align-items: center; }

.grid-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; margin: 6px 0 10px; }
.pick {
  border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); min-height: 64px;
}
.pick svg { width: 34px; height: 34px; }
.pick svg path { fill: #9a8b78; }
.pick.on { border-color: var(--berry); background: #fff0f2; color: var(--berry-dark); box-shadow: 0 0 0 1px var(--berry) inset; }
.pick.on svg path { fill: var(--berry); }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: .88rem; }
.field > span:first-child { color: var(--muted); font-weight: 600; }
.field input:not([type=range]):not([type=checkbox]):not([type=color]), .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--paper); width: 100%;
}
.field textarea { resize: vertical; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.money { display: inline-flex; align-items: center; gap: 2px; }
.money input { width: 64px !important; padding: 4px 6px !important; }

.slider { margin: 8px 0; }
.slider .row { display: flex; justify-content: space-between; font-size: .85rem; }
.slider .row span:first-child { color: var(--muted); font-weight: 600; }
.slider .row output { font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--berry); margin: 4px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 8px; }
.chip {
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 5px 11px; font-size: .84rem; font-weight: 600;
}
.chip.on { background: var(--pine-3); border-color: var(--pine-3); color: #fff; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; }
.sw {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0;
}
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
.sw-custom { width: 30px; height: 30px; border: 0; padding: 0; background: none; }

.curve { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; position: relative; }
.curve canvas { width: 100%; height: 170px; display: block; touch-action: none; cursor: ew-resize; }
.curve .hint { position: absolute; left: 8px; top: 6px; font-size: .74rem; color: var(--muted); pointer-events: none; }

.decal {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0;
}
.decal-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.decal-head strong { font-size: .9rem; }
.decal-head .acts { display: flex; gap: 4px; }
.add-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.fontchip { font-weight: 400; }
.imgprev { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.imgprev img { width: 56px; height: 56px; object-fit: contain; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 50% / 12px 12px; border-radius: 8px; border: 1px solid var(--line); }
.check { display: flex; align-items: center; gap: 6px; font-size: .88rem; margin: 6px 0; }
.check input { accent-color: var(--berry); width: 16px; height: 16px; }

/* ---------- library */
.lib-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lib-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lib-list li { position: relative; }
.lib-list button.load {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: radial-gradient(#24533f, #0f2b20);
  display: flex; flex-direction: column; align-items: center; color: var(--cream); font-size: .75rem; gap: 2px;
}
.lib-list img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.lib-list .del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55);
  color: #fff; font-size: .8rem; line-height: 1;
}
.lib-empty { color: var(--muted); font-size: .85rem; grid-column: 1 / -1; }
.tips summary { font-weight: 700; cursor: pointer; }
.tips ul { padding-left: 18px; margin: 8px 0; font-size: .86rem; color: #4a423b; }
.tips li { margin: 4px 0; }

/* ---------- dialogs */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: var(--shadow); background: var(--cream); }
.dlg::backdrop { background: rgba(5, 20, 14, .6); }
.dlg form { padding: 20px; }
.dlg h2 { font-family: 'Mountains of Christmas', cursive; font-size: 1.8rem; color: var(--berry-dark); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.tpl {
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper); padding: 12px; text-align: left;
  display: flex; flex-direction: column; gap: 4px;
}
.tpl:hover { border-color: var(--berry); }
.tpl b { font-size: .95rem; }
.tpl span { font-size: .8rem; color: var(--muted); }
.tpl .dot { width: 34px; height: 34px; border-radius: 50%; margin-bottom: 4px; box-shadow: inset -6px -6px 12px rgba(0, 0, 0, .25), inset 4px 4px 8px rgba(255, 255, 255, .3); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; transition: .25s;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 330px 1fr; }
  .library { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  body { overflow: auto; }
  .layout { min-height: calc(100vh - 60px); }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .top-actions { margin-left: 0; width: 100%; }
  .top-actions .btn { flex: 1 1 auto; padding: 6px 8px; font-size: .85rem; }
  .layout { display: flex; flex-direction: column; }
  .stage { order: 1; }
  .viewport { height: 52vh; flex: none; }
  .panel { order: 2; border-right: 0; overflow: visible; }
  .library { order: 3; overflow: visible; display: flex; }
  .downloadbar { position: sticky; bottom: 0; z-index: 5; }
  .dl { width: 100%; }
  .dl .btn.primary { flex: 1; white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}
