@layer base, shop, admin, responsive;

@layer base {
  :root {
    color-scheme: dark;
    --bg: #121314;
    --surface: #202123;
    --raised: #28292c;
    --line: #3a3c40;
    --text: #f0f1f3;
    --muted: #aeb0b7;
    --silver: #d9dadf;
    --dark-ink: #18191b;
    --green: #9ad8b2;
    --red: #f4afb0;
    --radius: 12px;
    font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
    line-height: 1.5;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
      repeating-linear-gradient(135deg, transparent 0 70px, #fff1 71px, transparent 72px 144px) fixed,
      radial-gradient(ellipse at 50% 0%, #292b2e, #141516 54%, var(--bg) 82%) fixed;
    font-size: 15px;
  }
  [hidden] { display: none !important; }
  a { color: inherit; text-underline-offset: .2em; }
  a:hover { color: white; }
  img { max-width: 100%; }
  button, input, select, textarea { font: inherit; }
  button, .button { cursor: pointer; }
  button:disabled { cursor: default; }
  :focus-visible { outline: 2px solid #d4d9e0; outline-offset: 4px; }
  svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
  h1, h2, h3, p, dl { margin: 0; }
  h1 { font-size: clamp(1.6rem, 4vw, 2.25rem); font-weight: 660; line-height: 1.12; letter-spacing: -.048em; }
  h2 { font-size: 1.13rem; font-weight: 650; letter-spacing: -.018em; }
  h3 { font-size: 1rem; }
  .muted { color: var(--muted); }
  .mono { font-family: ui-monospace, Consolas, monospace; font-size: .87rem; }
  .spill { overflow-wrap: anywhere; }
  .split { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; }
  .stack { display: grid; gap: 1rem; }
  .stack > .button { justify-self: start; }
  .stack label, label:has(> input[readonly]) { display: grid; gap: .4rem; min-width: 0; }
  input:not([type=checkbox]), select, textarea {
    width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: .65rem .75rem;
    background: #191a1c; color: var(--text);
  }
  textarea { resize: vertical; }
  .check, .stack .check { display: flex; gap: .65rem; align-items: flex-start; }
  .check input { accent-color: var(--silver); width: 1rem; height: 1rem; margin: .24rem 0 0; flex-shrink: 0; }
  .button {
    display: inline-flex; gap: .45rem; justify-content: center; align-items: center; box-sizing: border-box;
    min-height: 39px; padding: .5rem .78rem; border: 1px solid #494b50; border-radius: 8px;
    background: #303135; color: var(--text); font-size: .88rem; font-weight: 580; text-decoration: none;
    transition: background .16s, border-color .16s, color .16s;
  }
  .button svg { width: 17px; height: 17px; }
  .button:hover { background: #404247; border-color: #6a6c72; }
  .button.primary { background: #d9dadf; color: var(--dark-ink); border-color: #ededee; font-weight: 700; }
  .button.primary:hover { background: #f0f0f2; }
  .button.primary:disabled { background: #3a3b3f; border-color: #4a4b50; color: #a1a3aa; }
  .button.secondary { background: transparent; color: #c7c8cd; border-color: #45464b; }
  .button.secondary:hover { background: var(--raised); color: white; }
  .notice {
    padding: .75rem .9rem; border: 1px solid #494b50; border-radius: 8px;
    background: #27282b; color: #d5d6de; font-size: .9rem;
  }
  .notice.error { color: var(--red); background: #331e22; border-color: #754448; }
  .facts { display: flex; gap: 1.5rem; flex-wrap: wrap; padding: .95rem; background: #191a1c; border: 1px solid var(--line); border-radius: 9px; }
  .facts > div { min-width: 0; }
  .facts dt { color: var(--muted); font-size: .84rem; margin-bottom: .12rem; }
  .facts dd { margin: 0; overflow-wrap: anywhere; }
}

@layer shop {
  .store { width: min(100% - 2rem, 760px); margin: 0 auto; padding: clamp(2.2rem, 7vh, 5rem) 0 2rem; }
  .store-head { display: flex; justify-content: center; margin-bottom: 1.7rem; }
  .brand {
    display: inline-flex; align-items: center; gap: .7rem; color: var(--text); width: fit-content;
    text-decoration: none; font-size: 1.35rem; font-weight: 710; letter-spacing: -.042em;
  }
  .brand-mark {
    display: grid; place-items: center; width: 39px; height: 39px; border-radius: 10px; overflow: hidden;
    background: linear-gradient(150deg, #484a4e, #292a2d); border: 1px solid #65676c; color: #f1f2f4;
    font-family: ui-monospace, Consolas, monospace; font-size: .86rem; letter-spacing: -.09em;
  }
  .brand-mark svg { width: 26px; height: 26px; }
  .brand-mark img { width: 100%; height: 100%; object-fit: contain; }
  .panel {
    border: 1px solid #43454b; border-radius: 17px; background: var(--surface); overflow: hidden;
    box-shadow: 0 28px 88px #0008, inset 0 1px #ffffff0b;
  }
  .panel:focus { outline: none; }
  .panel-body { padding: clamp(1.15rem, 4vw, 2rem); }
  .panel-heading { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.4rem; }
  .panel-heading p { margin-top: .25rem; }
  .heading-icon, .app-icon { display: grid; place-items: center; flex: 0 0 auto; color: #dedfe4; }
  .heading-icon {
    width: 52px; height: 52px; border-radius: 12px; border: 1px solid #515359;
    background: linear-gradient(150deg, #393a3e, #2a2b2e);
  }
  .heading-icon svg { width: 27px; height: 27px; }
  .heading-icon.success { color: var(--green); background: #253a30; border-color: #436552; }
  .app-icon {
    width: 44px; height: 44px; border-radius: 10px; border: 1px solid #494b50; overflow: hidden;
    background: linear-gradient(150deg, #414247, #303135);
  }
  .app-icon img { width: 100%; height: 100%; object-fit: contain; }
  .product-list { display: grid; gap: .6rem; }
  .panel-body > .notice + .product-list { margin-top: .65rem; }
  .product-row {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: .8rem; align-items: center;
    padding: .74rem; border: 1px solid var(--line); border-radius: var(--radius); background: #26272a;
  }
  .product-title h2 { overflow-wrap: anywhere; font-size: 1rem; }
  .product-title p { color: var(--muted); font-size: .83rem; margin-top: .12rem; }
  .product-row .price { font-size: .95rem; white-space: nowrap; }
  .row-actions { display: flex; gap: .4rem; }
  .promo-price { display: grid; grid-template-columns: auto; justify-items: end; align-items: baseline; gap: .1rem; }
  .promo-price del { color: var(--muted); font-size: .75rem; }
  .promo-tag { border-radius: 4px; background: #3c3e43; color: var(--text); font-size: .7rem; padding: .05rem .35rem; }
  .detail-purchase .promo-price { justify-items: start; }
  .choice { min-width: 110px; }
  .choice.chosen { background: #c9cbd1; border-color: #e2e3e8; color: var(--dark-ink); }
  .choice.chosen:hover { background: #e0e1e6; }
  .panel-checkout { display: grid; gap: 1rem; border-top: 1px solid var(--line); background: #1c1d1f; padding: 1.22rem clamp(1.15rem, 4vw, 2rem); }
  .total-line p, .checkout-hint { font-size: .85rem; }
  .total-line strong { font-size: 1.7rem; font-weight: 670; letter-spacing: -.045em; }
  .checkout-hint { display: flex; align-items: flex-start; gap: .55rem; color: var(--muted); }
  .checkout-hint svg { width: 17px; height: 17px; margin-top: .15rem; }
  .checkout-check { font-size: .88rem; }
  .pay { width: 100%; min-height: 47px; display: grid; grid-template-columns: 1fr auto 1fr; padding: .6rem 1rem; }
  .pay svg { justify-self: end; }
  .pay svg:first-child { justify-self: start; }
  .payment-note { color: var(--muted); text-align: center; font-size: .8rem; margin: -.45rem 0 0; }
  .store-foot { display: grid; gap: .75rem; justify-items: center; padding: 1.22rem 0 0; }
  .legal, .support { display: flex; justify-content: center; flex-wrap: wrap; gap: .45rem 1.35rem; }
  .store-foot a { font-size: .85rem; color: var(--muted); text-decoration: none; }
  .store-foot a:hover { color: var(--text); text-decoration: underline; }
  .support a { display: inline-flex; gap: .45rem; align-items: center; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 7px; }
  .support svg { width: 16px; height: 16px; }
  .detail { display: grid; gap: 1rem; animation: appear .16s ease-out; }
  .detail > .button:not(.pay) { justify-self: start; }
  .detail .panel-heading { margin: 0; }
  .back { width: max-content; background: transparent; border-color: transparent; color: var(--muted); padding-left: 0; }
  .back:hover { background: transparent; border-color: transparent; color: var(--text); }
  .detail-purchase { border-top: 1px solid var(--line); padding-top: 1rem; }
  .detail-purchase strong { font-size: 1.35rem; }
  .screenshots { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 195px), 1fr)); gap: .6rem; }
  .screenshots img { width: 100%; border: 1px solid var(--line); border-radius: 8px; }
  .prose { white-space: pre-wrap; overflow-wrap: anywhere; color: #dadbe1; }
  .download-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .recovery-code { padding: .72rem; background: #161719; border: 1px solid var(--line); border-radius: 8px; font: .98rem ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
  .store-compact { max-width: 470px; display: grid; gap: 1.3rem; }
  .store-compact .panel { display: grid; gap: 1.25rem; }
  @keyframes appear { from { opacity: .65; transform: translateY(3px); } }
}

@layer admin {
  .admin-shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; background: #17181a; }
  .sidebar {
    display: flex; flex-direction: column; position: sticky; top: 0; min-height: 100vh; height: fit-content;
    gap: 1.5rem; padding: 1.2rem 1rem; border-right: 1px solid var(--line); background: #202123;
  }
  .sidebar nav, .side-bottom { display: grid; gap: .3rem; }
  .sidebar nav a, .side-bottom > a { text-decoration: none; padding: .52rem .7rem; border-radius: 7px; color: var(--muted); }
  .sidebar nav a:hover, .sidebar nav a[aria-current] { background: #383a3e; color: var(--text); }
  .side-bottom { margin-top: auto; }
  .side-bottom form { padding-left: .7rem; }
  .admin-content { padding: clamp(1rem, 3vw, 2rem); width: min(100%, 1380px); display: grid; gap: 1rem; align-content: start; }
  .delete-product { border-top: 1px solid var(--line); padding-top: .8rem; }
  .delete-product summary { list-style: none; }
  .delete-product summary::-webkit-details-marker { display: none; }
  .delete-product form { margin-top: .8rem; }
  .button.danger { color: var(--red); border-color: #754448; }
  .button.danger:hover { background: #40292c; }
  .admin-heading { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; justify-content: space-between; }
  .filters { display: flex; gap: .5rem; flex-wrap: wrap; }
  .filters > input, .filters > select { width: auto; max-width: 100%; }
  .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: .65rem; }
  .admin-card {
    min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1rem; display: grid; gap: .8rem;
  }
  .metric { gap: .35rem; }
  .metric span { font-size: .85rem; color: var(--muted); }
  .metric strong { font-size: 1.52rem; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
  .table-scroll { overflow-x: auto; }
  table { width: 100%; text-align: left; border-collapse: collapse; font-size: .9rem; white-space: nowrap; }
  th { font-weight: 550; color: var(--muted); background: #1b1c1e; }
  th, td { padding: .63rem; border-bottom: 1px solid var(--line); }
  .order-link { font-family: ui-monospace, Consolas, monospace; }
  .status { padding: .18rem .45rem; border: 1px solid #505157; border-radius: 5px; }
  .status-paid { color: var(--green); border-color: #436552; }
  .status-failed { color: var(--red); border-color: #754448; }
  .detail-line { padding: .55rem 0; border-bottom: 1px solid var(--line); }
  .promo-editor { margin: 0; padding: .8rem; }
  .promo-editor > p { margin-top: .45rem; }
  .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  fieldset { display: grid; gap: .4rem; border: 1px solid var(--line); border-radius: 8px; }
}

@layer responsive {
  @media (max-width: 700px) {
    .admin-shell { display: block; }
    .sidebar { position: static; min-height: 0; border: 0; border-bottom: 1px solid var(--line); gap: .65rem; }
    .sidebar nav, .side-bottom { display: flex; flex-wrap: wrap; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .filters { width: 100%; }
  }
  @media (max-width: 550px) {
    .store { width: calc(100% - 1rem); }
    .product-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: .6rem; }
    .row-actions { grid-column: 2 / -1; }
    .row-actions > button { flex: 1; }
    .download-row { grid-template-columns: auto minmax(0, 1fr); }
    .download-row > .button { grid-column: 2; }
    .facts { gap: .8rem 1rem; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
  }
}
