/* =========================================================================
   ENTROPIC CONFIGURACIÓN — UI 3.1 (same system as Entropic Dimensión 3.5)
   One family (Prompt, the tool's own typeface), pure black / white,
   hairline structure, inversion for the active state. No accent colour:
   the glyph is the only loud thing on screen.
   ========================================================================= */

/* ---------- Fonts -------------------------------------------------------- */
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Thin.ttf');    font-weight: 100; }
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Light.ttf');   font-weight: 300; }
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Regular.ttf'); font-weight: 400; }
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Medium.ttf');  font-weight: 500; }
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Bold.ttf');    font-weight: 700; }
@font-face { font-family: 'Prompt'; src: url('prompt/Prompt-Black.ttf');   font-weight: 900; }
/* Per-weight families, used by p5 text() in the playground */
@font-face { font-family: 'Prompt-Thin';    src: url('prompt/Prompt-Thin.ttf'); }
@font-face { font-family: 'Prompt-Light';   src: url('prompt/Prompt-Light.ttf'); }
@font-face { font-family: 'Prompt-Regular'; src: url('prompt/Prompt-Regular.ttf'); }
@font-face { font-family: 'Prompt-Medium';  src: url('prompt/Prompt-Medium.ttf'); }
@font-face { font-family: 'Prompt-Bold';    src: url('prompt/Prompt-Bold.ttf'); }
@font-face { font-family: 'Prompt-Black';   src: url('prompt/Prompt-Black.ttf'); }

/* ---------- Tokens ------------------------------------------------------- */
:root,
[data-theme="dark"] {
    --bg: #000000;
    --fg: #ffffff;
    --line: #2a2a2a;      /* hairlines, idle tracks */
    --line-strong: #4a4a4a;
    --muted: #8c8c8c;     /* labels, hints (AA on black) */
    --hover: rgba(255, 255, 255, 0.06);

    --panel-w: 272px;
    --bar-h: 76px;
    --r-pill: 999px;
    --r-box: 14px;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);

    --t-micro: 11px;      /* values, stop labels */
    --t-small: 12.5px;    /* labels, hints, buttons */
    --t-body: 14px;       /* wordmark */
}

[data-theme="light"] {
    --bg: #ffffff;
    --fg: #000000;
    --line: #dedede;
    --line-strong: #b5b5b5;
    --muted: #6e6e6e;
    --hover: rgba(0, 0, 0, 0.05);
}

/* ---------- Base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--fg);
    font-family: 'Prompt', system-ui, sans-serif;
    font-weight: 300;
    font-size: var(--t-small);
    line-height: 1.4;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s ease, color .3s ease;
}

button, input, output, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor;
      stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 1.5px solid var(--fg); outline-offset: 3px; border-radius: 4px; }

#app { display: flex; height: 100vh; width: 100vw; }

/* ---------- Panel -------------------------------------------------------- */
#panel {
    flex: 0 0 var(--panel-w);
    width: var(--panel-w);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    overflow: hidden;
    transition: flex-basis .45s var(--ease), width .45s var(--ease), border-color .3s ease;
}

.panel-head,
.panel-body,
.panel-foot { width: var(--panel-w); padding-inline: 20px; }

/* Footer: same height and top line as the entropy bar, so both read as one strip */
.panel-foot {
    flex: 0 0 var(--bar-h);
    display: flex; align-items: center;
    border-top: 1px solid var(--line);
}
.panel-foot .segmented { flex: 1; }

.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    height: 64px;
}

.wordmark { font-size: var(--t-body); font-weight: 500; letter-spacing: 0.01em; }
.version { font-weight: 300; color: var(--muted); margin-left: 4px; }

