:root {
  --ink: #15151a;
  --paper: #fffdf6;
  --paper-2: #f6f1e2;
  --glow: #fffdf6;
  --card-on: #ffe9a8;
  --shadow: 0 3px 0 rgba(21, 21, 26, 0.16);
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe Print", "Bradley Hand", "Marker Felt", system-ui, sans-serif;
}

[data-ui="dark"] {
  --ink: #f2efe4;
  --paper: #24262f;
  --paper-2: #15161d;
  --glow: #2c2f3a;
  --card-on: #6d5a24;
  --shadow: 0 3px 0 rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper-2);
  background-image: radial-gradient(circle at 18% 12%, var(--glow) 0%, transparent 55%),
    radial-gradient(circle at 82% 88%, var(--glow) 0%, transparent 55%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100dvh;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------------- top */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 4px solid var(--ink);
  background: var(--paper);
  flex: none;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.5px;
}

.tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tool,
.tab,
.chip,
.card,
.swatch {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, background 0.12s ease;
}

.tool {
  padding: 7px 12px;
  font-size: 15px;
}

.tool:hover,
.tab:hover,
.chip:hover,
.card:hover,
.swatch:hover {
  transform: translateY(-2px);
}

.tool:active,
.tab:active,
.chip:active,
.card:active {
  transform: translateY(1px);
  box-shadow: none;
}

.tool.on {
  background: var(--ink);
  color: var(--paper);
}

/* ---------------------------------------------------------------- layout */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#scene {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 10px;
  filter: drop-shadow(0 8px 16px rgba(21, 21, 26, 0.18));
  touch-action: none;
  user-select: none;
}

#scene .figure {
  cursor: pointer;
}

#scene .decor {
  cursor: grab;
}

#scene .decor.dragging {
  cursor: grabbing;
  opacity: 0.85;
}

/* ----------------------------------------------------------------- panel */

.panel {
  border-left: 4px solid var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 12px 8px;
  flex: none;
}

.tab {
  flex: 1;
  padding: 9px 6px;
  font-size: 15px;
}

.tab.on {
  background: var(--ink);
  color: var(--paper);
}

.hint {
  margin: 0;
  padding: 0 14px 8px;
  font-size: 13px;
  opacity: 0.72;
  flex: none;
  min-height: 34px;
}

.tray {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 24px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--paper);
  padding: 10px 0 8px;
  z-index: 2;
}

.chip {
  padding: 5px 10px;
  font-size: 13px;
  border-width: 2px;
  border-radius: 999px;
}

.chip.on {
  background: var(--ink);
  color: var(--paper);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border-radius: 16px;
}

.card.on {
  background: var(--card-on);
  border-color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--paper), var(--shadow);
}

.card span {
  font-size: 11.5px;
  line-height: 1.15;
  text-align: center;
}

.thumb {
  width: 100%;
  height: 74px;
  display: block;
  pointer-events: none;
}

.section {
  margin-bottom: 16px;
}

.section:first-child {
  padding-top: 8px;
}

/* ------------------------------------------------------------------ paint */

.paint {
  border: 3px dashed var(--ink);
  border-radius: 16px;
  padding: 8px 10px 10px;
  margin-bottom: 14px;
  background: var(--glow);
}

.paint.off {
  opacity: 0.55;
}

.paint.off .dot {
  pointer-events: none;
}

.paint-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.paint-label {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mix-open {
  position: relative;
  display: flex;
  align-items: center;
  gap: 3px;
  flex: none;
  padding: 3px 6px 3px 4px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: var(--paper);
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: var(--shadow);
}

.mix-open.on {
  background: var(--ink);
  color: var(--paper);
}

.mix-open[disabled] {
  opacity: 0.5;
  cursor: default;
}

.mix-swatch {
  width: 22px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--ink);
  display: block;
}

.mix-open.on .mix-swatch {
  border-color: var(--paper);
}

.mix-plus {
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  width: 12px;
  text-align: center;
}

.mixer {
  margin-top: 10px;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
}

.mix-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mix-chip {
  width: 34px;
  height: 26px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  flex: none;
}

.mix-hex {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  flex: 1;
  text-transform: uppercase;
}

.mix-done {
  font: inherit;
  font-size: 13px;
  padding: 3px 12px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}

.mix-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

.mix-row span {
  font-size: 12px;
  width: 62px;
  flex: none;
}

.rail {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  touch-action: pan-y;
}

.rail::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper);
  border: 4px solid var(--ink);
  cursor: grab;
}

.rail::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--paper);
  border: 4px solid var(--ink);
  cursor: grab;
}

.dots {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 4px;
}

.dot {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.08s ease;
}

.dot:hover {
  transform: scale(1.18);
}

.dot.on {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.surface-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.surface {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.tool .ico {
  margin-right: 3px;
}

.card.sel {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.section h3 {
  margin: 6px 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.65;
}

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 52px;
  height: 40px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-width: 2px;
}

.swatch span {
  flex: 1;
  display: block;
}

.swatch.on {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ------------------------------------------------------- toast & picture */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

.toast[hidden] {
  display: none;
}

.toast button {
  font: inherit;
  font-size: 14px;
  padding: 3px 12px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  background: none;
  color: var(--paper);
  cursor: pointer;
}

.shot {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 10, 14, 0.78);
}

.shot[hidden] {
  display: none;
}

.shot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  max-height: 100%;
}

.shot-tip {
  margin: 0;
  padding: 8px 16px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 14px;
  font-size: 15px;
  text-align: center;
}

.shot img {
  max-width: 100%;
  min-height: 0;
  max-height: 68vh;
  border: 4px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .panel {
    border-left: none;
    border-top: 4px solid var(--ink);
  }

  .stage {
    padding: 8px 8px 4px;
  }

  #scene {
    width: 100%;
    max-width: calc(46dvh * 1.7143);
    height: auto;
    max-height: none;
    aspect-ratio: 960 / 560;
    margin: 0 auto;
  }

  .topbar {
    padding: 8px 10px;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 17px;
  }

  .tools {
    gap: 6px;
  }

  .tabs {
    padding: 10px 10px 6px;
  }

  .tray {
    padding: 0 10px 28px;
  }

  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* phones in portrait: icon-only tools so the header stays on one line */
@media (max-width: 620px) {
  .topbar h1 {
    font-size: 15px;
    max-width: 7ch;
    line-height: 1.05;
  }

  .tool {
    padding: 8px 10px;
    font-size: 17px;
  }

  .tool .ico {
    margin: 0;
  }

  .tool .label {
    display: none;
  }

  .tab {
    padding: 11px 6px;
    font-size: 15px;
  }

  .chip {
    padding: 7px 12px;
    font-size: 14px;
  }

  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dots {
    grid-template-columns: repeat(7, 1fr);
    gap: 7px;
  }

  .dot {
    border-width: 3px;
  }

  .thumb {
    height: 68px;
  }

  .mix-row span {
    width: 54px;
  }

  .rail {
    height: 22px;
  }

  .hint {
    font-size: 12px;
  }
}

/* phones on their side: put the tray back beside the scene */
@media (max-width: 900px) and (orientation: landscape) {
  .layout {
    grid-template-columns: minmax(0, 1fr) min(46%, 340px);
    grid-template-rows: minmax(0, 1fr);
  }

  .panel {
    border-top: none;
    border-left: 4px solid var(--ink);
  }

  #scene {
    max-width: 100%;
    max-height: 100%;
  }

  .stage {
    padding: 6px;
  }

  .topbar h1 {
    display: none;
  }
}

@media (max-width: 380px) {
  .dots {
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
  }

  .grid {
    gap: 8px;
  }
}
