/* ============================================================================
   Tyler Johns - portfolio site
   ONE stylesheet, shared by index.html, portfolio.html and projects.html.

   ---------------------------------------------------------------------------
   NAMING REFERENCE - every class and id on the site, and what it is for.
   Named by PURPOSE, not appearance. lowercase-with-hyphens.
   ---------------------------------------------------------------------------
   .theme-switch   the <label> in the header that wraps the toggle
   #theme-toggle   the checkbox that drives light/dark (exactly one per page)
   .btn            the two link-buttons in #about (still <a>: they navigate)
   .headshot       the portrait image in #about
   .card-grid      wrapper <div> around the cards - becomes the responsive grid
   .card           each <details> - one project box. On the home page it is
                   an <a> instead, because that card links out rather than
                   opening in place.
   .featured       used ALONGSIDE .card on the home page: accent border only
   .card-thumb     thumbnail <img> inside <summary>
   .card-title     <h3> inside <summary>
   .card-brief     one-line <p> inside <summary>
   .card-body      the <div> after </summary> - hidden until the card opens
   .card-photos    the <div> of photos inside .card-body - stacked vertically
                   Each photo is a <figure> holding a linked <img> and a
                   <figcaption> that repeats the image's alt text.

   Card ids, used as link targets (e.g. portfolio.html#extruder):
     portfolio.html  #extruder  #viewfinder
     projects.html   #endtable  #glovebox  #rotating-tv

   Page landmark ids (index.html only):  #about  #featured  #contact
   ============================================================================ */


/* ============================================================================
   1. VARIABLES - the "paint cans"
   Each --name is a can of paint. Rules below never name a color directly;
   they say var(--name), so swapping the cans repaints the whole site.
   THIS IS THE ONLY PLACE IN THIS FILE WHERE A COLOR VALUE APPEARS.
   ============================================================================ */

/* :root is the <html> element - the outermost box. Dark is the default. */
:root {
  --bg:     #121418;   /* page background */
  --card:   #1b1f27;   /* card background */
  --text:   #f3efe4;   /* main text (ivory) */
  --border: #3a4252;   /* borders and dividing lines */
  --accent: #8fb0e0;   /* links, the switch, featured border (light navy) */
  --muted:  #a0a6b0;   /* secondary text */
}

/* The light cans. Read the selector as: "if this page contains a theme toggle
   that is NOT checked, swap in light paint." :has() lets the outer box react
   to the state of a box inside it - which is how this works without any
   JavaScript. Unchecked = light, checked = dark, and the HTML ships checked. */
:root:has(#theme-toggle:not(:checked)) {
  --bg:     #fbf8f0;   /* ivory */
  --card:   #ffffff;
  --text:   #1a1a1a;
  --border: #cfc8b8;
  --accent: #1f3a68;   /* navy */
  --muted:  #5a5a5a;
}


/* ============================================================================
   2. SMALL RESET
   ============================================================================ */

/* border-box means padding and border count INSIDE a box's stated width,
   so a 280px box stays 280px once you add padding. Far fewer surprises. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Browsers put a margin around <body> by default. Remove it so our own
   spacing is the only spacing. */
body {
  margin: 0;
}


/* ============================================================================
   3. BASE - text, colors, links
   ============================================================================ */

body {
  background: var(--bg);
  color: var(--text);
  /* System font stack: use whatever font the visitor's computer already has.
     No web font is downloaded, so no third-party request is made. */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent);
}

/* Keep a visible outline for keyboard users. :focus-visible shows it when
   tabbing but not on a plain mouse click. */
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ============================================================================
   4. IMAGES AND VIDEO
   ============================================================================ */

/* max-width: 100% keeps a picture inside its parent box however big the file
   is; height: auto scales the height to match so nothing looks squashed;
   display: block removes the small gap browsers leave under inline images. */
img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}


/* ============================================================================
   5. CENTERED COLUMN
   One width shared by header, main and footer, so everything lines up.
   margin: 0 auto splits the leftover space evenly - that is the centering.
   ============================================================================ */

header,
main,
footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}


/* ============================================================================
   6. HEADER - nav on the left, theme switch on the right
   ============================================================================ */