.panel-body {
    flex: 1;
    overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 22px;
    padding-top: 4px; padding-bottom: 20px;
    scrollbar-width: none;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Groups — like Illustrator's Character / Paragraph panels */
.group { display: flex; flex-direction: column; gap: 12px; }
.group + .group { padding-top: 18px; border-top: 1px solid var(--line); }
.group-label { font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-label { color: var(--muted); }
.value { font-size: var(--t-micro); font-variant-numeric: tabular-nums; }

/* Text field — compact, set in the chosen weight */
.text-input {
    display: block;
    width: 100%;
    min-height: 64px;
    max-height: 168px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 10px;
    resize: none;
    overflow: hidden;
    text-align: var(--text-align, center);
    font-size: var(--text-fs, 40px);
    line-height: 1.05;
    font-weight: 400;
    color: var(--fg);
    caret-color: var(--muted);
    overflow-wrap: anywhere;
    transition: border-color .2s ease;
}
.text-input.is-upper { text-transform: uppercase; }
.text-input:hover { border-color: var(--line-strong); }
.text-input:focus { outline: none; border-color: var(--fg); }
.notice { font-size: var(--t-micro); margin-top: -4px; }
.notice[hidden] { display: none; }

/* Boxed controls: weight select and the two spin fields share one look */
.select, .spin {
    position: relative;
    display: flex; align-items: center;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    transition: border-color .2s ease;
}
.select:hover, .spin:hover { border-color: var(--line-strong); }
.select:focus-within, .spin:focus-within { border-color: var(--fg); }

.select select {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 100%;
    padding: 0 34px 0 12px;
    background: transparent; border: 0;
    font: inherit; font-weight: 400; color: var(--fg);
    cursor: pointer;
}
.select select:focus { outline: none; }
.select select option { background: var(--bg); color: var(--fg); }
.select > svg { position: absolute; right: 9px; pointer-events: none; color: var(--muted); }

/* Spin field: [icon][▲▼][value][▾] */
.spin-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.spin { min-width: 0; padding-left: 6px; }
.spin-icon {
    display: grid; place-items: center;
    width: 22px; height: 100%;
    color: var(--muted);
    cursor: ew-resize;
    touch-action: none;
}
.spin-icon svg { width: 18px; height: 18px; stroke-width: 1.2; }
.spin:hover .spin-icon { color: var(--fg); }
.spin-steps { display: flex; flex-direction: column; justify-content: center; margin-left: 2px; }
.spin-steps button {
    display: grid; place-items: center;
    width: 14px; height: 12px;
    color: var(--muted);
    border-radius: 3px;
}
.spin-steps button:hover { color: var(--fg); background: var(--hover); }
.spin-steps svg { width: 10px; height: 6px; stroke-width: 1.4; }
.spin-input {
    flex: 1; min-width: 0; width: 100%;
    height: 100%;
    padding: 0 2px 0 6px;
    background: transparent; border: 0;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.spin-input:focus { outline: none; }
.spin-menu {
    position: relative;
    display: grid; place-items: center;
    width: 24px; height: 100%;
    flex-shrink: 0;
    color: var(--muted);
}
.spin-menu:hover { color: var(--fg); }
.spin-menu svg { width: 16px; height: 16px; }
.spin-menu select {
    position: absolute; inset: 0;
    opacity: 0; cursor: pointer;
    font: inherit;
}
.spin-menu select option { background: var(--bg); color: var(--fg); }
.spin.is-idle { opacity: .45; }

/* Alignment + all caps */
.tool-row { display: flex; align-items: center; justify-content: space-between; }
.icon-group { display: flex; gap: 2px; }
.icon-group button, .caps-btn {
    display: grid; place-items: center;
    width: 34px; height: 30px;
    border-radius: 7px;
    color: var(--muted);
    transition: background-color .2s ease, color .2s ease;
}
.icon-group button:hover, .caps-btn:hover { color: var(--fg); background: var(--hover); }
.icon-group button[aria-checked="true"],
.caps-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.icon-group.is-idle button[aria-checked="true"] { background: var(--line); color: var(--fg); }
.caps-btn { width: 40px; border: 1px solid var(--line); font-weight: 500; font-size: var(--t-micro); letter-spacing: 0.02em; }
.caps-btn[aria-pressed="true"] { border-color: var(--fg); }

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-pair .field { min-width: 0; }
.field-pair .field-row { gap: 6px; }
.field-pair .field-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Range — hairline track, filled up to the thumb */
input[type="range"] {
    --p: 50%;
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 18px;
    background: transparent;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 2px; border-radius: 2px;
    background: linear-gradient(to right, var(--fg) var(--p), var(--line) var(--p));
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); border-radius: 2px; }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--fg); }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; margin-top: -6px;
    border-radius: 50%;
    background: var(--fg);
    border: 3px solid var(--bg);
    box-shadow: 0 0 0 1px var(--fg);
    transition: transform .15s ease;
}
input[type="range"]::-moz-range-thumb {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--fg); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--fg);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }
input[type="range"]:focus-visible { outline-offset: 4px; }

