/* SPDX-License-Identifier: MIT | Copyright (c) 2026 Gunawan Wijaya */

@layer reset, tokens, layout, components, og;

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

  html {
    scroll-behavior: smooth;
  }
}

@layer tokens {
  :root {
    color-scheme: light dark;
    --bg: light-dark(#f8fafc, #0c0f14);
    --surface: light-dark(#ffffff, #141922);
    --surface-alt: light-dark(#f1f5f9, #1b2230);
    --text: light-dark(#0f172a, #e6ebf2);
    --muted: light-dark(#475569, #9aa6b8);
    --accent: light-dark(#1f3a5f, #60a5fa);
    --accent-soft: light-dark(#e8eef6, rgba(96, 165, 250, 0.14));
    --accent-fg: light-dark(#ffffff, #0c0f14);
    --border: light-dark(#e2e8f0, #252e3d);
    --shadow: light-dark(0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(0, 0, 0, 0.35));
    --avatar-bg: light-dark(#f0f2f5, #141922);
    --avatar-fg: light-dark(#d34f4f, #f06565);
    --og-zoom: 1;
  }

  html[data-theme="light"] { color-scheme: light; }
  html[data-theme="dark"] { color-scheme: dark; }
}

@layer layout {
  html {
    background-color: var(--bg);
  }

  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  .container {
    max-width: 860px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3.5rem;
  }

  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
  }

  header {
    margin-bottom: 2.5rem;
  }

  section {
    margin-top: 2.75rem;
  }

  .grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;

    & .card {
      margin-bottom: 0;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }
  }

  footer {
    margin-top: 3.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: var(--muted);
  }

  @media (min-width: 680px) {
    .container { padding: 2.25rem 2rem 4rem; }
    .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
}

@layer components {
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    letter-spacing: 0.01em;

    & span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .brand-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex-shrink: 0;

    & .bg { fill: var(--avatar-bg); }
    & .fg { fill: var(--avatar-fg); }
  }

  theme-switch {
    display: inline-flex;
    flex-shrink: 0;
    margin-left: auto;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;

    & button {
      appearance: none;
      border: none;
      background: transparent;
      color: var(--muted);
      font: 500 0.8rem/1 inherit;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0.35rem;
      padding: 0.42rem 0.65rem;
      border-radius: 6px;
      cursor: pointer;

      &:hover { color: var(--text); }
      &[aria-pressed="true"] {
        background: var(--surface);
        color: var(--text);
        box-shadow: var(--shadow);
        font-weight: 600;
      }
    }

    & .theme-icon {
      width: 14px;
      height: 14px;
      flex-shrink: 0;
    }

    @media (max-width: 480px) {
      & .theme-label {
        display: none;
      }

      & button {
        padding: 0.45rem;
      }
    }
  }

  h1 {
    font-size: clamp(1.85rem, 4.5vw, 2.5rem);
    line-height: 1.15;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
  }

  h2 {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 1rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--border);
  }

  h3 {
    font-size: 1.05rem;
    line-height: 1.35;
    margin-bottom: 0.25rem;
  }

  .headline {
    font-size: clamp(1rem, 2.3vw, 1.15rem);
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.4rem;
  }

  .location {
    font-size: 0.92rem;
    color: var(--muted);
    margin-bottom: 1.1rem;
  }

  .summary {
    font-size: 1rem;
    color: var(--text);
    max-width: 72ch;
    margin-bottom: 1.4rem;
  }

  .og-only {
    display: none;
  }

  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;

    @media (max-width: 480px) {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      & .btn.primary { grid-column: 1 / -1; }
    }
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 40px;
    padding: 0.5rem 0.75rem;
    text-align: center;
    line-height: 1.25;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow);

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

    &.primary {
      background: var(--accent);
      border-color: var(--accent);
      color: var(--accent-fg);
      font-weight: 600;

      &:hover {
        opacity: 0.92;
        color: var(--accent-fg);
      }
    }
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.2rem 1.3rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);

    & p {
      color: var(--muted);
      font-size: 0.95rem;
      margin-bottom: 0.6rem;
      &:last-child { margin-bottom: 0; }
    }
  }

  .card-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.35rem 1rem;
    margin-bottom: 0.45rem;
  }

  .meta {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
    margin-bottom: 0.45rem;
  }

  .period {
    font-size: 0.84rem;
    color: var(--muted);
  }

  ul {
    padding-left: 1.15rem;
    color: var(--muted);
    font-size: 0.94rem;
  }

  li {
    margin-bottom: 0.4rem;
    &:last-child { margin-bottom: 0; }
    & strong { color: var(--text); font-weight: 600; }
  }

  code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.86em;
    background: var(--surface-alt);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    color: var(--text);
  }

  .skill-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow);
  }

  .skill-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.35rem;
  }

  .skill-list {
    font-size: 0.9rem;
    color: var(--muted);
  }

  a.inline {
    color: var(--accent);
    text-decoration: none;
    overflow-wrap: anywhere;
    &:hover { text-decoration: underline; }
  }

  .tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
  }

  .tag {
    font-size: 0.76rem;
    font-weight: 500;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 220ms;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  }

  @media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
      animation-duration: 0.01ms;
    }
  }
}

