@layer reset, theme, layout, components, variants;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, p, figure { margin: 0; }
  button, input { font: inherit; }
  a { color: inherit; }
  img { display: block; max-width: 100%; height: auto; }
}

@layer theme {
  :root {
    color-scheme: dark;
    font-family: "Avenir Next", system-ui, sans-serif;
    font-weight: 500;
    background: #080b13;
    color: #f5f4ff;
    --base: #171329;
    --surface: #221c37;
    --raised: #302647;
    --line: #564366;
    --muted: #c7bbd7;
    --accent: #d4baff;
    --on-accent: #21143a;
    --success: #a4f4cb;
    --permit: #ffcb96;
    --radius: 22px;
    --scene: image-set(url("recursos/base-aurora.v062.webp") 1x, url("recursos/base-aurora.v062.2x.webp") 2x);
  }

  .older {
    --base: #0d1720;
    --surface: #142432;
    --raised: #1d3242;
    --line: #3a5365;
    --muted: #b8cbd7;
    --accent: #a7edf1;
    --on-accent: #0b3035;
    --radius: 13px;
    --scene: image-set(url("recursos/base-orbital.v062.webp") 1x, url("recursos/base-orbital.v062.2x.webp") 2x);
  }
}

@layer layout {
  .app {
    width: min(100%, 510px);
    min-height: 100svh;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    background: var(--base);
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 66px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--line);
  }

  .brand, .context, .tag, .state, .row, .text-icon {
    display: flex;
    align-items: center;
    gap: 9px;
  }

  .brand { font-size: 0.9375rem; font-weight: 500; }
  .brand .icon { color: var(--accent); }
  .context { font-size: 0.8125rem; color: var(--muted); }
  .screen { padding: 22px 16px 20px; display: grid; gap: 18px; align-content: start; }
  .intro { display: grid; gap: 5px; }
  h1 { font-size: clamp(2.125rem, calc(9.5vw * var(--ge-letra, 1)), 3.0625rem); letter-spacing: normal; line-height: 1.03; font-weight: 500; }
  h2 { font-size: 1.375rem; line-height: 1.17; letter-spacing: normal; }
  p { line-height: 1.38; }
  .overline { font-size: 0.8125rem; font-weight: 500; color: var(--accent); }
  .description, .muted { color: var(--muted); }
  .small { font-size: 0.8125rem; }
  .icon { inline-size: 22px; block-size: 22px; flex: none; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@layer components {
  .control {
    min-height: 48px;
    min-width: 48px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: inherit;
    border-radius: calc(var(--radius) * .75);
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    text-decoration: none;
    line-height: 1.17;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .control:focus-visible, input:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
  }

  .control:active, .control[aria-pressed="true"] {
    background: var(--raised);
    box-shadow: inset 0 0 0 2px var(--accent);
  }

  .primary {
    min-height: 56px;
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
    justify-content: space-between;
    border-radius: calc(var(--radius) * .78);
    font-size: 1.0625rem;
    padding-inline: 15px;
  }

  .primary:active { background: #f3eaff; box-shadow: inset 0 0 0 3px var(--on-accent); }
  .plain { background: transparent; }
  .full { width: 100%; }
  .panel { background-color: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  .mini-asset { flex: none; width: 44px; height: 44px; object-fit: contain; }
  .split-copy { flex: 1; display: grid; gap: 2px; min-width: 0; }
  .split-copy strong { font-size: 1rem; line-height: 1.18; }

  .home { flex: 1; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 13px; align-content: stretch; }
  .home .intro { padding-inline: 3px; }
  .hero {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    isolation: isolate;
    min-height: 334px;
    background: var(--base);
  }

  .scene, .scene::after { position: absolute; inset: 0; }
  .scene { background: var(--scene) center 52% / cover; z-index: -2; }
  .scene::after { content: ""; background: linear-gradient(180deg, #130e22 0%, transparent 20% 44%, #181226e0 75%, #181226 97%); }
  .floating { position: absolute; top: 10%; left: 50%; transform: translateX(-50%); width: 45%; max-height: 56%; object-fit: contain; filter: drop-shadow(0 9px 22px #070b295c); z-index: -1; }
  .hero-info { padding: 16px; display: grid; gap: 9px; }
  .module-icon { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 11px; color: var(--accent); background: #352752e8; border: 1px solid var(--line); }
  .hero-info .row { gap: 11px; }
  .hero-info .label { color: #e8dbff; font-size: 0.8125rem; }
  .guide { display: flex; align-items: center; gap: 9px; padding: 8px 9px; min-height: 70px; }
  .guide .control { flex: none; }
  .dock { display: grid; grid-template-columns: 1.4fr 1fr; gap: 9px; }
  .dock .control { min-height: 56px; }
  .dock .icon { color: var(--accent); }

  .board { display: grid; gap: 14px; padding: 16px; }
  .model { background: radial-gradient(ellipse at 50% 60%, #59427f, transparent 83%), var(--base); min-height: 175px; border: 1px solid var(--line); border-radius: calc(var(--radius) * .7); display: grid; align-content: center; justify-items: center; gap: 13px; padding: 12px; }
  .model .figure-icon { width: 90px; height: 90px; }
  .candidates { display: grid; gap: 9px; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .candidate { min-height: 112px; flex-direction: column; align-items: center; justify-content: center; background: var(--raised); }
  .candidate .figure-icon { width: 58px; height: 58px; }
  .figure-icon { filter: drop-shadow(0 5px 10px #05071270); color: var(--accent); }
  .moon { color: #86ecd6; }
  .turn { color: #b8edf1; }
  .board-footer { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

  .badge-stage { min-height: 284px; display: grid; place-content: center; place-items: center; padding: 20px; text-align: center; gap: 14px; background: radial-gradient(ellipse at 50% 36%, #425348, var(--surface) 70%); }
  .badge { width: 158px; aspect-ratio: 1; clip-path: polygon(50% 0,94% 25%,94% 75%,50% 100%,6% 75%,6% 25%); display: grid; place-items: center; background: conic-gradient(from 35deg, #c1f7db, #3f756a, #183c36, #a3f5dd, #466e56, #c1f7db); }
  .badge-core { width: 83%; height: 83%; clip-path: inherit; display: grid; place-items: center; background: radial-gradient(ellipse at 45% 20%, #356a5f, #193331 75%); color: var(--success); }
  .badge-core .icon { width: 58px; height: 58px; }
  .state { width: fit-content; max-width: 100%; min-height: 30px; padding: 4px 9px; background: var(--base); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; font-size: 0.8125rem; font-weight: 500; }
  .state .icon { width: 17px; height: 17px; }
  .earned { color: var(--success); }
  .locked { color: var(--permit); }
  .detail { display: grid; gap: 7px; padding: 17px; }

  .voice-stage { min-height: 310px; display: grid; justify-items: center; align-content: center; gap: 14px; padding: 15px; background: radial-gradient(ellipse at 50% 37%, #413965, transparent 69%), var(--surface); }
  .voice-asset { width: 190px; height: 155px; object-fit: contain; filter: drop-shadow(0 8px 22px #0c0a24); }
  .wave { display: flex; gap: 4px; align-items: center; justify-content: center; height: 33px; color: var(--accent); }
  .wave i { width: 3px; height: 11px; border-radius: 4px; background: currentColor; }
  .wave i:nth-child(2n) { height: 17px; }
  .wave i:nth-child(3n) { height: 27px; }
  .wave i:nth-child(5n) { height: 21px; }
  .quote { text-align: center; font-size: 1.3125rem; font-weight: 500; }
  .steps { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px; }
  .step { display: flex; justify-content: center; align-items: center; gap: 6px; border-radius: calc(var(--radius) * .7); min-height: 42px; padding: 5px; color: var(--muted); font-size: 0.8125rem; }
  .step.current { background: var(--raised); color: var(--accent); font-weight: 500; }
  .step .icon { width: 18px; height: 18px; }
  .listen-example { display: none; }
  .voice-screen:has(:target) .talk-example { display: none; }
  .voice-screen:has(:target) .listen-example { display: grid; }
  .voice-screen:has(:target) .step:first-child { background: transparent; color: var(--muted); font-weight: 500; }
  .voice-screen:has(:target) .step:last-child { background: var(--raised); color: var(--accent); font-weight: 500; }
  .mic-large { display: grid; place-items: center; width: 75px; aspect-ratio: 1; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); box-shadow: 0 0 0 12px #a7edf11a; }
  .mic-large .icon { width: 36px; height: 36px; }

  .preview { position: relative; isolation: isolate; display: flex; align-items: end; min-height: 212px; padding: 12px; overflow: hidden; }
  .preview .scene { background-position: center 67%; }
  .preview .scene::after { background: linear-gradient(0deg, #100c1de6, transparent 62%); }
  .preview .floating { top: 20%; width: 33%; max-height: 51%; }
  .preview-label { color: white; position: relative; font-size: 1.125rem; font-weight: 500; }
  .custom-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .custom-options .control { min-height: 82px; flex-direction: column; padding-inline: 5px; }
  .custom-options .icon { color: var(--accent); }
  .swatches { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
  .swatch { display: inline-block; width: 20px; height: 20px; border-radius: 50%; background: #d4baff; }
  .swatch.cool { background: #a7edf1; }
  .name-input { width: 100%; min-height: 48px; padding: 10px; border: 1px solid var(--line); color: inherit; background: var(--base); border-radius: 9px; }

  .permit-art { min-height: 194px; display: grid; place-items: center; background: radial-gradient(ellipse at center, #5b403e, transparent 72%), var(--surface); }
  .lock-symbol { display: grid; place-items: center; width: 116px; height: 116px; border-radius: 29px; background: linear-gradient(145deg,#664c44,#2a2534 80%); border: 1px solid #977258; color: var(--permit); box-shadow: 0 14px 28px #130d23a0, inset 0 1px 0 #ffffff5e; }
  .lock-symbol .icon { width: 54px; height: 54px; }
  .permit-body { display: grid; gap: 10px; padding: 16px; }
  .permit-actions { display: grid; gap: 9px; }

  [popover] { position: fixed; inset: auto 0 18px; margin: 0 auto; width: min(calc(100% - 28px), 466px); max-height: calc(100svh - 36px); overflow: auto; border: 1px solid var(--line); padding: 20px; color: inherit; background: var(--base); border-radius: var(--radius); box-shadow: 0 14px 60px #0009; }
  [popover]:popover-open { display: grid; gap: 13px; }
  [popover]::backdrop { background: #060913b3; }
  .menu-link { justify-content: space-between; }
}

@layer variants {
  .older .topbar { min-height: 62px; }
  .older .screen:not(.home) { gap: 15px; }
  .older h1 { font-size: clamp(2rem, calc(8.6vw * var(--ge-letra, 1)), 2.75rem); letter-spacing: normal; }
  .older .hero { border-radius: var(--radius); }
  .older .hero .scene { background-position: 55% 52%; }
  .older .hero .scene::after { background: linear-gradient(180deg, #0b17217a, transparent 30% 45%, #0d171fed 78%, #0d171f 100%); }
  .older .floating { top: 14%; left: 57%; width: 39%; }
  .older .hero-info { padding: 14px; gap: 11px; }
  .older .module-icon { background: #1c3544; }
  .older .hero-info .label { color: var(--muted); }
  .older .guide { min-height: 65px; }
  .older .dock .control { min-height: 50px; }
  .older .model { border-radius: 8px; background: radial-gradient(ellipse at 50% 60%, #2a4d61, transparent 73%), var(--base); }
  .older .candidates { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .older .candidate { min-height: 99px; font-size: 0.8125rem; }
  .older .candidate .figure-icon { width: 43px; height: 43px; }
  .older .badge-stage { padding: 18px 12px; background: radial-gradient(ellipse at 50% 45%, #264b4b, transparent 75%), var(--surface); min-height: 222px; }
  .older .badge { width: 128px; }
  .older .badge-core .icon { width: 47px; height: 47px; }
  .older .voice-stage { background: radial-gradient(ellipse at 50% 37%, #24485a, transparent 69%), var(--surface); }
  .older .preview .floating { left: 56%; }
  .older .custom-options { grid-template-columns: 1fr; }
  .older .custom-options .control { min-height: 54px; padding-inline: 11px; justify-content: flex-start; flex-direction: row; text-align: left; }
  .older .custom-options .value { flex: 1; text-align: right; font-size: 0.8125rem; color: var(--muted); }
  .older .permit-art { background: radial-gradient(ellipse at center, #4d3d33, transparent 72%), var(--surface); min-height: 157px; }
  .older .lock-symbol { width: 96px; height: 96px; border-radius: 18px; }
  .older .lock-symbol .icon { width: 46px; height: 46px; }

  @media (max-height: 810px) {
    .home { padding-block: 17px 15px; }
    .home .hero { min-height: 316px; }
    .screen:not(.home) { padding-block: 17px; gap: 13px; }
    .voice-stage { min-height: 275px; }
    .permit-art { min-height: 158px; }
  }

  @media (max-width: 375px) {
    .screen, .topbar { padding-inline: 13px; }
    .guide { gap: 7px; }
    .guide .control { padding-inline: 8px; }
    .guide .small { font-size: 0.75rem; }
    .hero-info { padding-inline: 13px; }
  }

  @media (prefers-reduced-motion: no-preference) {
    .control { transition: background-color .12s ease, box-shadow .12s ease; }
  }
}

@layer variants {
  .turn-right { transform: rotate(90deg); }
  .turn-left { transform: rotate(270deg); }
  .turn-down { transform: rotate(180deg); }
  .voice-screen .listen-example.primary { display: none; }
  .voice-screen:has(:target) .talk-example.primary { display: none; }
  .voice-screen:has(:target) .listen-example.primary { display: flex; }
  .preview[data-color-preview="Violeta"] { border-color: #a781dd; }
  .preview[data-color-preview="Violeta"] .scene { box-shadow: inset 0 0 40px 3px #c592ff6b; }
  .preview[data-color-preview="Hielo"] { border-color: #70bcc6; }
  .preview[data-color-preview="Hielo"] .scene { box-shadow: inset 0 0 40px 3px #68dae164; }
  .preview[data-piece-preview="Anillo"]::after,
  .preview[data-piece-preview="Visor"]::after { content: ""; position: absolute; pointer-events: none; z-index: -1; }
  .preview[data-piece-preview="Anillo"]::after { inset: 52% 23% 25%; border: 3px solid #d8b1ffb0; border-radius: 50%; box-shadow: 0 0 13px #bd83ff8c; }
  .preview[data-piece-preview="Visor"]::after { inset: 9% 13% 31%; border: 2px solid #7debf885; clip-path: polygon(0 0,100% 0,100% 33%,92% 33%,92% 100%,8% 100%,8% 33%,0 33%); border-radius: 11px; }
  .preview-label { overflow-wrap: anywhere; min-width: 0; }
  .custom-options .value { overflow-wrap: anywhere; min-width: 0; }
}

@layer variants {
  .screen:not(.home) { flex: 1; align-content: stretch; }
  .screen-memoria { grid-template-rows: auto minmax(0, 1fr); }
  .board { grid-template-rows: minmax(175px, 1fr) auto auto; }
  .screen-logros, .screen-arma, .screen-permiso { grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .voice-screen { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
  .home .floating { top: 16%; width: 50%; }
  .older .home .floating { top: 19%; left: 67%; width: 43%; }
  .older .home .intro { grid-template-columns: 1fr max-content; align-items: end; }
  .older .home .overline { grid-column: 1 / -1; }
  .older .home .description { font-size: 0.8125rem; padding-bottom: 3px; }
  .older .hero-info {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    background-color: #101d28ee;
    border-top: 1px solid var(--line);
  }
  .older .hero-info .primary { font-size: 0.875rem; min-height: 50px; padding-inline: 10px; }
  .older .hero-info .label { max-width: 155px; }
  .older .hero-info .label, .older .hero-info .split-copy strong { font-size: 0.8125rem; }
}

@layer variants {
  .older { font-family: system-ui, sans-serif; }
  .older h1 { font-weight: 500; }
  .older .control, .older .brand { font-weight: 500; }
  .older .hero-info .label { line-height: 1.3; }
}

@layer variants {
  .gallery { background: #100f1b; }
  .gallery main { width: min(100%, 520px); margin-inline: auto; padding: 24px 16px; display: grid; gap: 17px; }
  .gallery-header { display: grid; gap: 6px; }
  .album { overflow: hidden; }
  .album-art { height: 137px; background: var(--scene) center 51% / cover; display: grid; place-items: center; }
  .album-art img { width: 104px; height: 104px; object-fit: contain; }
  .album-copy { padding: 13px; display: grid; gap: 11px; }
  .album-copy .primary { min-height: 48px; font-size: 0.9375rem; }
  .album-copy summary { padding: 11px 3px; min-height: 44px; color: var(--muted); cursor: pointer; }
  .album-copy ul { margin: 0; padding-inline-start: 23px; }
  .album-copy li a { display: block; padding-block: 10px; min-height: 44px; }
  .gallery .compare-link { justify-content: space-between; }
}

/* La jerarquía se apoya en tamaño, espacio y color. */
:where(h1, h2, h3, h4, h5, h6, th, strong, b) { font-weight: 500; }
:where(button, summary) { font-synthesis-weight: none; }

@media (min-width: 900px) {
  .app:has(.home) { width: min(100%, 730px); }
  .home { grid-template-rows: auto auto auto auto; align-content: start; }
  .home .hero { min-height: 0; aspect-ratio: 4 / 3; }
  .home .scene::after {
    background: linear-gradient(0deg, #181226 0%, #181226bb 20%, transparent 50%);
  }
  .older .home .hero .scene::after {
    background: linear-gradient(0deg, #0d171f 0%, #0d171f80 18%, transparent 50%);
  }
}