/* display: flex lays this box's children out in a row. Its two children are
   <nav> and the <label>, and space-between pushes them to opposite ends,
   which is what puts the switch at the top right. */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;   /* on a narrow phone they drop onto two lines */
  border-bottom: 1px solid var(--border);
}

/* The nav links are a list. Remove the bullets and lay them out in a row. */
header nav ul {
  list-style: none;
  display: flex;
  gap: 1rem;
  margin: 0;
  padding: 0;
}


/* ============================================================================
   7. THEME SWITCH - a slider built from one checkbox, no JavaScript
   The checkbox itself is painted as the track; its ::before is the knob.
   ============================================================================ */

.theme-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--muted);
}

/* appearance: none strips the native checkbox so we can paint our own shape. */
#theme-toggle {
  appearance: none;
  -webkit-appearance: none;
  position: relative;   /* makes this box the frame the knob sits inside */
  flex: none;           /* never let flexbox squash the track */
  width: 2.75rem;
  height: 1.5rem;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  cursor: pointer;
}

/* The knob. An empty ::before is a small extra box we can place and move. */
#theme-toggle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0.1875rem;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--accent);
  /* The one animation on the site: the knob slides instead of jumping. */
  transition: left 0.15s ease-in-out;
}

/* Checked = dark mode = knob on the right. */
#theme-toggle:checked::before {
  left: calc(100% - 1.1875rem);
}

#theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ============================================================================
   8. SECTIONS
   ============================================================================ */

main section {
  margin-bottom: 2.5rem;
}

/* A thin line between the home page's sections, for separation without
   adding any decoration. */
#featured,
#contact {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}


/* ============================================================================
   9. BUTTONS (.btn)
   These stay <a> elements because they navigate - they only LOOK like buttons.
   ============================================================================ */

.btn {
  display: inline-block;   /* lets a link take padding like a box */
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  margin: 0.25rem 0.5rem 0.25rem 0;
  text-decoration: none;
}


/* ============================================================================
   10. CARDS
   ============================================================================ */

/* auto-fill + minmax means: fit as many 280px-wide columns as the window
   allows, then share the leftover space between them. On a phone that works
   out to one column with no extra rules needed. */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  align-items: start;
}

.card {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  padding: 1rem;
}

/* Two labels on one box: .card does all the work, .featured only recolors
   the border. Home-page cards carry class="card featured". */
.card.featured {
  border-color: var(--accent);
}

/* The home page's featured card is an <a>, not a <details> - the whole box is
   one link to the full project. These three lines stop it looking like a link:
   no underline, normal text color, and block so it fills the grid cell. */
a.card {
  display: block;
  text-decoration: none;
  color: inherit;
}

/* :target is "the element the address bar's #name is pointing at". Arriving
   from portfolio.html#extruder outlines that card so it is obvious which
   project the link meant. scroll-margin-top leaves a little room above it
   instead of pinning it to the very top of the window. */
.card {
  scroll-margin-top: 1rem;
}

.card:target {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* An open card spans every column, so its neighbours flow below it
   instead of being stretched to match its height. */
.card[open] {
  grid-column: 1 / -1;
}

/* Once the card is open the thumbnail and the one-line brief are redundant -
   the full photos and description are right there. The title stays. */
.card[open] .card-thumb,
.card[open] .card-brief {
  display: none;
}

summary {
  cursor: pointer;
}

.card-thumb {
  border: 1px solid var(--border);
  border-radius: 4px;
}

.card-title {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.1rem;
}

.card-brief {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card-body {
  margin-top: 1rem;
}

/* Photos stacked one after another, top to bottom. No carousel, no slider. */
.card-photos {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-photos img {
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Each photo is a <figure>: the picture plus its caption treated as one unit.
   <figure> has a big default margin, so clear it and let .card-photos' gap do
   the spacing instead. */
.card-photos figure {
  margin: 0;
}

/* The caption repeats the image's alt text, so a photo has a name two people
   can refer to - "the third extruder photo" becomes "Extruder Photo 3". */
.card-photos figcaption {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* The portrait in #about. Without a cap it would stretch to the full
   900px column. */
.headshot {
  max-width: 400px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 1rem;
}


/* ============================================================================
   11. FOOTER
   ============================================================================ */

footer {
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

footer ul {
  list-style: none;
  display: flex;
  gap: 1rem;
  margin: 0;
  padding: 0;
}