/* Segmented control */
.segmented {
    display: flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
}
.segmented button {
    flex: 1;
    padding: 6px 16px;
    border-radius: var(--r-pill);
    color: var(--muted);
    white-space: nowrap;
    transition: background-color .2s ease, color .2s ease;
}
.segmented button:hover { color: var(--fg); }
.segmented--compact button { padding: 6px 8px; }

/* Local-only block inside the Entropy group */
.subgroup { display: flex; flex-direction: column; gap: 12px; padding: 12px; margin: 0 -12px; border-radius: 10px; background: var(--hover); }
.subgroup[hidden] { display: none; }
.pins-row { display: flex; align-items: baseline; gap: 10px; }
.text-btn { font-size: var(--t-micro); color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.text-btn:hover:not(:disabled) { color: var(--fg); }
.text-btn:disabled { opacity: .4; text-decoration: none; cursor: default; }
.segmented button[aria-checked="true"] { background: var(--fg); color: var(--bg); }

/* Collapsed panel */
.is-collapsed #panel { flex-basis: 0; width: 0; border-right-color: transparent; }

/* ---------- Buttons ------------------------------------------------------ */
.icon-btn {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 10px;
    color: var(--muted);
    transition: color .2s ease, background-color .2s ease;
}
.icon-btn:hover { color: var(--fg); background: var(--hover); }

.pill {
    display: inline-flex; align-items: center; gap: 8px;
    height: 38px; padding: 0 16px 0 13px;
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    white-space: nowrap;
    transition: border-color .2s ease, background-color .2s ease;
}
.pill:hover { border-color: var(--fg); }
.pill--solid { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---------- Stage -------------------------------------------------------- */
#stage {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex; flex-direction: column;
}

#stage-top {
    position: absolute; z-index: 20;
    top: 14px; left: 16px; right: 16px;
    display: grid; grid-template-columns: 1fr auto 1fr;
    align-items: center;
    pointer-events: none;
}
#stage-top > * { pointer-events: auto; }
#stage-top .segmented { background: var(--bg); }
#stage-top .segmented button { padding: 6px 18px; }
#playground-btn { justify-self: end; background: var(--bg); }

.reveal-btn { justify-self: start; visibility: hidden; opacity: 0; transition: opacity .3s ease; }
.is-collapsed .reveal-btn { visibility: visible; opacity: 1; }

.local-hint {
    position: absolute; z-index: 20;
    top: 62px; left: 0; right: 0;
    text-align: center;
    color: var(--muted); font-size: var(--t-micro);
    opacity: 0; transition: opacity .3s ease;
    pointer-events: none;
}
.is-local .local-hint, .is-interactive .local-hint { opacity: 1; }
.is-local #canvas-container { cursor: none; }
#restart-btn { display: none; }
.is-local #restart-btn, .is-interactive #restart-btn { display: inline-flex; }
#restart-btn:disabled { opacity: .4; cursor: default; }
#restart-btn:disabled:hover { border-color: var(--line); }

/* Interactive: after the first change the text and its layout are locked */
.is-locked .lockable { opacity: .45; pointer-events: none; }
.is-dragging #canvas-container { cursor: grabbing; }

#canvas-container { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#canvas-container canvas { display: block; }

/* ---------- Entropy bar -------------------------------------------------- */
#bar {
    flex: 0 0 var(--bar-h);
    display: flex; align-items: center;
    gap: 28px;
    padding: 0 20px 0 16px;
    border-top: 1px solid var(--line);
}

