/* ─── Custom properties ─────────────────────────────────────────────────── */

:root {
  --bg: #f5f5f5;
  --text-primary: #0f0f0f;
  --text-secondary: #5e5e5e;
  --text-tertiary: #9e9e9e;
  --border: #dedede;
  --border-hover: #c8c8c8;
  --surface: #ebebeb;
  --surface-hover: #e2e2e2;
  --accent: #d42b2b;

  --btn-primary-bg: #0f0f0f;
  --btn-primary-text: #f5f5f5;
  --btn-primary-hover: #2a2a2a;

  --success-bg: #f0fdf4;
  --success-text: #16a34a;
  --success-border: #22c55e;

  --font-body: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --max-width: 500px;
  --padding: 1.5rem;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 200ms var(--ease);

  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #09090b;
      --text-primary: #f0f0f0;
      --text-secondary: #828282;
      --text-tertiary: #4c4c4c;
      --border: #1e1e22;
      --border-hover: #2e2e34;
      --surface: #131316;
      --surface-hover: #1c1c20;
      --accent: #f05454;

      --btn-primary-bg: #f0f0f0;
      --btn-primary-text: #09090b;
      --btn-primary-hover: #d8d8d8;

      --success-bg: rgba(34, 197, 94, 0.1);
      --success-text: #4ade80;
      --success-border: rgba(34, 197, 94, 0.2);
    }
  }

}

html[data-theme="light"] {
  --bg: #f5f5f5;
  --text-primary: #0f0f0f;
  --text-secondary: #5e5e5e;
  --text-tertiary: #9e9e9e;
  --border: #dedede;
  --border-hover: #c8c8c8;
  --surface: #ebebeb;
  --surface-hover: #e2e2e2;
  --accent: #d42b2b;

  --btn-primary-bg: #0f0f0f;
  --btn-primary-text: #f5f5f5;
  --btn-primary-hover: #2a2a2a;

  --success-bg: #f0fdf4;
  --success-text: #16a34a;
  --success-border: #22c55e;
}

html[data-theme="dark"] {
  --bg: #09090b;
  --text-primary: #f0f0f0;
  --text-secondary: #828282;
  --text-tertiary: #4c4c4c;
  --border: #1e1e22;
  --border-hover: #2e2e34;
  --surface: #131316;
  --surface-hover: #1c1c20;
  --accent: #f05454;

  --btn-primary-bg: #f0f0f0;
  --btn-primary-text: #09090b;
  --btn-primary-hover: #d8d8d8;

  --success-bg: rgba(34, 197, 94, 0.1);
  --success-text: #4ade80;
  --success-border: rgba(34, 197, 94, 0.2);
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  html { color-scheme: dark; }
}

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

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

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ─── Layout ────────────────────────────────────────────────────────────── */

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--padding) 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ────────────────────────────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: 4rem;
  padding-bottom: 1.5rem;

  margin-left: calc(-1 * var(--padding));
  margin-right: calc(-1 * var(--padding));
  padding-left: var(--padding);
  padding-right: var(--padding);

  background-color: var(--bg);
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
  opacity: 0;
  transition: opacity var(--transition);
}

.header.scrolled::after {
  opacity: 1;
}

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

.header-title {
  font-size: 1.625rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--text-primary);
}

.theme-icon {
  display: none;
  flex-shrink: 0;
}

/* Smooth theme crossfade via View Transitions API */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* Old view stays underneath */
::view-transition-old(root) {
  z-index: 1;
}

/* New view expands over the top */
::view-transition-new(root) {
  z-index: 2;
}

/* Auto mode: follow system preference */
@media (prefers-color-scheme: light) {
  html:not([data-theme]) .icon-light { display: block; }
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .icon-dark { display: block; }
}

/* Manual overrides */
html[data-theme="light"] .icon-light,
html[data-theme="dark"] .icon-dark {
  display: block;
}

/* ─── Name animation ────────────────────────────────────────────────────── */

.greeting,
.name-wrapper {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.25em;
  letter-spacing: 0;
}

.name-wrapper {
  display: inline-flex;
  align-items: baseline;
  position: relative;
  cursor: pointer;
  transform: translateZ(0);
  isolation: isolate;
}

