@layer base, theme, layout, components;

@layer theme {
  :root {
    color-scheme: light dark;

    /* Palette tokens */
    --ink: #102536;
    --ink-muted: #39556b;
    --surface-sky: #e6f1f6;
    --surface-pill: rgba(255, 253, 248, 0.78);
    --surface-pill-hover: rgba(255, 253, 248, 0.96);
    --border-pill: rgba(16, 37, 54, 0.14);
    --shadow-pill: 0 6px 20px rgba(16, 37, 54, 0.12), 0 1px 2px rgba(16, 37, 54, 0.08);
    --accent: #df472d;
    --accent-hover: #c93921;
    --accent-ink: #fffdf8;
    --focus-ring: #df472d;

    --font-display: ui-rounded, 'SF Pro Rounded', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --ink: #f3f7fa;
      --ink-muted: #a6c1d4;
      --surface-sky: #0b1929;
      --surface-pill: rgba(15, 34, 54, 0.76);
      --surface-pill-hover: rgba(22, 48, 74, 0.92);
      --border-pill: rgba(214, 234, 248, 0.18);
      --shadow-pill: 0 8px 24px rgba(2, 8, 16, 0.42), 0 1px 2px rgba(2, 8, 16, 0.3);
      --accent: #f05d40;
      --accent-hover: #ff7054;
      --accent-ink: #0c1724;
      --focus-ring: #ff8a6b;
    }
  }
}

@layer base {
  html,
  body {
    margin: 0;
    padding: 0;
    block-size: 100%;
    background-color: var(--surface-sky);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  h1,
  p {
    margin: 0;
  }

  button {
    font: inherit;
    color: inherit;
  }
}

@layer layout {
  .stage {
    position: relative;
    inline-size: 100%;
    block-size: 100dvh;
    min-block-size: 460px;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    padding-block: clamp(1.25rem, 4vh, 2.75rem);
    padding-inline: clamp(1.25rem, 4vw, 3rem);
    box-sizing: border-box;
    isolation: isolate;
  }

  .harbor-canvas {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    display: block;
    z-index: 0;
    cursor: pointer;
    touch-action: manipulation;
  }
}

@layer components {
  .hero {
    position: relative;
    z-index: 1;
    justify-self: center;
    text-align: center;
    pointer-events: none;
    user-select: none;
    display: grid;
    justify-items: center;
    gap: 0.45rem;
    padding-block-start: clamp(0.5rem, 3.5vh, 2.25rem);
  }

  .hero h1 {
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 7vw, 4.75rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1;
    color: var(--ink);
  }

  .tagline {
    font-size: clamp(0.95rem, 2.2vw, 1.15rem);
    font-weight: 500;
    color: var(--ink-muted);
    max-inline-size: 32ch;
  }

  .controls {
    position: relative;
    z-index: 1;
    grid-row: 3;
    justify-self: end;
    align-self: end;
    display: flex;
    align-items: center;
    gap: 0.6rem;

    @media (max-width: 520px) {
      justify-self: center;
    }
  }

  .control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-block-size: 2.5rem;
    min-inline-size: 2.5rem;
    padding-block: 0.45rem;
    padding-inline: 0.95rem;
    border-radius: 999px;
    border: 1px solid var(--border-pill);
    background: var(--surface-pill);
    color: var(--ink);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    box-shadow: var(--shadow-pill);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;

    /* Identity transforms to keep stacking context stable */
    translate: 0 0;
    scale: 1;
    transition:
      background-color 150ms ease,
      border-color 150ms ease,
      translate 140ms cubic-bezier(0.22, 1, 0.36, 1),
      scale 120ms cubic-bezier(0.22, 1, 0.36, 1);

    @media (pointer: coarse) {
      min-block-size: 2.75rem;
      padding-inline: 1.1rem;
    }

    &:hover:not(:disabled) {
      background: var(--surface-pill-hover);
      translate: 0 -1px;
    }

    &:active:not(:disabled) {
      translate: 0 0;
      scale: 0.96;
    }

    &:focus-visible {
      outline: 3px solid var(--focus-ring);
      outline-offset: 3px;
    }
  }

  .control-btn-accent {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: transparent;

    &:hover:not(:disabled) {
      background: var(--accent-hover);
    }
  }

  .btn-icon {
    flex-shrink: 0;
  }

  .control-btn .icon-play {
    display: none;
  }

  .control-btn[data-paused="true"] .icon-pause {
    display: none;
  }

  .control-btn[data-paused="true"] .icon-play {
    display: block;
  }

  @media (forced-colors: active) {
    .control-btn {
      border: 1px solid ButtonText;
      backdrop-filter: none;
    }

    .control-btn:focus-visible {
      outline: 3px solid Highlight;
    }
  }
}
