/* Avatar Studio. Paper and ink surfaces; the one colour is the character's own. */
:root {
  --ink: #12141c;
  --paper: #ffffff;
  --line: #e4e0d6;
  --mute: #6a6e7a;
  --track: #dedad0;
  --signature: #ff6f5b;
  --on-stage: var(--ink);
  --panel: clamp(240px, 29vw, 400px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: "SF Pro Display", "Inter", "Segoe UI", "PingFang HK", "Noto Sans HK", "Noto Sans CJK HK", "Noto Sans CJK TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: #f4f1ea; }
body { user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, .custom:has(:focus-visible), .switch input:focus-visible + i { outline: 3px solid var(--signature); outline-offset: 2px; }
h1, h2, p { margin: 0; }

/* ---- backdrop: the scene behind the transparent canvas ---- */
.backdrop { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.backdrop > * { position: absolute; }
.wash { inset: 0; background: #f4f1ea; }
.slab {
  left: var(--clear-x, 50%); top: -10%; height: 120%;
  width: min(calc(var(--clear-w, 100vw) * 0.66), calc(var(--clear-h, 100vh) * 0.52));
  transform: translateX(-50%) skewX(-11deg);
  background: var(--signature);
  box-shadow: 26px 0 0 color-mix(in srgb, var(--signature) 55%, #fff), -12px 0 0 var(--ink);
}
.word {
  left: var(--clear-x, 50%); top: calc(var(--clear-y, 50%) - var(--clear-h, 100vh) * 0.16);
  transform: translate(-50%, -50%) skewX(-11deg);
  font-size: min(calc(var(--clear-w, 100vw) / 5.9), calc(var(--clear-h, 100vh) / 3.6));
  font-weight: 900; font-style: italic; line-height: 0.84; letter-spacing: -0.03em;
  text-align: center; word-spacing: 100vw; white-space: normal; width: 200vw;
  color: #fff;
}
.beam, .pane { display: none; }

[data-light="cafe"] .wash { background: linear-gradient(180deg, #ffd9a0 0%, #f6b877 62%, #ee9f62 100%); }
[data-light="cafe"] .slab { display: none; }
[data-light="cafe"] .pane {
  display: block; left: var(--clear-x, 50%); top: -6%; height: 78%;
  width: min(calc(var(--clear-w, 100vw) * 0.9), calc(var(--clear-h, 100vh) * 0.74));
  transform: translateX(-58%) skewX(-18deg);
  background:
    linear-gradient(90deg, transparent 0 31%, #f6b877 31% 34%, transparent 34% 65%, #f6b877 65% 68%, transparent 68%),
    linear-gradient(180deg, transparent 0 46%, #f6b877 46% 49%, transparent 49%),
    #ffeec4;
}
[data-light="cafe"] .word { color: #fff6dc; }

[data-light="stage"] { --on-stage: #ffffff; }
[data-light="stage"] .wash { background: linear-gradient(180deg, #2a3fc0 0%, #2233a4 55%, #1c2a8c 100%); }
[data-light="stage"] .slab { display: none; }
[data-light="stage"] .beam {
  display: block; left: var(--clear-x, 50%); top: 0; height: calc(var(--clear-y, 50%) + var(--clear-h, 100vh) * 0.42);
  width: min(calc(var(--clear-w, 100vw) * 0.95), calc(var(--clear-h, 100vh) * 0.8));
  transform: translateX(-50%);
  clip-path: polygon(42% 0, 58% 0, 100% 100%, 0 100%);
  background: linear-gradient(180deg, #7fd0ff 0%, #4f79e6 100%);
  opacity: 0.6;
}
[data-light="stage"] .beam-b { clip-path: polygon(4% 0, 15% 0, 78% 100%, 30% 100%); opacity: 0.32; }
[data-light="stage"] .word { color: transparent; -webkit-text-stroke: 2px #8fe2ff; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }

/* ---- layout ---- */
.app { position: fixed; inset: 0; z-index: 2; display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) var(--panel); transition: grid-template-columns 0.32s var(--ease); }
[data-folded="true"] .app { grid-template-columns: minmax(0, 1fr) 0px; }
.stage { position: relative; min-width: 0; touch-action: none; cursor: grab; color: var(--on-stage); padding: env(safe-area-inset-top) 0 0 env(safe-area-inset-left); }
.stage:active { cursor: grabbing; }

.top { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.brand { display: grid; gap: 1px; min-width: 0; margin-right: auto; font-size: 15px; line-height: 1.15; }
.brand span { font-size: 10px; font-weight: 800; letter-spacing: 0.22em; opacity: 0.7; }
.brand b { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.who { display: flex; padding: 3px; border-radius: 999px; background: var(--paper); box-shadow: 0 0 0 2px var(--ink); }
.who button { min-height: 38px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 800; color: var(--ink); white-space: nowrap; transition: background 0.18s, color 0.18s; }
.who button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.lang { min-height: 44px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 800; background: var(--paper); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

.focus { position: absolute; left: calc(12px + env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); display: grid; gap: 6px; padding: 4px; border-radius: 16px; background: var(--paper); box-shadow: 0 0 0 2px var(--ink); }
.focus button { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--ink); transition: background 0.18s, color 0.18s; }
.focus svg { width: 24px; height: 24px; fill: currentColor; }
.focus .cut { fill: var(--paper); }
.focus button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.focus button[aria-checked="true"] .cut { fill: var(--ink); }

.meter { position: absolute; right: 14px; top: calc(66px + env(safe-area-inset-top)); font: 600 10px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.04em; opacity: 0.6; }

.motion { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 6px; padding: 0 12px; }
.motion button { flex: 0 1 96px; min-width: 0; min-height: 46px; padding: 0 6px; font-size: 14px; font-weight: 900; color: var(--ink); background: var(--paper); box-shadow: 0 0 0 2px var(--ink); transform: skewX(-11deg); border-radius: 6px; transition: background 0.16s, color 0.16s, translate 0.16s var(--ease); }
.motion button span { display: block; transform: skewX(11deg); white-space: nowrap; }
.motion button[aria-checked="true"] { background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--ink), 4px 4px 0 2px var(--signature); translate: -2px -2px; }

/* ---- panel ---- */
.panel { position: relative; min-width: 0; min-height: 0; container-type: inline-size; background: var(--paper); box-shadow: -2px 0 0 var(--ink); display: flex; flex-direction: column; padding-right: env(safe-area-inset-right); }
.tabs { display: flex; align-items: stretch; flex: none; border-bottom: 2px solid var(--line); min-width: var(--panel); }
.tabs [role="tab"] { flex: 1; min-height: 46px; font-size: 14px; font-weight: 800; color: var(--mute); position: relative; }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"]::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: -2px; height: 4px; background: var(--signature); transform: skewX(-20deg); }
.tabs .reset { align-self: center; margin: 0 10px 0 2px; }
[data-tab="scene"] .tabs .reset { visibility: hidden; }
.fold { position: absolute; left: -30px; top: 50%; width: 30px; height: 64px; margin-top: -32px; display: grid; place-items: center; background: var(--paper); border-radius: 12px 0 0 12px; box-shadow: -2px 0 0 var(--ink), 0 -2px 0 var(--ink), 0 2px 0 var(--ink); color: var(--ink); }
.fold svg { width: 20px; height: 20px; transform: rotate(-90deg); transition: transform 0.3s var(--ease); }
[data-folded="true"] .fold svg { transform: rotate(90deg); }
.sheet { flex: 1; min-height: 0; min-width: var(--panel); overflow-y: auto; overscroll-behavior: contain; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
[data-folded="true"] .sheet, [data-folded="true"] .tabs { visibility: hidden; }

.card { display: none; }
[data-tab="body"] .card[data-card="body"], [data-tab="colour"] .card[data-card="colour"], [data-tab="scene"] .card[data-card="scene"] { display: block; }
.card > header { display: none; align-items: center; }
.card h2 { font-size: 13px; font-weight: 900; letter-spacing: 0.08em; margin-right: auto; }
.reset { flex: none; min-height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12px; font-weight: 800; color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.reset:active { background: var(--ink); color: var(--paper); }

.sliders { display: grid; gap: 6px 16px; }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: end; column-gap: 8px; font-size: 13px; font-weight: 700; }
.slider output { font: 700 12px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--mute); font-variant-numeric: tabular-nums; }
.slider input {
  grid-column: 1 / -1; appearance: none; -webkit-appearance: none; width: 100%; height: 34px; margin: 0; background: none; cursor: pointer; touch-action: pan-y;
  --thumb: calc(12px + (100% - 24px) * var(--at, 0.5));
  --fill: linear-gradient(90deg, var(--track) min(50%, var(--thumb)), var(--ink) min(50%, var(--thumb)), var(--ink) max(50%, var(--thumb)), var(--track) max(50%, var(--thumb)));
}
.slider input::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--fill); }
.slider input::-moz-range-track { height: 6px; border-radius: 3px; background: var(--fill); }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--signature); }
.slider input::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--signature); }

.looks { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 2px 14px 10px; }
.looks::-webkit-scrollbar { display: none; }
.looks button { flex: none; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; min-height: 44px; padding: 0 14px 0 10px; border-radius: 12px; font-size: 13px; font-weight: 800; box-shadow: inset 0 0 0 2px var(--line); text-align: left; line-height: 1.15; }
.looks button em { grid-row: span 2; display: flex; }
.looks button span:only-of-type:last-child { grid-row: span 2; }
.looks button em:empty { width: 20px; height: 20px; border-radius: 50%; background: conic-gradient(#ee9580 0 33%, #f6ecdb 0 66%, #22383f 0); }
[data-who="courier"] .looks button em:empty { background: conic-gradient(#d6d0e3 0 33%, #2b2e3d 0 66%, #ee8a44 0); }
.looks button i { width: 16px; height: 16px; border-radius: 50%; margin-left: -5px; box-shadow: 0 0 0 2px var(--paper); }
.looks button i:first-child { margin-left: 0; }
.looks button small { grid-column: 2; font-size: 10px; font-weight: 700; color: var(--mute); }
.looks button[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--ink); background: var(--ink); color: var(--paper); }
.looks button[aria-checked="true"] small { color: #c9ccd6; }
.looks button[aria-checked="true"] i { box-shadow: 0 0 0 2px var(--ink); }

.channels { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 3px; border-radius: 12px; background: #f1eee6; }
.channels button { display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 38px; min-width: 0; border-radius: 9px; font-size: 12px; font-weight: 800; color: var(--mute); white-space: nowrap; }
.channels i { flex: none; width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(18, 20, 28, 0.35); }
.channels button[aria-checked="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
/* A narrow panel names only the channel in hand; the rest are their colour. */
@container (max-width: 340px) {
  .channels { grid-auto-columns: auto; grid-template-columns: none; display: flex; }
  .channels button { flex: 1; }
  .channels button[aria-checked="true"] { flex: 2.2; }
  .channels button:not([aria-checked="true"]) span { display: none; }
  .channels i { width: 16px; height: 16px; }
}

.swatches { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 12px 14px 4px; }
.swatches::-webkit-scrollbar { display: none; }
.swatches button, .swatches .custom { flex: none; position: relative; width: 34px; height: 34px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(18, 20, 28, 0.18); cursor: pointer; }
.swatches [aria-checked="true"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4.5px var(--ink); }
.swatches .sculpted::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; border: 2.5px solid var(--paper); mix-blend-mode: difference; }
.swatches .custom { --c: conic-gradient(#ff5c5c, #ffd23f, #3dffc0, #35a8ff, #a070ff, #ff5ca8, #ff5c5c); overflow: hidden; }
.swatches .custom input { position: absolute; inset: -8px; width: 150%; height: 150%; opacity: 0; cursor: pointer; }

.lights { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.lights button { display: grid; justify-items: center; gap: 6px; min-height: 64px; padding: 8px 4px; border-radius: 12px; font-size: 12px; font-weight: 800; box-shadow: inset 0 0 0 2px var(--line); line-height: 1.15; }
.lights i { width: 100%; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 1.5px rgba(18, 20, 28, 0.2); }
.lights [data-light="studio"] i { background: linear-gradient(100deg, #f4f1ea 0 34%, var(--signature) 34% 66%, #f4f1ea 66%); }
.lights [data-light="cafe"] i { background: linear-gradient(100deg, #f6b877 0 30%, #ffeec4 30% 58%, #f6b877 58%); }
.lights [data-light="stage"] i { background: linear-gradient(100deg, #2233a4 0 36%, #7fd0ff 36% 60%, #2233a4 60%); }
.lights button[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--ink); background: var(--ink); color: var(--paper); }

.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 8px; font-size: 13px; font-weight: 800; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 44px; height: 26px; border-radius: 13px; background: var(--track); position: relative; transition: background 0.18s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--paper); box-shadow: 0 0 0 2px var(--ink); transition: translate 0.18s var(--ease); }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { translate: 18px 0; }
.hint { font-size: 12px; font-weight: 600; color: var(--mute); line-height: 1.5; }

/* ---- roomy panel: every section open at once ---- */
@media (min-width: 900px) and (min-height: 700px) {
  .tabs { display: none; }
  .sheet { padding: 20px 22px; display: grid; align-content: start; gap: 26px; }
  .card { display: block !important; }
  .card > header { display: flex; min-height: 34px; margin-bottom: 10px; }
  .sliders { grid-template-columns: 1fr 1fr; gap: 10px 22px; }
  .looks { flex-wrap: wrap; margin: 0; padding: 0 0 12px; }
  .looks button { flex: 1 1 40%; }
  .swatches { flex-wrap: wrap; margin: 0; padding: 14px 0 0; }
  .top { padding: 18px 22px; }
  .brand { font-size: 20px; }
  .brand span { font-size: 11px; }
  .motion { bottom: 22px; gap: 10px; }
  .motion button { flex-basis: 124px; min-height: 52px; font-size: 16px; }
  .focus { left: 22px; }
  .meter { right: 22px; top: 84px; font-size: 11px; }
}

/* ---- upright phone: the panel is a sheet under the stage ---- */
@media (max-aspect-ratio: 1/1) {
  :root { --panel: 100vw; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; transition: none; }
  [data-folded="true"] .app { grid-template-columns: minmax(0, 1fr); }
  .stage { padding-left: 0; }
  .panel { box-shadow: 0 -2px 0 var(--ink); padding-right: 0; }
  .tabs { padding-right: 48px; }
  .fold { left: auto; right: 4px; top: 1px; margin: 0; width: 44px; height: 44px; border-radius: 12px; box-shadow: none; }
  .fold svg { transform: none; }
  [data-folded="true"] .fold svg { transform: rotate(180deg); }
  .sheet { flex: none; height: calc(190px + env(safe-area-inset-bottom)); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); transition: height 0.32s var(--ease), padding 0.32s var(--ease); }
  [data-folded="true"] .tabs { visibility: visible; padding-bottom: env(safe-area-inset-bottom); }
  [data-folded="true"] .sheet { height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }
  .sliders { grid-template-columns: 1fr 1fr; gap: 4px 16px; }
  .focus { top: 46%; }
  .who button { padding: 0 12px; font-size: 13px; }
  .motion button { font-size: 13px; }
}

/* ---- phone on its side: height is scarce, so the motions stack beside the figure, clear of the fold handle ---- */
@media (max-height: 500px) and (min-aspect-ratio: 1/1) {
  .motion { left: auto; right: 40px; top: 66px; bottom: 8px; width: 96px; padding: 0; flex-direction: column; justify-content: center; gap: 6px; }
  .motion button { flex: 0 1 46px; min-height: 40px; }
  .focus { top: calc(50% + 24px); }
  .meter { left: 14px; right: auto; top: auto; bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- loading and failure ---- */
.veil { position: fixed; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 18px; background: #f4f1ea; text-align: center; padding: 24px; font-weight: 800; transition: opacity 0.35s, visibility 0.35s; }
.veil-mark { width: 72px; height: 72px; background: var(--signature); transform: skewX(-11deg); box-shadow: 8px 8px 0 var(--ink); animation: mark 0.9s var(--ease) infinite alternate; }
.veil[data-state="error"] .veil-mark { animation: none; background: var(--ink); box-shadow: 8px 8px 0 var(--signature); }
.veil[data-state="done"] { opacity: 0; visibility: hidden; }
.veil button { min-height: 46px; padding: 0 22px; border-radius: 999px; background: var(--ink); color: var(--paper); font-weight: 800; }
@keyframes mark { to { transform: skewX(-11deg) translateY(-10px); } }
