@layer reset, tokens, base, components;

@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
}

@layer tokens {
  :root {
    --bg:        hsl(214, 100%, 5%);
    --surface:   hsl(215, 11%, 3%);
    --surface2:  hsl(214, 4%, 5%);
    --border:    hsl(214, 35%, 22%);
    --border2:   hsl(214, 10%, 25%);
    --text:      hsl(215, 25%, 85%);
    --text2:     hsl(215, 25%, 85%);
    --text3:     hsl(216, 15%, 60%);
    --accent:    hsl(22, 100%, 62%);
    --accent2:   hsl(22, 100%, 78%);
    --danger:    hsl(0, 100%, 71%);
    --pass-a:    hsl(41, 100%, 65%);
    --pass-aa:   hsl(153, 100%, 55%);
    --pass-aaa:  hsl(201, 100%, 65%);
    --mono:      'Courier New', Courier, monospace;
    --sans:      system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --radius:    0.625rem;
    --radius-sm: 0.375rem;
    --fs-xs:     0.9rem;
    --fs-sm:     1rem;
    --fs-base:   1rem;
    --fs-md:     1.125rem;
    --fs-xl:     3rem;
    --ls-tight:  0.02em;
    --ls-normal: 0.04em;
    --ls-wide:   0.06em;
  }
}

@layer base {
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: var(--fs-base);
    min-height: 100vh;
    padding: 1.4rem 1rem;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  h1 {
    font-weight: 400;
    color: var(--accent);
  }

  .app {
    width: 100%;
    max-width: 65rem;
  }

  main {
    display: grid;
    gap: 1rem;
  }

  code {
    font-family: var(--mono);
    font-size: var(--fs-xs);
    color: var(--accent2);
  }

  img {
    display: block;
    max-width: 100%;
  }

  button {
    font-family: var(--sans);
  }
}