.name-anim {
  display: inline-grid;
  vertical-align: bottom;
  transition: grid-template-columns 0.6s cubic-bezier(0.25, 1, 0.5, 1),
              opacity 0.5s ease;
  will-change: grid-template-columns, opacity;
}

.name-anim .inner {
  overflow: hidden;
  white-space: pre;
  min-width: 0;
}

.name-main {
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
  transition: text-decoration-color 0.5s ease;
}

/* Collapsed state */
.name-alias {
  grid-template-columns: 0fr;
  opacity: 0;
}

.name-sur {
  opacity: 0.55;
  transition: opacity 0.5s ease;
}

/* Expanded state */
.name-wrapper.expanded .name-anim {
  transition-delay: 0s;
}

.name-wrapper.expanded .name-alias {
  grid-template-columns: 1fr;
  opacity: 1;
}

.name-wrapper.expanded .name-sur {
  opacity: 1;
}

.name-wrapper.expanded .name-main {
  text-decoration-color: var(--text-tertiary);
  transition-delay: 0s;
}

/* ─── Sparkles ──────────────────────────────────────────────────────────── */

.sparkle {
  position: absolute;
  pointer-events: none;
  color: #fbbf24;
  line-height: 1;
  opacity: 0;
  z-index: 1;
}

/* ─── Bio ───────────────────────────────────────────────────────────────── */

.bio {
  margin-bottom: 1.5rem;
}

