@property --tint {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 0%;
}

@layer tokens {
  :root {
    --tone-red: #d4431b;
    --tone-green: #2f8c3d;
    --tone-orange: #f07c12;
    --tone-grey: #8f9398;
    --drum-steel: #17191c;
    --pill-dark: #0b0c0e;
    --card-shadow: 0 18px 40px rgb(0 0 0 / 0.35);
    --panel-shadow: 0 30px 80px rgb(0 0 0 / 0.35);
    --slot-inline: 104px;
    --slot-block: 168px;
  }
}

@layer base {
  .sprite {
    position: absolute;
    inline-size: 0;
    block-size: 0;
    overflow: hidden;
  }
}

@layer layout {
  .dashboard {
    --sidebar-inline: 380px;
    --sidebar-rail: 64px;
    display: grid;
    gap: var(--space-m);
    max-inline-size: 1560px;
    margin-inline: auto;
    padding: var(--space-2xl) var(--space-m);

    & > main {
      min-inline-size: 0;
    }

    @media (width >= 1100px) {
      grid-template-columns: minmax(0, 1fr) var(--sidebar-inline);
      align-items: start;
      transition: grid-template-columns 0.4s var(--ease-out);

      &:has(.collapse:checked) {
        --sidebar-inline: var(--sidebar-rail);
      }
    }
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-s);
    margin: 0;
    padding: 0;
    list-style: none;
  }
}

@layer components {
  .containers {
    padding: var(--space-xl);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-l);
    background: var(--color-panel);
    backdrop-filter: blur(28px) saturate(1.4);
    box-shadow: var(--panel-shadow), inset 0 1px 0 var(--color-sheen);

    @media (width < 600px) {
      padding: var(--space-l) var(--space-m);
    }

    & > header {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-m);
    }

    & :where(h2) {
      display: flex;
      align-items: center;
      gap: var(--space-s);
      font-size: var(--text-xl);
      font-weight: 500;

      & svg {
        inline-size: 24px;
        block-size: 24px;
        color: var(--color-muted);
      }
    }

    & :where(.actions) {
      display: flex;
      align-items: center;
      gap: var(--space-xs);

      & svg {
        inline-size: 22px;
        block-size: 22px;
        color: var(--color-accent);
      }
    }

    & :where(.link) {
      display: inline-flex;
      align-items: center;
      gap: var(--space-xs);
      padding: 6px var(--space-xs);
      border: 0;
      border-radius: var(--radius-full);
      background: none;
    }

    & :where(.icon) {
      display: grid;
      place-items: center;
      inline-size: 40px;
      block-size: 40px;
      border: 0;
      border-radius: 50%;
      background: none;
    }
  }

  .tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
    margin-block: var(--space-l);

    & button {
      padding: var(--space-xs) 18px;
      border: 0;
      border-radius: var(--radius-full);
      background: none;

      &[aria-pressed="true"] {
        background: #fff;
        color: #111;
      }
    }

    & span {
      margin-inline-start: var(--space-2xs);
      font-size: var(--text-s);
      color: var(--color-muted);
    }
  }

  .card {
    --tone: transparent;
    --tint: 34%;
    display: grid;
    justify-items: center;
    padding: var(--space-m) var(--space-m) 20px;
    border-radius: var(--radius-m);
    text-align: center;
    background:
      linear-gradient(to top, color-mix(in oklab, var(--tone) var(--tint), transparent), transparent 80%),
      var(--color-card);
    box-shadow: inset 0 0 0 1px var(--color-line);
    transition:
      --tint var(--duration-m) var(--ease-out),
      translate var(--duration-m) var(--ease-out),
      box-shadow var(--duration-m) var(--ease-out);

    &[data-tone="red"] {
      --tone: var(--tone-red);
    }

    &[data-tone="green"] {
      --tone: var(--tone-green);
    }

    &[data-tone="orange"] {
      --tone: var(--tone-orange);
    }

    &[data-tone="grey"] {
      --tone: var(--tone-grey);
      --tint: 12%;
    }

    &:is(:hover, :focus-within) {
      --tint: 64%;
      box-shadow: var(--card-shadow), inset 0 0 0 1px var(--color-sheen), inset 0 1px 0 var(--color-line);

      @media (prefers-reduced-motion: no-preference) {
        translate: 0 -4px;
      }
    }

    & > header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      justify-self: stretch;
      gap: var(--space-xs);
    }

    & :where(h3) {
      margin: 0;
      font-size: var(--text-l);
      font-weight: 500;
      letter-spacing: -0.01em;
    }

    & :where(.more) {
      display: grid;
      flex: none;
      place-items: center;
      inline-size: 34px;
      block-size: 34px;
      border: 0;
      border-radius: 50%;
      background: rgb(255 255 255 / 0.08);

      & svg {
        inline-size: 18px;
        block-size: 18px;
      }
    }

    & :where(.desc) {
      margin-block: 18px var(--space-2xs);
      font-size: 0.9rem;
      text-wrap: balance;
    }

    & :where(.date) {
      font-size: var(--text-s);
      color: var(--color-muted);
    }
  }

  .slot {
    position: relative;
    isolation: isolate;
    inline-size: var(--slot-inline);
    block-size: var(--slot-block);
    margin-block-start: 22px;

    &::before {
      content: "";
      position: absolute;
      inset: 4% 8% 0;
      border-radius: 14% / 7%;
      background: linear-gradient(to top, var(--tone) calc(var(--pct) * 1%), var(--drum-steel) 0);
    }

    :root[data-drums="ready"] &::before {
      display: none;
    }

    &::after {
      content: "";
      position: absolute;
      inset-inline: 4%;
      inset-block-end: -8px;
      z-index: -1;
      block-size: 16px;
      border-radius: 50%;
      background: radial-gradient(closest-side, rgb(0 0 0 / 0.6), transparent);
    }

    & :where(.drum) {
      position: absolute;
      inset: 0;
      inline-size: 100%;
      block-size: 100%;
    }

    & :where(.badge) {
      position: absolute;
      inset-block-start: 22%;
      inset-inline-start: 50%;
      z-index: 1;
      display: grid;
      place-items: center;
      inline-size: 22px;
      block-size: 22px;
      translate: -50% -50%;
      border-radius: 50%;
      background: #fff;
      color: #111;
      font-size: 0.75rem;
      font-weight: 700;
    }

    & :where(.pill) {
      position: absolute;
      inset-block-end: var(--pill-at, 12%);
      inset-inline-start: 50%;
      z-index: 1;
      padding: 2px var(--space-xs);
      translate: -50% 50%;
      border-radius: var(--radius-full);
      background: var(--pill-dark);
      color: #fff;
      font-size: 0.68rem;
      font-weight: 700;
      letter-spacing: 0.02em;
      white-space: nowrap;

      &[data-kind="level"] {
        --pill-at: calc(var(--pct) * 0.84% + 4%);
        background: #fff;
        color: #111;
        font-size: 0.75rem;
        letter-spacing: 0;
        font-variant-numeric: tabular-nums;
      }
    }
  }
}