@layer components {
  .hero, .footer, .demo-stage {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
  }

  .hero:hover {
    border-color: var(--accent);
  }

  .hero__eyebrow {
    font-family: var(--sans);
    font-size: var(--fs-base);
    color: var(--text3);
  }

  .hero__title {
    font-size: var(--fs-xl);
    line-height: 1.1;
    letter-spacing: var(--ls-tight);
    margin: 0.25rem 0 0.75rem;
  }

  .hero__text {
    color: var(--text);
    max-width: 60ch;
  }

  .hero__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
  }

  .index-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .demo-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-decoration: none;
    transition: border-color 0.2s, transform 0.15s;
  }

  .demo-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
  }

  .demo-card__tag {
    align-self: flex-start;
    font-size: var(--fs-xs);
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--surface2);
    color: var(--text3);
    border: 1px solid var(--border);
  }

  .demo-card__title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--accent2);
  }

  .demo-card__desc {
    font-size: var(--fs-base);
    color: var(--text3);
    line-height: 1.5;
  }

  .demo-card__go {
    font-size: var(--fs-sm);
    color: var(--accent);
  }

  .demo-stage {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
  }

  .link {
    color: var(--accent);
    border-bottom: 1.5px solid var(--accent);
    text-decoration: none;
  }

  .link:hover {
    color: var(--accent2);
  }

  .btn {
    background: var(--surface2);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1.125rem;
    font-size: var(--fs-base);
    letter-spacing: var(--ls-normal);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
  }

  .btn:hover {
    border-color: var(--accent);
  }

  .btn:active {
    transform: translateY(1px);
  }

  .btn:focus-visible,
  .arrow:focus-visible,
  .dot:focus-visible,
  .card__link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* ── Card con stretch link ── */
  .card {
    position: relative;
    width: 230px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s, transform 0.15s;
  }

  .card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
  }

  .card__link {
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    z-index: 1;
    text-decoration: none;
  }

  .card__cover {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 3;
    overflow: hidden;
  }

  .card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .card__cover-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 10px;
    background: rgba(10, 8, 28, 0.82);
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--accent2);
    line-height: 1.3;
  }

  .card__fav {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text3);
    padding: 0;
    transition: color 0.15s, border-color 0.15s;
  }

  .card__fav:hover {
    color: var(--danger);
    border-color: var(--danger);
  }

  .card__fav[aria-pressed="true"] {
    color: var(--danger);
    border-color: var(--danger);
  }

  .card__fav svg {
    width: 20px;
    height: 20px;
  }

  .card__fav .is-hidden {
    display: none;
  }

  .card__body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .card__title {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    margin: 0;
    line-height: 1.3;
  }

  .card__meta {
    margin: 0;
    font-size: var(--fs-base);
    color: var(--text3);
    line-height: 1.5;
  }

  .card__meta span {
    display: block;
  }

  .card__genre {
    display: inline-block;
    margin-top: 6px;
    font-size: var(--fs-xs);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--accent2);
    border: 1px solid var(--border);
  }

  .card__price {
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text);
    margin-top: 10px;
  }

  .card__cart {
    position: relative;
    z-index: 2;
    margin-top: 10px;
    width: 100%;
    padding: 8px 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }

  .card__cart:hover {
    background: var(--surface2);
    border-color: var(--accent);
  }

  .card__cart:active {
    transform: scale(0.98);
  }

  .card__cart svg {
    width: 18px;
    height: 18px;
  }

  .card__cart.is-added {
    border-color: var(--pass-aa);
    color: var(--pass-aa);
  }

  .docs {
    width: 100%;
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 0.75rem;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .docs__title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--accent2);
    margin: 0;
  }

  .about__intro {
    font-size: var(--fs-base);
    color: var(--text3);
    line-height: 1.6;
    max-width: 60ch;
    margin: 0;
  }

  .docs__block {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .docs__h {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--text);
    margin: 0;
    padding-bottom: 4px;
  }

  .ann {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: var(--fs-base);
    color: var(--text3);
    line-height: 1.5;
  }

  .ann__dot {
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-top: 4px;
    background: var(--accent);
  }

  .ann__label {
    font-weight: 500;
    color: var(--text);
  }

  /* ── Shelf / streaming scroll ── */
  .shelf {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
  }

  .shelf__header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
  }

  .shelf__title {
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text);
    margin: 0;
  }

  .shelf__count {
    font-size: var(--fs-xs);
    color: var(--text3);
  }

  .scroll {
    position: relative;
  }

  .scroll__track {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    padding: 4px 2px 8px;
  }

  .scroll__track:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  .scroll__row {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: 1fr;
    gap: 12px;
  }

  .shelf .scroll__row {
    grid-auto-columns: 160px;
  }

  .products .scroll__row {
    grid-auto-columns: 280px;
  }

  .scroll__track::-webkit-scrollbar {
    height: 4px;
  }

  .scroll__track::-webkit-scrollbar-track {
    background: transparent;
  }

  .scroll__track::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
  }

  .scroll__track.is-hidethumb {
    scrollbar-width: none;
  }

  .scroll__track.is-hidethumb::-webkit-scrollbar {
    display: none;
  }

  .arrow {
    position: absolute;
    top: 50%;
    width: 44px;
    height: 44px;
    transform: translateY(-50%);
    z-index: 10;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    background: var(--surface);
    transition: background 0.15s, opacity 0.2s;
    opacity: 1;
  }

  .arrow:disabled {
    opacity: 0;
    pointer-events: none;
  }

  .arrow:hover:not(:disabled) {
    background: var(--surface2);
    color: var(--accent2);
  }

  .arrow svg {
    width: 22px;
    height: 22px;
  }

  .arrow--left {
    left: 0;
  }

  .arrow--right {
    right: 0;
  }

  .scroll--gutter .scroll__track {
    margin: 0 44px;
  }

  /* ── Item comic portada ── */
  .comic {
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
    transition: border-color 0.15s, transform 0.15s;
  }

  .comic:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
  }

  .comic:focus-within {
    border-color: var(--accent);
  }

  .comic__cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    position: relative;
    overflow: hidden;
  }

  .comic__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .comic__issue {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: var(--fs-xs);
    font-weight: 500;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--surface);
    z-index: 2;
  }

  .comic__title {
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    z-index: 1;
    font-size: var(--fs-xs);
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
    padding: 4px 6px;
    color: var(--text);
    background: var(--surface);
  }

  .comic__meta {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .comic__name {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    margin: 0;
  }

  .comic__sub {
    font-size: var(--fs-base);
    color: var(--text3);
    margin: 0;
    line-height: 1.4;
  }

  .comic__genre {
    display: inline-block;
    margin-top: 4px;
    font-size: var(--fs-xs);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--accent2);
    border: 1px solid var(--border);
  }

  /* ── Product card horizontal ── */
  .products {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
  }

  .products__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .products__title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--accent2);
    margin: 0;
  }

  .product-card {
    scroll-snap-align: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s;
  }

  .product-card:hover {
    border-color: var(--accent);
  }

  .product-card:focus-within {
    border-color: var(--accent);
  }

  .product-card__image {
    width: 100%;
    aspect-ratio: 3 / 2;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
  }

  .product-card__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .product-card__body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
  }

  .product-card__category {
    font-size: var(--fs-xs);
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--text3);
    text-transform: uppercase;
  }

  .product-card__name {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    margin: 0;
    line-height: 1.3;
  }

  .product-card__desc {
    font-size: var(--fs-base);
    color: var(--text3);
    line-height: 1.5;
    margin: 0;
    flex: 1;
  }

  .product-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
  }

  .product-card__price {
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text);
  }

  .product-card__badge {
    font-size: var(--fs-xs);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--pass-aa);
    font-weight: 500;
  }

  .product-card__btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
  }

  .product-card__btn:hover {
    background: var(--surface2);
    border-color: var(--accent);
  }

  .product-card__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .product-card__btn.is-added {
    border-color: var(--pass-aa);
    color: var(--pass-aa);
  }

  /* ── Dots ── */
  .dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
  }

  .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, width 0.2s;
    border: none;
    padding: 0;
    cursor: pointer;
  }

  .dot.is-active {
    background: var(--accent);
    width: 18px;
    border-radius: 3px;
  }

  /* ── Subgrid demo ── */
  .subgrid-demo {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .subgrid-demo__controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  .subgrid-demo__label {
    font-size: var(--fs-xs);
    color: var(--text3);
  }

  .subgrid-demo__label strong {
    font-weight: 500;
    color: var(--text);
  }

  .mode-badge {
    font-size: var(--fs-xs);
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-weight: 500;
  }

  .mode-badge--on {
    background: var(--surface2);
    color: var(--pass-aa);
    border: 1px solid var(--pass-aa);
  }

  .mode-badge--off {
    background: var(--surface2);
    color: var(--danger);
    border: 1px solid var(--danger);
  }

  .cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    align-items: start;
  }

  article.sub-card {
    display: grid;
    grid-row: span 4;
    grid-template-rows: subgrid;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
  }

  article.sub-card:hover {
    border-color: var(--accent);
  }

  .sub-card__cover {
    width: 100%;
    aspect-ratio: 3 / 2;
    overflow: hidden;
  }

  .sub-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .sub-card__text {
    padding: 12px 14px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .sub-card__title {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text);
    margin: 0;
    line-height: 1.35;
  }

  .sub-card__meta {
    font-size: var(--fs-base);
    color: var(--text3);
    margin: 4px 0 0;
    line-height: 1.5;
  }

  .sub-card__footer {
    padding: 10px 14px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
    margin-top: 12px;
  }

  .sub-card__price {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
  }

  .sub-card__btn {
    font-size: var(--fs-xs);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }

  .sub-card__btn:hover {
    background: var(--surface2);
    border-color: var(--accent);
  }

  .sub-card__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .cards-grid.no-subgrid {
    align-items: stretch;
  }

  .cards-grid.no-subgrid article.sub-card {
    display: flex;
    flex-direction: column;
    grid-row: unset;
    grid-template-rows: unset;
  }

  .cards-grid.no-subgrid .sub-card__footer {
    margin-top: auto;
  }

  .track-labels {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 6px;
  }

  .track-label {
    font-size: var(--fs-xs);
    color: var(--text3);
    text-align: center;
  }

  .footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .footer__brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .footer__logo {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--radius-sm);
    object-fit: cover;
  }

  .footer__name {
    font-weight: 600;
    letter-spacing: var(--ls-wide);
  }

  .footer__link {
    color: var(--text3);
    text-decoration: none;
    font-size: var(--fs-sm);
  }

  .footer__link:hover {
    color: var(--accent);
  }

  /* ── Código replicable ── */
  .doc {
    width: 100%;
    margin-top: 0.75rem;
  }

  .doc__intro {
    color: var(--text3);
    max-width: 60ch;
    margin: 0 0 1rem;
  }

  .code {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin: 0 0 0.75rem;
    transition: border-color 0.2s;
  }

  .code:hover { border-color: var(--accent); }

  .code__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
  }

  .code__header-text {
    font-size: var(--fs-sm);
    color: var(--text3);
    font-family: var(--mono);
  }

  .code__copy {
    background: var(--accent);
    color: var(--surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius-sm);
    font-family: var(--sans);
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: var(--ls-normal);
    padding: 0.4rem 1rem;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
  }

  .code__copy:hover { transform: scale(1.03); opacity: 0.9; }
  .code__copy:active { transform: scale(0.98); }

  .code__pre {
    margin: 0;
    padding: 1rem 1.125rem;
    font-family: var(--mono);
    font-size: var(--fs-sm);
    line-height: 1.6;
    overflow-x: auto;
    color: var(--text);
    white-space: pre;
  }

  .tok-sel  { color: var(--accent2); }
  .tok-prop { color: var(--text); }
  .tok-val  { color: var(--pass-aaa); }
  .tok-comment { color: var(--text3); }
}

@media (prefers-reduced-motion: reduce) {
  .demo-card,
  .card,
  .comic,
  .arrow,
  .product-card,
  .code__copy,
  .scroll__row {
    scroll-behavior: auto;
    transition: none !important;
  }
}

@media (max-width: 55rem) {
  .index-grid {
    grid-template-columns: 1fr;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .track-labels {
    grid-template-columns: 1fr;
  }
}
