/* Jasu Coloring Studio - self-contained styles (the studio uses its own full-screen layout) */
@font-face { font-family: 'Fraunces'; src: url('/public/fonts/fraunces-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Work Sans'; src: url('/public/fonts/work-sans-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Work Sans'; src: url('/public/fonts/work-sans-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }

:root {
  color-scheme: light dark;
  --bg: #ece5d9;
  --chrome: #fffdf9;
  --chrome-2: #f5eee2;
  --line: #ddd0bb;
  --text: #2b2620;
  --soft: #5c554c;
  --accent: #8e5300;
  --accent-ink: #ffffff;
  --accent-tint: #f6e6cf;
  --focus: #1a5fd1;
  --shadow: 0 10px 30px rgba(43, 36, 29, 0.14);
  --font-sans: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --chrome: #24211d;
    --chrome-2: #2e2a25;
    --line: #443e35;
    --text: #f4ede2;
    --soft: #c4baa9;
    --accent: #e8a040;
    --accent-ink: #1c1915;
    --accent-tint: #3d3122;
    --focus: #8bbcff;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
.studio-body { background: var(--bg); color: var(--text); font-family: var(--font-sans); font-size: 15px; line-height: 1.4; overflow: hidden; -webkit-text-size-adjust: 100%; }
.studio-noscript { padding: 2rem; text-align: center; }
button, input, select { font: inherit; color: inherit; }
.i { width: 22px; height: 22px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- layout ---------- */
.studio {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: 92px minmax(0, 1fr) 348px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "tools stage panel";
}
.studio-top { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--chrome); border-bottom: 1px solid var(--line); min-width: 0; }
.studio-heading { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; justify-content: center; }
.studio-title { margin: 0; font: 600 1.15rem/1.2 var(--font-serif); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }

.btn-icon, .btn-chrome, .btn-primary-chrome { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; text-decoration: none; font-weight: 600; transition: background 0.15s ease, border-color 0.15s ease; }
.btn-icon { width: 42px; padding: 0; }
.btn-chrome { padding: 0 14px; border-color: var(--line); background: var(--chrome); }
.btn-primary-chrome { padding: 0 16px; background: var(--accent); color: var(--accent-ink); }
.btn-icon:hover, .btn-chrome:hover { background: var(--chrome-2); border-color: var(--line); }
.btn-primary-chrome:hover { filter: brightness(1.08); }
[aria-disabled="true"] { opacity: 0.38; cursor: default; }
.zoom-label { min-width: 66px; font-variant-numeric: tabular-nums; }

.studio-tools { grid-area: tools; display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; overflow-y: auto; background: var(--chrome); border-right: 1px solid var(--line); }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 62px; padding: 6px 2px; border-radius: 14px; border: 2px solid transparent; background: transparent; cursor: pointer; font-size: 0.72rem; font-weight: 600; color: var(--soft); }
.tool:hover { background: var(--chrome-2); }
.tool[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--text); }
.tool-label { text-align: center; line-height: 1.1; }
.tool-colors { display: none; }
.tool-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--text); background: var(--cur, #3a7bd5); }

.studio-stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.stage-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; outline-offset: -4px; }
.stage-viewport.is-hand { cursor: grab; }
.stage-viewport.is-panning { cursor: grabbing; }
.stage-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.22); will-change: transform; }
.stage-world canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.stage-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: 92%; margin: 0; padding: 10px 18px; border-radius: 999px; background: rgba(28, 25, 21, 0.92); color: #fff; font-size: 0.9rem; text-align: center; pointer-events: none; }
.stage-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; background: var(--bg); color: var(--soft); font-weight: 600; }
.stage-loading[hidden], .stage-hint[hidden] { display: none; }

/* ---------- side panel ---------- */
.studio-panel { grid-area: panel; overflow-y: auto; background: var(--chrome); border-left: 1px solid var(--line); padding: 6px 16px 24px; scrollbar-width: thin; }
.panel-grab { display: none; }
.panel-block { padding: 14px 0; border-bottom: 1px solid var(--line); }
.panel-block:last-child { border-bottom: 0; }
.panel-block h2 { margin: 0 0 10px; font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--soft); font-weight: 600; }
.panel-block h2 + .swatches ~ h2, .panel-block .mine-head { margin-top: 14px; }
.mine-head { display: flex; align-items: center; justify-content: space-between; }
.mine-head h2 { margin-bottom: 8px; }
.link-btn { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 0.85rem; padding: 6px; }