/* Play */
.play {
    width: 44px; height: 44px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--fg); color: var(--bg);
    transition: transform .2s var(--ease);
}
.play:active { transform: scale(.94); }
.play svg { fill: currentColor; stroke: none; }
.play .i-pause, .is-playing .play .i-play { display: none; }
.is-playing .play .i-pause { display: block; }

/* Timeline — the memorable piece: phases as a scrubbable line */
.timeline {
    flex: 1; min-width: 220px;
    display: flex; flex-direction: column; gap: 8px;
    padding-top: 6px;
}
.track {
    --p: 0;
    position: relative;
    height: 18px;
    cursor: ew-resize;
    touch-action: none;
}
.track::before,
.track-fill {
    content: '';
    position: absolute; left: 0; top: 50%;
    height: 2px; margin-top: -1px;
    border-radius: 2px;
}
.track::before { right: 0; background: var(--line); }
.track-fill { width: calc(var(--p) * 100%); background: var(--fg); }
.track-head {
    position: absolute; top: 50%;
    left: calc(var(--p) * 100%);
    width: 14px; height: 14px; margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: var(--fg);
    border: 3px solid var(--bg);
    box-shadow: 0 0 0 1px var(--fg);
}
.track:focus-visible { outline: none; }
.track:focus-visible .track-head { box-shadow: 0 0 0 1px var(--fg), 0 0 0 5px var(--line-strong); }

.stops { position: relative; height: 16px; }
.stop {
    position: absolute; top: 0;
    transform: translateX(-50%);
    font-size: var(--t-micro); font-weight: 400;
    color: var(--muted);
    padding: 0 4px;
    transition: color .2s ease;
}
.stop:first-child { transform: none; padding-left: 0; }
.stop:last-child { transform: translateX(-100%); padding-right: 0; }
.stop:hover, .stop.is-reached { color: var(--fg); }
.stop.is-current { font-weight: 500; }
/* tick above each stop */
.stop::before {
    content: ''; position: absolute; left: 50%; top: -15px;
    width: 1px; height: 6px; background: currentColor; opacity: .7;
}
.stop:first-child::before { left: 0; }
.stop:last-child::before { left: auto; right: 0; }

/* Export — split button, menu opens upwards */
.export { position: relative; display: flex; }
.export-main, .export-caret {
    height: 38px;
    background: var(--fg); color: var(--bg);
    font-weight: 400;
}
.export-main {
    width: 164px; padding: 0 14px;
    border-radius: var(--r-pill) 0 0 var(--r-pill);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.export-caret {
    width: 36px; display: grid; place-items: center;
    border-radius: 0 var(--r-pill) var(--r-pill) 0;
    border-left: 1px solid var(--bg);
}
.export-caret svg { width: 16px; height: 16px; transition: transform .2s ease; }
.export-caret[aria-expanded="true"] svg { transform: rotate(180deg); }
.export.is-busy .export-main { cursor: progress; }

.export-menu {
    position: absolute; right: 0; bottom: calc(100% + 10px);
    width: 260px;
    padding: 6px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--r-box);
    z-index: 50;
}
.export-menu[hidden] { display: none; }
.menu-group + .menu-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.menu-item {
    width: 100%;
    display: grid; grid-template-columns: 64px 1fr; align-items: baseline;
    padding: 8px 10px;
    border-radius: 8px;
    text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item b { font-weight: 500; }
.menu-item span { color: var(--muted); font-size: var(--t-micro); }
.menu-item[aria-checked="true"] b::after { content: ' ✓'; font-weight: 300; }

/* ---------- Playground --------------------------------------------------- */
#pg-start, .playground-hint, #pg-hud, #pg-controls { display: none; }

.is-playground #panel,
.is-playground #bar,
.is-playground #stage-top,
.is-playground .local-hint { display: none; }

.is-playground #pg-start {
    display: flex; gap: 10px; align-items: center;
    position: fixed; z-index: 220; top: 20px; left: 20px;
}
/* Only problems are written on screen (camera, hand tracking), under the top buttons */
.is-playground .playground-hint.is-error {
    display: block;
    position: fixed; z-index: 200; top: 72px; left: 0; right: 0;
    text-align: center; color: var(--fg);
}

