/* ============================================================
   gwilber.com — hand-written styles, no build step.
   Theme model:
     - CSS variables on :root define LIGHT mode.
     - @media (prefers-color-scheme: dark) flips the defaults.
     - [data-theme="light"|"dark"] on <html> (set by the toggle)
       overrides the OS preference in both directions.
   ============================================================ */

/* ---------- design tokens ---------- */
:root {
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
               "Liberation Mono", monospace;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
               Arial, sans-serif;

  /* light theme (default) */
  --bg: #f7f8fa;
  --bg-raised: #ffffff;
  --text: #1f2430;
  --text-muted: #57606e;
  --border: #d7dce3;
  --accent: #0b7a3e;          /* green, 4.5:1+ on light bg */
  --accent-soft: #e3f2e9;
  --link: #0a5fb4;
  --shadow: 0 1px 3px rgba(20, 26, 36, 0.08), 0 8px 24px rgba(20, 26, 36, 0.06);

  /* terminal stays dark in both themes, like a real editor pane */
  --term-bg: #0d1117;
  --term-chrome: #161b22;
  --term-border: #30363d;
  --term-text: #e6edf3;
  --term-muted: #8b949e;
  --term-green: #3fb950;
  --term-cyan: #56d4dd;
  --term-yellow: #d29922;
  --term-red: #f85149;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-raised: #161b22;
    --text: #e6edf3;
    --text-muted: #9aa4b2;
    --border: #30363d;
    --accent: #3fb950;
    --accent-soft: #12261a;
    --link: #58a6ff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* manual toggle overrides the OS preference, both directions */
:root[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-raised: #ffffff;
  --text: #1f2430;
  --text-muted: #57606e;
  --border: #d7dce3;
  --accent: #0b7a3e;
  --accent-soft: #e3f2e9;
  --link: #0a5fb4;
  --shadow: 0 1px 3px rgba(20, 26, 36, 0.08), 0 8px 24px rgba(20, 26, 36, 0.06);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --text: #e6edf3;
  --text-muted: #9aa4b2;
  --border: #30363d;
  --accent: #3fb950;
  --accent-soft: #12261a;
  --link: #58a6ff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.25s ease, color 0.25s ease;
}

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

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}
.brand-prompt { color: var(--accent); }

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

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.15s ease;
}
.nav-links a:hover { color: var(--accent); }

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 999px;
  width: 2.1rem;
  height: 2.1rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { border-color: var(--accent); transform: rotate(15deg); }

/* show the icon for the mode you'd switch TO */
.theme-icon-sun { display: none; }
.theme-icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-icon-sun { display: inline; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
:root[data-theme="light"] .theme-icon-sun { display: none; }
:root[data-theme="light"] .theme-icon-moon { display: inline; }

/* ---------- hero ---------- */
.hero {
  padding-top: 3.5rem;
  padding-bottom: 1rem;
  text-align: center;
}

.hero-name {
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.hero-tagline {
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.now-building {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  margin: 0 0 2rem;
}
.now-building-label { opacity: 0.75; }

.hero-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.9rem;
}

/* ---------- terminal ---------- */
.terminal {
  text-align: left;
  background: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 760px;
  margin: 0 auto;
}

.terminal-titlebar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--term-chrome);
  border-bottom: 1px solid var(--term-border);
  padding: 0.55rem 0.9rem;
}

.terminal-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}
.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }

.terminal-title {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--term-muted);
  margin-left: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.terminal-body {
  padding: 0.9rem 1rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--term-text);
  height: 20rem;
  overflow-y: auto;
  cursor: text;
}

.terminal-output { white-space: pre-wrap; word-break: break-word; }

.terminal-output .t-line { min-height: 1.35em; }
.terminal-output .t-echo { color: var(--term-text); }
.terminal-output .t-echo::before { content: "visitor@gwilber.com:~$ "; color: var(--term-green); }
.terminal-output .t-muted { color: var(--term-muted); }
.terminal-output .t-green { color: var(--term-green); }
.terminal-output .t-cyan { color: var(--term-cyan); }
.terminal-output .t-yellow { color: var(--term-yellow); }
.terminal-output .t-red { color: var(--term-red); }
.terminal-output a { color: var(--term-cyan); }

