:root {
  --bg:          #F7F4EE;
  --bg-alt:      #F0EBE3;
  --surface:     #FFFCF8;
  --surface-alt: #F5F0E8;

  --text-primary:   #1C1714;
  --text-secondary: #6B5F56;
  --text-muted:     #A09488;

  --accent:       #C96442;
  --accent-hover: #B5512E;
  --accent-light: rgba(201, 100, 66, 0.10);
  --accent-glow:  rgba(201, 100, 66, 0.18);

  --border:       #E8E2D8;
  --border-dark:  #D4CEC5;

  --nav-bg: rgba(247, 244, 238, 0.85);

  --shadow-sm:  0 1px 3px rgba(28,23,20,0.07), 0 1px 2px rgba(28,23,20,0.05);
  --shadow-md:  0 4px 12px rgba(28,23,20,0.08), 0 2px 4px rgba(28,23,20,0.05);
  --shadow-lg:  0 16px 40px rgba(28,23,20,0.10), 0 4px 12px rgba(28,23,20,0.06);
  --shadow-card: 0 2px 8px rgba(28,23,20,0.06), 0 1px 2px rgba(28,23,20,0.04);

  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-sans:  'DM Sans', system-ui, sans-serif;

  --nav-h: 64px;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 100px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

:root[data-theme="dark"] {
  --bg:          #14110F;
  --bg-alt:      #1B1714;
  --surface:     #1F1A17;
  --surface-alt: #261F1B;

  --text-primary:   #F4EDE6;
  --text-secondary: #D1C5BB;
  --text-muted:     #A6988D;

  --accent:       #D87956;
  --accent-hover: #C56745;
  --accent-light: rgba(216, 121, 86, 0.18);
  --accent-glow:  rgba(216, 121, 86, 0.28);

  --border:       #2F2823;
  --border-dark:  #3C322C;

  --nav-bg: rgba(20, 17, 15, 0.88);

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.35);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.35);
  --shadow-lg:  0 16px 40px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.35);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  background: var(--nav-bg);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-style: italic;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  transition: opacity 0.2s var(--ease);
}
.nav-logo:hover { opacity: 0.65; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-pill);
  transition: all 0.18s var(--ease);
}
.nav-links a:hover  { color: var(--text-primary); background: var(--bg-alt); }
.nav-links a.active { color: var(--accent); background: var(--accent-light); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: auto;
  height: 38px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 0.7rem;
  transition: all 0.18s var(--ease);
  box-shadow: var(--shadow-sm);
}
.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-dark);
  background: var(--surface-alt);
}
.theme-toggle:active { transform: translateY(1px); }

.theme-caret {
  font-size: 0.6rem;
  opacity: 0.7;
}

.theme-menu {
  position: relative;
}

.theme-dropdown {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  min-width: 160px;
  padding: 0.35rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 10;
}

.theme-menu.is-open .theme-dropdown {
  display: block;
  animation: dropdown-in 0.2s var(--ease) both;
}

.theme-option {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}

.theme-option:hover {
  color: var(--text-primary);
  background: var(--bg-alt);
}

.theme-option.is-active {
  color: var(--text-primary);
  background: var(--accent-light);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.75rem 1.6rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  border: none;
  transition: all 0.22s var(--ease-spring);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(201,100,66,0.35), inset 0 1px 0 rgba(255,255,255,0.12);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(201,100,66,0.38), inset 0 1px 0 rgba(255,255,255,0.12);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--bg-alt);
  border-color: var(--border-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.btn-secondary:active { transform: translateY(0); }

.btn-fm {
  background: var(--text-primary);
  color: var(--bg);
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 0.88rem;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
}
.btn-fm:hover {
  background: #2C2420;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.btn-fm:active { transform: translateY(0); }

body.home {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  align-items: center;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2rem, 4vw, 3.5rem);
  padding: calc(var(--nav-h) + clamp(1.25rem, 3vw, 2rem)) clamp(1.25rem, 3vw, 2rem) clamp(1.25rem, 3vw, 2rem);
}

.hero-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  width: min(100%, 1000px);
  padding: 0 clamp(0.75rem, 4vw, 2rem);
}

.wordmark {
  display: inline-block;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(3.25rem, 12.5vw, 9.5rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.06;
  padding: 0.06em 0.1em 0.12em;
  max-width: 100%;
  text-align: center;
  color: var(--text-primary);
  background: linear-gradient(145deg, var(--text-primary) 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: wordmark-in 0.8s var(--ease) both;
}

@keyframes wordmark-in {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tagline {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  animation: fade-in 0.8s 0.2s var(--ease) both;
}

.hero-buttons {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  justify-content: center;
  animation: fade-in 0.8s 0.35s var(--ease) both;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}

body.home .footer {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.85rem 1.6rem;
  width: min(820px, calc(100% - 2.5rem));
  margin: 1rem auto 1.5rem;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

body.home .footer::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 55%);
  opacity: 0.65;
  pointer-events: none;
}

body.home .footer > * {
  position: relative;
  z-index: 1;
}

.footer-socials {
  display: flex;
  gap: 0.25rem;
}

.footer-socials a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: all 0.18s var(--ease);
}
.footer-socials a:hover {
  color: var(--text-primary);
  background: var(--bg-alt);
}

.footer-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
}