/* Round text button next to Exit, and its small window */
.pg-round {
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 60%, transparent);
    color: var(--fg);
    transition: border-color .2s ease, background-color .2s ease, color .2s ease;
}
.pg-round svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.pg-round:hover { border-color: var(--fg); }
.pg-round[aria-expanded="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.pg-text-pop {
    position: absolute; top: 48px; left: 0;
    width: 260px;
    display: flex; flex-direction: column; gap: 8px;
    padding: 12px;
    border: 1px solid var(--line); border-radius: 12px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.pg-text-pop[hidden] { display: none; }
.pg-text-pop input {
    height: 44px; padding: 0 12px;
    border: 1px solid var(--line); border-radius: 8px;
    background: transparent; color: var(--fg);
    font-size: 22px; font-weight: 500;
}
.pg-text-pop input:focus { outline: none; border-color: var(--fg); }
.pg-text-pop input:disabled { opacity: .5; }
.pg-text-note { font-size: var(--t-micro); color: var(--muted); }

/* Phase scale: the main timeline, read-only, driven by the right hand.
   The line keeps the width of the former hand meter (324 px). */
.is-playground #pg-hud {
    display: block;
    position: fixed; z-index: 200;
    bottom: 20px; left: 50%; transform: translateX(-50%);
    width: min(324px, calc(100vw - 32px));
    pointer-events: none;
}
#pg-hud .timeline { min-width: 0; }
/* Left-hand settings under the phase scale */
.pg-values { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.pg-val {
    display: inline-flex; align-items: center; gap: 5px;
    height: 28px; padding: 0 12px;
    border: 1px solid var(--line); border-radius: var(--r-pill);
    background: color-mix(in srgb, var(--bg) 60%, transparent);
    color: var(--muted); font-size: var(--t-micro); white-space: nowrap;
    transition: border-color .2s ease, background-color .2s ease, color .2s ease;
}
.pg-val b { color: var(--fg); font-weight: 500; font-variant-numeric: tabular-nums; }
.pg-val.is-active { border-color: var(--fg); color: var(--fg); }
.pg-val.is-fixed { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.pg-val.is-fixed b { color: var(--bg); }
#pg-hud .track { cursor: default; }

.is-playground #pg-controls {
    display: flex; gap: 10px; align-items: center;
    position: fixed; z-index: 200; top: 20px; right: 20px;
}
/* Buttons over the camera: 60% backgrounds */
#pg-controls .segmented, #pg-controls .pill { background: color-mix(in srgb, var(--bg) 60%, transparent); }
#pg-controls .segmented button[aria-checked="true"],
.is-playground #back-btn { background: color-mix(in srgb, var(--fg) 60%, transparent); }
.is-playground #back-btn { border-color: transparent; }

/* Short confirmation for density steps and theme switches */
/* Top centre, on the line of the playground buttons and the same height */
#pg-toast {
    position: fixed; z-index: 210; top: 20px; left: 50%;
    display: flex; align-items: center;
    height: 38px; padding: 0 18px;
    transform: translate(-50%, -6px);
    border-radius: var(--r-pill);
    background: var(--fg); color: var(--bg);
    font-weight: 500; white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, transform .2s var(--ease);
}
#pg-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
#pg-toast:empty { display: none; }
.is-playground #canvas-container::after {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    box-shadow: inset 0 0 0 2px var(--fg);
}

/* ---------- Narrow screens ------------------------------------------------ */
@media (max-width: 900px) {
    #bar { flex-wrap: wrap; height: auto; flex-basis: auto; gap: 14px 20px; padding: 14px 16px; }
    .timeline { order: 1; flex-basis: 100%; }
    #variation-btn { margin-right: auto; }
}
@media (max-width: 640px) {
    :root { --panel-w: 100vw; }
    #panel { position: fixed; inset: 0 auto 0 0; z-index: 100; background: var(--bg); }
    #playground-btn { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
}