.terminal-output .t-cmd-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--term-cyan);
  text-decoration: underline;
  cursor: pointer;
}

.terminal-input-line {
  display: flex;
  align-items: baseline;
  gap: 0.5ch;
  margin-top: 0.15rem;
}

.terminal-prompt {
  color: var(--term-green);
  white-space: nowrap;
  flex: none;
}

.terminal-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: baseline;
}

.terminal-input {
  position: relative;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--term-text);
  font: inherit;
  padding: 0;
  margin: 0;
  caret-color: transparent;
}

/* mirror measures typed text so the block cursor can sit after it */
.terminal-mirror {
  position: absolute;
  visibility: hidden;
  white-space: pre;
}

.terminal-cursor {
  position: absolute;
  top: 0.1em;
  left: 0;
  width: 0.6ch;
  height: 1.2em;
  background: var(--term-green);
  animation: cursor-blink 1.1s steps(1) infinite;
  pointer-events: none;
}

@keyframes cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---------- sections ---------- */
.section { padding: 3rem 1.25rem 0.5rem; }

.section-title {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  margin: 0 0 1rem;
}
.section-hash { color: var(--accent); margin-right: 0.25rem; }

/* ---------- projects ---------- */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.project-card:hover,
.project-card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.project-preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--term-bg);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.project-preview-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--term-muted);
  padding: 1rem;
  text-align: center;
}

.project-preview-glyph { font-size: 1.6rem; color: var(--term-green); }
.project-preview-sub { font-size: 0.72rem; opacity: 0.8; }

/* live iframe preview: sits above the fallback, fades in once loaded.
   Scaled 2x down so the remote page renders at a sensible width. */
.project-preview iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  transform: scale(0.5);
  transform-origin: top left;
  border: 0;
  pointer-events: none;    /* clicks stay on the card link */
  opacity: 0;
  transition: opacity 0.35s ease;
  background: #fff;
}
.project-preview iframe.is-loaded { opacity: 1; }

.project-info { padding: 1rem 1.1rem 1.1rem; }
.project-name { margin: 0 0 0.35rem; font-size: 1.05rem; }
.project-desc { margin: 0 0 0.6rem; font-size: 0.92rem; color: var(--text-muted); }

.project-link-hint {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
}

/* ---------- github feed ---------- */
.github-feed {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0;
  margin-top: 1.25rem;
}

.feed-loading, .feed-fallback {
  padding: 1rem 1.25rem;
  color: var(--text-muted);
  margin: 0;
}

.feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.feed-item:last-child { border-bottom: none; }

.feed-verb { flex: 1; min-width: 0; }
.feed-time {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.feed-more {
  display: block;
  padding: 0.7rem 1.25rem;
  font-size: 0.85rem;
}

/* ---------- footer ---------- */
.site-footer {
  margin-top: 3.5rem;
  padding: 2.5rem 0 2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

.footer-fineprint {
  margin-top: 2rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ---------- toast (konami & misc notices) ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(0.5rem);
  background: var(--term-bg);
  color: var(--term-text);
  border: 1px solid var(--term-green);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  max-width: min(90vw, 32rem);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- confetti (konami easter egg) ---------- */
.confetti {
  position: fixed;
  top: -16px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  z-index: 99;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  100% {
    transform: translate3d(calc(var(--drift, 0) * 18vw), 105vh, 0)
               rotate(calc(var(--spin, 1) * 660deg));
    opacity: 0.7;
  }
}

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  .nav-links { gap: 0.7rem; font-size: 0.9rem; }
  .terminal-body { height: 16rem; font-size: 0.8rem; }
  .hero { padding-top: 2.25rem; }
  .section { padding-top: 2.25rem; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .confetti { display: none; }
  .project-card, .theme-toggle { transition: none; }
  .project-card:hover, .project-card:focus-visible { transform: none; }
  .terminal-cursor { animation: none; }
}
