/* Scribble Toes — dark neutral chrome so the art is the color. */
:root {
  --bg: #141519;
  --panel: #1d1f24;
  --panel-2: #26282f;
  --line: #34363e;
  --text: #f2f2f4;
  --dim: #9a9da8;
  --accent: #ff5a76;
  --accent-2: #ffb340;
  --radius: 14px;
  --topbar-h: 52px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  overflow: hidden;
  position: fixed;
  inset: 0;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }

#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }

/* ---------- top bar ---------- */
#topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding-left: 8px; padding-right: 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto; z-index: 5;
}
.tb-group { display: flex; gap: 4px; }
.tb-btn {
  width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--text);
}
.tb-btn:active { background: var(--panel-2); }
.tb-btn:disabled { opacity: .3; }
.tb-btn svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tb-btn.wide { width: auto; padding: 0 12px; font-size: 14px; }
#piece-title { text-align: center; min-width: 0; flex: 1 1 auto; cursor: pointer; }
#piece-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#save-state { display: block; font-size: 11px; color: var(--dim); }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1 1 auto; overflow: hidden; background:
  radial-gradient(circle at 50% 40%, #1a1b20, #101116); touch-action: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#empty-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  color: var(--dim); font-size: 13px; text-align: center; line-height: 1.5;
  pointer-events: none; background: rgba(20,21,25,.72); padding: 6px 14px; border-radius: 999px;
  transition: opacity .4s;
}
#empty-hint.gone { opacity: 0; }

/* ---------- toolbar (phone: bottom) ---------- */
#toolbar {
  flex: 0 0 auto; background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px; z-index: 5;
}
.tools-row { display: flex; justify-content: space-between; gap: 2px; }
.tool-btn {
  flex: 1 1 0; min-width: 48px; height: 52px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--dim); font-size: 11px;
}
.tool-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--accent); }
.sliders-row { display: flex; align-items: center; gap: 10px; }
#color-chip {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--line); padding: 3px; background: var(--panel-2);
}
#color-chip-inner { display: block; width: 100%; height: 100%; border-radius: 50%; background: #222222; }
.slider-block { display: flex; align-items: center; gap: 6px; flex: 1 1 0; color: var(--dim); font-size: 12px; }
.slider-block input[type=range] { flex: 1 1 auto; min-width: 40px; }
.slider-val { color: var(--text); font-size: 12px; min-width: 24px; text-align: right; }
input[type=range] { accent-color: var(--accent); height: 28px; }

/* ---------- wide screens: side rail ---------- */
@media (min-width: 900px) {
  #app { flex-direction: row; flex-wrap: wrap; }
  #topbar { flex: 1 1 100%; }
  #toolbar {
    order: 2; flex: 0 0 96px; flex-direction: column; align-items: stretch;
    border-top: none; border-right: 1px solid var(--line);
    padding: 10px 8px; height: auto; overflow-y: auto;
  }
  #stage { order: 3; }
  .tools-row { flex-direction: column; gap: 6px; }
  .tool-btn { flex: 0 0 auto; height: 58px; }
  .sliders-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .slider-block { flex-direction: column; align-items: stretch; gap: 0; }
  .slider-block input[type=range] { width: 100%; }
  #color-chip { align-self: center; }
  #btn-layers { justify-content: center; }
}

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgba(8, 8, 10, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-card {
  background: var(--panel); width: 100%; max-width: 560px; max-height: 86dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); border-bottom: none;
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 20px; border-bottom: 1px solid var(--line); }
  .sheet-card.wide-card { max-width: 720px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-close { width: 40px; height: 40px; border-radius: 10px; background: var(--panel-2); font-size: 15px; }
.small-btn { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; margin-right: 6px; }
.hint { color: var(--dim); font-size: 12px; }
.hint.center { text-align: center; }
.primary-btn {
  width: 100%; padding: 15px; border-radius: 12px; margin-top: 14px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #16171b; font-weight: 700;
}
.menu-btn {
  display: block; width: 100%; text-align: left; padding: 14px 12px; border-radius: 12px;
  background: var(--panel-2); margin-bottom: 8px; font-size: 15px;
}
.menu-btn small { color: var(--dim); }
.about-note { color: var(--dim); font-size: 13px; line-height: 1.55; margin-top: 14px; text-align: center; }
.about-note strong { color: var(--text); }

/* ---------- color sheet ---------- */
.color-main { display: flex; gap: 14px; align-items: flex-start; }
#wheel { width: 200px; height: 200px; border-radius: 50%; flex: 0 0 auto; touch-action: none; }
@media (max-width: 420px) { #wheel { width: 168px; height: 168px; } }
.color-side { flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px; min-width: 130px; }
#color-preview { height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #222222; }
.mini-slider { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; }
.mini-slider span { min-width: 38px; }
.mini-slider input { flex: 1 1 auto; }
.hex-row { display: flex; align-items: center; gap: 4px; color: var(--dim); }
.hex-row input {
  flex: 1 1 auto; min-width: 0; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 8px; text-transform: uppercase;
}
.swatch-label { margin: 14px 0 6px; font-size: 13px; color: var(--dim); }
.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch-row.inner { display: contents; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); padding: 0;
}
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.swatch.add { background: var(--panel-2); color: var(--text); font-size: 18px; border-style: dashed; }

/* ---------- layers sheet ---------- */
#layer-list { display: flex; flex-direction: column; gap: 8px; }
.layer-row {
  display: flex; align-items: center; gap: 8px; background: var(--panel-2);
  border-radius: 12px; padding: 8px; border: 1.5px solid transparent;
}
.layer-row.active { border-color: var(--accent); }
.layer-row .lname { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; padding: 8px 4px; }
.layer-row .lbtn { width: 38px; height: 38px; border-radius: 9px; background: var(--panel); font-size: 15px; flex: 0 0 auto; }
.layer-row .lbtn.off { opacity: .35; }
.layer-opacity { margin-top: 12px; }

/* ---------- gallery ---------- */
#gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.piece-card { background: var(--panel-2); border-radius: 12px; overflow: hidden; text-align: left; padding: 0; }
.piece-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #0c0c0e; display: block; }
.piece-card .pmeta { padding: 8px 10px 4px; }
.piece-card .pname { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece-card .pdate { color: var(--dim); font-size: 11px; }
.piece-card .pactions { display: flex; gap: 6px; padding: 8px 10px 10px; }
.piece-card .pactions button { flex: 1; background: var(--panel); border-radius: 8px; padding: 8px 4px; font-size: 12px; }
.piece-card .pactions button.danger { color: #ff7a8a; }
.gallery-empty { color: var(--dim); text-align: center; padding: 24px 0; }

/* ---------- new dialog ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--dim); font-size: 13px; margin-bottom: 6px; }
.field input[type=text] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px;
}
.size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.size-opt { background: var(--panel-2); border: 1.5px solid transparent; border-radius: 12px; padding: 12px; line-height: 1.35; }
.size-opt small { color: var(--dim); }
.size-opt.selected { border-color: var(--accent); }
.paper-row { display: flex; gap: 10px; }
.paper-opt { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); }
.paper-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #2c2e35; color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 40;
  box-shadow: 0 6px 24px rgba(0,0,0,.45); pointer-events: none; white-space: nowrap;
}