body.inner-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.page-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: calc(var(--nav-h) + clamp(1.75rem, 4vw, 3rem)) clamp(1.25rem, 3vw, 2rem) clamp(1.5rem, 4vw, 3rem);
}

.page-header {
  margin-bottom: 3rem;
  animation: fade-in 0.6s var(--ease) both;
}

.page-title {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.page-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 300;
}

.link-section {
  margin-bottom: 3rem;
  animation: fade-in 0.6s var(--ease) both;
}

.link-section:nth-child(2) { animation-delay: 0.05s; }
.link-section:nth-child(3) { animation-delay: 0.1s;  }
.link-section:nth-child(4) { animation-delay: 0.15s; }

.section-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: clamp(0.6rem, 1.6vw, 0.8rem);
}

.link-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.22s var(--ease);
  box-shadow: var(--shadow-card);
}
.link-card:hover {
  border-color: var(--border-dark);
  background: var(--surface-alt);
  transform: translateY(-2px) scale(1.01);
  box-shadow: var(--shadow-md);
}
.link-card:active {
  transform: translateY(0) scale(1);
}

.link-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.05rem;
  flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.project-icon {
  background: linear-gradient(135deg, var(--accent), #7C4A3A);
}

.link-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: hidden;
}

.link-name {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-handle {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0;
  transform: translate(-4px, 4px);
  transition: all 0.18s var(--ease);
}
.link-card:hover .link-arrow {
  opacity: 1;
  transform: translate(0, 0);
}

body.not-found {
  background: radial-gradient(1200px 600px at 20% -10%, rgba(201,100,66,0.12), transparent 60%),
              radial-gradient(900px 500px at 90% 0%, rgba(201,100,66,0.08), transparent 55%),
              var(--bg);
}

.notfound {
  flex: 1;
  display: grid;
  place-items: center;
  padding: calc(var(--nav-h) + clamp(2rem, 6vw, 4rem)) clamp(1.25rem, 4vw, 3rem) clamp(2.5rem, 6vw, 4rem);
  position: relative;
  overflow: hidden;
}

.notfound-sheen {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 0%, rgba(255,255,255,0.18) 45%, transparent 70%);
  opacity: 0.7;
  pointer-events: none;
  animation: sheen-sweep 2.6s var(--ease) 1 both;
}

.notfound-card {
  position: relative;
  z-index: 2;
  width: min(720px, 92vw);
  padding: clamp(2rem, 5vw, 3.25rem);
  border-radius: clamp(18px, 2.5vw, 28px);
  border: 1px solid var(--border);
  background: linear-gradient(145deg, var(--surface), var(--surface-alt));
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: fade-in 0.7s var(--ease) both;
}

.notfound-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.notfound-code {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(4.5rem, 18vw, 9rem);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 0.9;
  margin-bottom: 0.75rem;
  background: linear-gradient(140deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.notfound-title {
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.notfound-copy {
  color: var(--text-secondary);
  max-width: 44ch;
  margin: 0 auto 1.6rem;
}

.notfound-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.notfound-orbit {
  position: absolute;
  width: min(720px, 90vw);
  height: min(720px, 90vw);
  border-radius: 50%;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  opacity: 0.8;
}

.notfound-orbit span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px dashed rgba(201,100,66,0.25);
  animation: orbit-spin 18s linear infinite;
}

.notfound-orbit span:nth-child(2) {
  inset: 12%;
  border-style: solid;
  border-color: rgba(201,100,66,0.18);
  animation-duration: 26s;
}

.notfound-orbit span:nth-child(3) {
  inset: 24%;
  border-style: dotted;
  border-color: rgba(201,100,66,0.22);
  animation-duration: 34s;
  animation-direction: reverse;
}

@keyframes orbit-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes sheen-sweep {
  0% { transform: translateX(-40%); }
  70% { transform: translateX(0%); }
  100% { transform: translateX(0%); }
}

@media (max-width: 640px) {
  .nav { padding: 0 1.25rem; }

  .hero { gap: 2.5rem; padding-top: calc(var(--nav-h) + 1.5rem); }
  .hero-buttons { gap: 0.6rem; }
  .btn { padding: 0.7rem 1.25rem; font-size: 0.88rem; }

  .page-main { padding: calc(var(--nav-h) + 1.5rem) 1.25rem 2.25rem; }
  .link-grid  { grid-template-columns: 1fr; }

  .notfound-card { padding: 2rem 1.5rem; }
  .notfound-actions { gap: 0.6rem; }

  .footer { flex-direction: column; gap: 0.75rem; text-align: center; }
}

@media (max-width: 400px) {
  .hero-buttons { flex-direction: column; width: 100%; }
  .btn { width: 100%; }

  .notfound-actions { width: 100%; }
  .notfound-actions .btn { width: 100%; }
}