.bio p {
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.bio p:last-child {
  margin-bottom: 0;
}

.bio strong {
  font-weight: 600;
}

.bio .highlight {
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.bio .highlight.typing {
  display: inline-block;
  min-width: 2px;
}

.hide-cursor-global,
.hide-cursor-global * {
  cursor: none !important;
}

/* Visually disable hover effects during animation to prevent distracting highlights when text shifts */
.hide-cursor-global .inline-link:hover,
.hide-cursor-global .handle-copy:hover {
  text-decoration-color: var(--border);
  color: inherit;
}

/* Cursor always exists to prevent layout shifts, but sits invisible */
.bio .highlight::after {
  content: '';
  display: inline-block;
  width: 1.5px;
  height: 0.85em;
  background: var(--accent);
  margin-left: 1px;
  margin-right: -2.5px; /* Negates width + margin-left so it takes 0 layout space */
  vertical-align: baseline;
  opacity: 0;
  transform-origin: left center;
  transition: opacity 250ms ease; /* Smooth fade for both blinking and final exit */
}

.bio .highlight.cursor-on::after {
  opacity: 1;
}

.bio .underline-word {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  text-decoration-color: var(--text-primary);
}

.bio .icon-inline {
  font-size: 0.9em;
}

.inline-link {
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  transition: text-decoration-color var(--transition);
}

.inline-link:hover {
  text-decoration-color: var(--text-primary);
}

.handle-copy {
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  transition: text-decoration-color var(--transition), color var(--transition);
  cursor: pointer;
  position: relative;
}

.handle-copy:hover {
  text-decoration-color: var(--text-primary);
}

.handle-copy.copied {
  color: #16a34a;
  text-decoration-color: #86efac;
}

/* ─── Divider ───────────────────────────────────────────────────────────── */

.divider {
  border: none;
  height: 1px;
  background: var(--border);
  margin-bottom: 2.5rem;
}

/* ─── Links ─────────────────────────────────────────────────────────────── */

.links {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.link-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.link-list {
  display: flex;
  flex-direction: column;
}

.link-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  transition: all var(--transition);
  color: var(--text-primary);
}

.link-item:last-child {
  border-bottom: none;
}

.link-item svg:first-child {
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.link-item span {
  flex: 1;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.link-item .arrow {
  flex-shrink: 0;
  color: var(--text-tertiary);
  opacity: 0;
  transform: translate(-4px, 4px);
  transition: all var(--transition);
}

.link-item:hover {
  padding-left: 0.25rem;
}

.link-item:hover svg:first-child {
  color: var(--text-primary);
}

.link-item:hover .arrow {
  opacity: 1;
  transform: translate(0, 0);
}

/* ─── Actions & buttons ─────────────────────────────────────────────────── */

.actions {
  display: flex;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6875rem 1.25rem;
  border-radius: 100px;
  font-size: 0.9375rem;
  font-weight: 550;
  letter-spacing: -0.01em;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn svg {
  flex-shrink: 0;
}

.btn.btn-expandable {
  gap: 0;
  padding: 0;
  max-width: 44px;
  height: 44px;
  border-radius: 22px;
  overflow: hidden;
  transition: max-width 400ms var(--ease), background var(--transition),
              border-color var(--transition), color var(--transition);
}

.btn-expandable .btn-icon {
  width: 41px;
  height: 41px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-expandable .btn-icon svg {
  color: var(--text-secondary);
  transition: color var(--transition);
}

.btn-expandable .btn-text {
  opacity: 0;
  padding-right: 0;
  transition: opacity 400ms var(--ease), padding-right 400ms var(--ease);
}

@media (hover: hover) {
  .btn.btn-expandable:hover {
    max-width: 300px;
  }

  .btn.btn-expandable:hover .btn-text {
    opacity: 1;
    padding-right: 1.25rem;
  }

  .btn.btn-expandable:hover .btn-icon svg {
    color: var(--text-primary);
  }
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-primary);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--surface);
}

.btn-secondary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary.copied,
.btn-secondary.copied:hover {
  border-color: var(--success-border);
  color: var(--success-text);
  background: var(--success-bg);
}

.btn-secondary.copied .btn-icon svg,
.btn.btn-expandable.btn-secondary.copied:hover .btn-icon svg {
  color: var(--success-text);
}

/* Keep expandable button fully open while copied — collapse only after state clears */
.btn.btn-expandable.copied {
  max-width: 300px;
  transition: max-width 600ms var(--ease), background var(--transition),
              border-color var(--transition), color var(--transition);
}

.btn.btn-expandable.copied .btn-text {
  opacity: 1;
  padding-right: 1.25rem;
}

.btn.btn-expandable.copied .btn-icon svg {
  color: var(--success-text);
}

/* Force collapse — !important beats :hover so no expanded flash is possible.
   .copied stays on during collapse so green colour persists until icon width
   is reached, then both classes are removed together. */
.btn.btn-expandable.collapsing {
  max-width: 44px !important;
  transition: max-width 500ms var(--ease), background var(--transition),
              border-color var(--transition), color var(--transition);
}

/* ─── Footer ────────────────────────────────────────────────────────────── */

.footer {
  margin-top: auto;
  padding-top: 1rem;
}

.footer p {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

/* ─── Animations ────────────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* Delays match DOM order: header → bio → divider → links → actions → footer */
.header-row {
  animation: fadeIn 500ms ease-out both;
  animation-delay: 50ms;
}

.bio {
  animation: fadeIn 500ms ease-out both;
  animation-delay: 150ms;
}

.divider {
  animation: fadeIn 400ms ease-out both;
  animation-delay: 230ms;
}

.link-group:nth-child(1) {
  animation: fadeIn 500ms ease-out both;
  animation-delay: 310ms;
}

.link-group:nth-child(2) {
  animation: fadeIn 500ms ease-out both;
  animation-delay: 390ms;
}

.actions {
  animation: fadeIn 500ms ease-out both;
  animation-delay: 470ms;
}

.footer {
  animation: fadeIn 400ms ease-out both;
  animation-delay: 550ms;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  :root {
    --padding: 1.25rem;
  }

  .header {
    padding-top: 3rem;
  }

  .header-title {
    font-size: 1.375rem;
  }

  .bio p {
    font-size: 1rem;
  }

  .btn {
    padding: 0.625rem 1.125rem;
    font-size: 0.875rem;
  }
}

@media (max-width: 360px) {
  .header-title {
    font-size: 1.25rem;
  }

  .actions {
    flex-direction: column;
  }

  .btn {
    justify-content: center;
  }
}

/* ─── Accessibility ─────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.link-item:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (hover: none) {
  .link-item:hover {
    padding-left: 0;
  }

  .link-item .arrow {
    opacity: 0.4;
    transform: translate(0, 0);
  }

  .btn-primary:hover,
  .btn-secondary:hover {
    transform: none;
    box-shadow: none;
  }

  .btn:active {
    transform: scale(0.97);
  }

  .link-item:active {
    opacity: 0.7;
  }
}