@layer og {
  html[data-og] {
    & body {
      font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      min-height: 100vh;
      display: grid;
      place-items: center;
      background: #06080c;
      padding: 2rem;
    }

    & theme-switch,
    & .actions,
    & .summary,
    & main,
    & footer {
      display: none;
    }

    & .container {
      width: 1200px;
      height: 630px;
      max-width: none;
      margin: 0;
      padding: 56px 72px;
      background:
        radial-gradient(circle at 88% 14%, rgba(96, 165, 250, 0.14), transparent 46%),
        #0c0f14;
      border: 1px solid #252e3d;
      border-radius: 14px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      overflow: hidden;
      font-size: calc(16px * var(--og-zoom));
      transform-origin: center;
    }

    &[data-og-capture] body {
      padding: 0;
      background: #0c0f14;
      overflow: hidden;
    }

    &[data-og-capture] .container {
      border: none;
      border-radius: 0;
    }

    &[data-og-preview="linkedin"] .container {
      transform: scale(0.32);
    }

    & .topbar {
      margin-bottom: 1.8em;
      padding-bottom: 1em;
    }

    & .brand {
      font-size: 1.35em;
      gap: 0.6em;
      color: #cbd5e1;
    }

    & .brand-icon {
      width: 36px;
      height: 36px;
      border-radius: 8px;
    }

    & header {
      margin-bottom: 0;
    }

    & h1 {
      font-size: 4.5em;
      font-weight: 800;
      letter-spacing: -0.035em;
      line-height: 1.06;
      margin-bottom: 0.2em;
    }

    & .headline {
      font-size: 1.95em;
      font-weight: 700;
      line-height: 1.25;
      margin-bottom: 0.45em;
    }

    & .location {
      font-size: 1.25em;
      margin-bottom: 0.9em;
    }

    & .og-only {
      display: block;
    }

    & .og-tagline {
      font-size: 1.4em;
      line-height: 1.4;
      color: #cbd5e1;
      margin-bottom: 1em;
    }

    & .og-pills {
      display: flex;
      flex-wrap: wrap;
      gap: 0.55em;
    }

    & .og-pill {
      font-size: 1.05em;
      font-weight: 600;
      padding: 0.35em 0.8em;
      border-radius: 999px;
      background: rgba(96, 165, 250, 0.14);
      border: 1px solid rgba(96, 165, 250, 0.3);
      color: #93c5fd;
    }
  }

  og-stage {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    background: #141922;
    border: 1px solid #252e3d;
    color: #e6ebf2;
    font-size: 0.85rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    z-index: 10;

    & label {
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }

    & button {
      background: #1b2230;
      color: #e6ebf2;
      border: 1px solid #252e3d;
      border-radius: 6px;
      padding: 5px 10px;
      font: 600 0.8rem/1 inherit;
      cursor: pointer;

      &[aria-pressed="true"] {
        background: #60a5fa;
        color: #0c0f14;
        border-color: #60a5fa;
      }
    }
  }

  html[data-og]:not([data-og-capture]) og-stage {
    display: flex;
  }
}