.slots { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.slot { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; border: 2px solid var(--line); background: var(--chrome-2); cursor: pointer; font-size: 0.85rem; font-weight: 600; min-height: 44px; }
.slot[aria-checked="true"] { border-color: var(--accent); background: var(--accent-tint); }
.slot-sw { width: 30px; height: 30px; border-radius: 50%; background: var(--c, #888); border: 2px solid var(--chrome); box-shadow: 0 0 0 1px var(--line); }
.slot[hidden], .slot-swap[hidden] { display: none; }

.sv { display: block; width: 100%; height: 150px; border-radius: 12px; border: 1px solid var(--line); touch-action: none; cursor: crosshair; margin-bottom: 12px; }
.field { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 10px; margin: 6px 0; font-size: 0.88rem; font-weight: 600; }
.field[hidden], .check[hidden], .seg[hidden] { display: none; }
.field-select { grid-template-columns: 1fr; }
.hexrow { display: flex; align-items: end; gap: 8px; margin-top: 6px; }
.field-hex { flex: 1; grid-template-columns: 96px 1fr; }
input[type="text"], select { min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--chrome); width: 100%; }
input[type="text"] { font-family: ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase; }
.color-name { margin: 8px 0 0; color: var(--soft); font-size: 0.88rem; min-height: 1.3em; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 12px; border-radius: 999px; background: var(--track, var(--line)); border: 1px solid var(--line); }
input[type="range"]::-moz-range-track { height: 12px; border-radius: 999px; background: var(--track, var(--line)); border: 1px solid var(--line); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -8px; border-radius: 50%; background: var(--chrome); border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--chrome); border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
#rHue { --track: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
#rSat { --track: linear-gradient(90deg, var(--sat0, #888), var(--sat1, #f00)); }
#rVal { --track: linear-gradient(90deg, #000, var(--val1, #f00)); }

.check { display: flex; align-items: center; gap: 10px; margin: 8px 0; min-height: 36px; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.seg { display: flex; gap: 8px; border: 0; padding: 0; margin: 8px 0; }
.seg legend { font-size: 0.88rem; font-weight: 600; padding: 0; margin-bottom: 6px; float: left; width: 100%; }
.seg label { flex: 1; text-align: center; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; padding: 10px 8px; border: 2px solid var(--line); border-radius: 12px; font-weight: 600; font-size: 0.88rem; cursor: pointer; }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-tint); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); background: var(--c); cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.sw:hover { transform: scale(1.08); }
.sw[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--chrome), 0 0 0 4px var(--text); }
.ramp .sw { border-radius: 9px; width: 34px; }
.swatches:empty::after { content: "-"; color: var(--soft); }

/* ---------- dialogs ---------- */
.dlg { border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(92vw, 420px); background: var(--chrome); color: var(--text); box-shadow: var(--shadow); }
.dlg-wide { width: min(94vw, 560px); }
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg h2 { margin: 0 0 8px; font: 600 1.25rem var(--font-serif); }
.dlg p { margin: 0 0 16px; color: var(--soft); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.help-list { margin: 0 0 6px; padding-left: 1.1rem; color: var(--soft); }
.help-list li { margin: 8px 0; }

/* ---------- tablets and phones ---------- */
@media (max-width: 1000px) {
  .studio { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "stage" "tools"; }
  .studio-top { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .studio-back span { display: none; }
  .studio-back { padding: 0; width: 42px; }
  .studio-heading { order: 2; flex: 1 1 50%; }
  .studio-actions { order: 3; flex: 1 1 100%; overflow-x: auto; justify-content: flex-start; padding-bottom: 2px; }
  .studio-top .studio-back { order: 1; }
  #btnSave span { display: none; }
  #btnSave { width: 42px; padding: 0; }
  .studio-tools { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 4px; }
  .tool { min-width: 64px; flex: none; }
  .tool-colors { display: flex; order: -1; border-color: var(--line); background: var(--chrome-2); }
  .studio-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 66vh; max-height: 66dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; box-shadow: var(--shadow); transform: translateY(105%); visibility: hidden; transition: transform 0.25s ease, visibility 0.25s; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .studio.panel-open .studio-panel { transform: none; visibility: visible; }
  .panel-grab { display: flex; justify-content: center; padding: 8px 0 0; position: sticky; top: 0; background: var(--chrome); z-index: 2; }
  .panel-done { min-height: 40px; }
}
@media (max-width: 520px) {
  .studio-title { font-size: 1rem; }
  .field { grid-template-columns: 84px 1fr; }
  .sw { width: 42px; height: 42px; }
}
@media (max-height: 520px) and (min-width: 700px) {
  .studio-tools { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .tool[aria-pressed="true"], .slot[aria-checked="true"], .sw[aria-pressed="true"] { outline: 3px solid Highlight; }
  .sw, .slot-sw, .tool-swatch { forced-color-adjust: none; }
}
