/* ==========================================================================
   base.css — shared, opt-in primitives for 332321.xyz
   ==========================================================================

   WHAT THIS FILE IS
   Small, composable building blocks that a sub-app page can link to get a
   consistent shell without restyling its whole app. Everything here is
   opt-in: nothing applies unless the page puts the class on an element.

   DESIGN RULES FOR THIS FILE
   · Class selectors only. The ONLY element selectors are inside the minimal
     reset below.
   · Base selectors stay at specificity 0-1-0 so a page's own stylesheet can
     always win without needing !important. The ONE exception is the focus
     ring in §2, which is !important on purpose — see the note there.
   · No hardcoded colours. Every colour is a token; the raw palette lives in
     tokens.css and the palettes live in themes.css.
   · No @import. Pages link each file explicitly.

   LOAD ORDER (hard requirement — do not reorder):
       <link rel="stylesheet" href="css/tokens.css">
       <link rel="stylesheet" href="css/base.css">
       <link rel="stylesheet" href="css/<page>.css">
       <link rel="stylesheet" href="css/themes.css">   <-- MUST BE LAST

   WHY tokens.css COMES FIRST
   The tokens are the vocabulary; the primitives are the sentences. The
   primitives read tokens.css's variables, so the vocabulary has to exist
   before the sentences are interpreted. tokens.css itself ships with
   fallbacks, so a page that forgets themes.css still renders correctly —
   it simply will not follow the site-wide theme.

   PRIMITIVES PROVIDED
       .app-shell .app-header .app-title .app-subtitle .app-main
       .app-footer .app-footer-link
       .back-link
       .btn .btn-primary .btn-ghost .btn-icon
       .card .panel
       .badge .chip
       .input .select .textarea
       .visually-hidden .skip-link
       .theme-switcher .theme-gear .theme-dropdown .theme-option
       .theme-active .theme-random      (the switcher UI, moved out of
                                         themes.css so that file stays pure
                                         token remapping)
   ========================================================================== */

/* ==========================================================================
   1. MINIMAL RESET
   Deliberately conservative. Font-family is NOT set globally — sub-apps ship
   their own stacks — so the font is opted into via .app-shell instead.
   ========================================================================== */

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

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

img,
svg,
video,
canvas {
  max-width: 100%;
}

body {
  line-height: var(--line-height-base, 1.6);
}

/* Form controls do not inherit font-family from their parent by default, so
   they would fall back to the UA font. Inheriting keeps them in the page
   font without this file ever declaring a font-family of its own. */
button,
input,
select,
textarea {
  font-family: inherit;
}

/* ==========================================================================
   2. FOCUS VISIBILITY
   The site previously had NO visible focus ring, which is a real WCAG 2.4.7
   failure.

   WHY THIS RULE IS !important
   :where() keeps the selector list at zero specificity, so the rule sits at
   0-1-0 -- and every page that styles focus with an element selector
   outranked it and turned the ring OFF with `outline: none`:
       textarea:focus, input:focus   (0-1-1)
       .sort-select:focus             (0-2-0)
       .header-text { outline: none } (0-1-0, but it wins on source order)
   Eight tools shipped that way, so a keyboard user had NO focus indicator
   at all on them.

   Raising the specificity is not enough: the offending rules range from
   0-1-1 to 0-2-0, and a page can always add a more specific one later. A
   focus ring is an accessibility affordance, not a decoration, so the
   SHARED layer declares it !important and wins over any page rule.

   It is scoped as narrowly as possible: only `outline` and `outline-offset`,
   only on :focus-visible. The selector list stays inside :where() so the
   whole rule is still 0-1-0 -- a page that genuinely needs its own ring
   can use !important too, and a MORE specific important declaration still
   wins. Nothing else about the element's styling is affected.

   [contenteditable] is in the list because a contenteditable span is
   focusable but matches none of the element selectors: /w/daily-planner/
   styled its editable column headers with `outline: none` and the shared
   ring never even got a chance to apply.
   ========================================================================== */

:where(
    a,
    button,
    input,
    select,
    textarea,
    summary,
    [tabindex],
    [contenteditable='true']
  ):focus-visible {
  outline: 2px solid var(--focus-ring, var(--accent, var(--blue-400))) !important;
  outline-offset: 2px !important;
}

/* ==========================================================================
   3. UTILITIES
   ========================================================================== */

/* Screen-reader-only text. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* "Skip to content" — hidden until it receives keyboard focus. */
.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  z-index: var(--z-toast, 11000);
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  background: var(--accent, var(--blue-400));
  color: var(--accent-contrast, var(--slate-950));
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius-md, 6px) 0;
  transform: translateY(-120%);
  transition: transform var(--transition-fast, 150ms ease);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

/* ==========================================================================
   4. APP SHELL
   The standard page wrapper. Put .app-shell on <body> (or on a single
   wrapper <div> — the html/body background rules below follow it either way).
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  font-family: var(
    --font-sans,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    sans-serif
  );
  font-size: var(--font-size-md, 1rem);
  line-height: var(--line-height-base, 1.6);
  color: var(--text-primary, var(--slate-200));
  background-color: var(--bg-primary, var(--slate-950));
}

/* Keep the page background painted when .app-shell is a nested wrapper. */
:where(html, body):has(.app-shell) {
  background-color: var(--bg-primary, var(--slate-950));
  color: var(--text-primary, var(--slate-200));
}

.app-main {
  width: 100%;
  max-width: var(--content-max, 72rem);
  margin: 0 auto;
  padding: var(--space-6, 1.5rem) var(--space-4, 1rem);
  flex: 1 0 auto;
}

.app-header {
  width: 100%;
  max-width: var(--content-max, 72rem);
  margin: 0 auto;
  padding: var(--space-6, 1.5rem) var(--space-4, 1rem) var(--space-4, 1rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-2, 0.5rem);
}

.app-title {
  margin: 0;
  font-size: var(--font-size-2xl, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: var(--line-height-tight, 1.2);
  color: var(--text-primary, var(--slate-200));
}

.app-subtitle {
  margin: 0;
  font-size: var(--font-size-base, 0.9rem);
  color: var(--text-secondary, var(--slate-300));
  line-height: 1.5;
  max-width: 65ch;
}

.app-footer {
  width: 100%;
  max-width: var(--content-max, 72rem);
  margin: 0 auto;
  padding: var(--space-4, 1rem);
  border-top: 1px solid var(--border, var(--slate-600));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3, 0.75rem);
  font-size: var(--font-size-sm, 0.8rem);
  color: var(--text-secondary, var(--slate-300));
}

.app-footer-link {
  display: inline-block;
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  border-radius: var(--radius-md, 6px);
  color: var(--text-secondary, var(--slate-300));
  text-decoration: none;
  transition: color var(--transition-base, 200ms ease),
    background var(--transition-base, 200ms ease);
}

.app-footer-link:hover {
  color: var(--accent, var(--blue-400));
  background: var(--accent-soft, transparent);
}

/* ==========================================================================
   5. BACK LINK
   One consistent "← Back to Home" for every sub-page, instead of the eight
   different hand-rolled versions that used to exist.
   ========================================================================== */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 4px);
  color: var(--text-secondary, var(--slate-300));
  font-size: var(--font-size-sm, 0.8rem);
  text-decoration: none;
  transition: color var(--transition-base, 200ms ease),
    border-color var(--transition-base, 200ms ease),
    background var(--transition-base, 200ms ease);
}

.back-link:hover {
  color: var(--accent, var(--blue-400));
  border-color: var(--border, var(--slate-600));
  background: var(--accent-soft, transparent);
}

/* ==========================================================================
   6. BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 0.5rem);
  padding: 0.55rem 1.15rem;
  border: 1px solid var(--border-strong, var(--slate-600));
  border-radius: var(--radius-md, 6px);
  background: var(--bg-secondary, var(--slate-900));
  color: var(--text-primary, var(--slate-200));
  font-family: inherit;
  font-size: var(--font-size-base, 0.9rem);
  font-weight: 500;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast, 150ms ease),
    border-color var(--transition-fast, 150ms ease),
    color var(--transition-fast, 150ms ease);
}

.btn:hover {
  background: var(--bg-elevated, var(--slate-850));
  border-color: var(--accent, var(--blue-400));
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent, var(--blue-400));
  border-color: var(--accent, var(--blue-400));
  color: var(--accent-contrast, var(--slate-950));
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover, var(--blue-300));
  border-color: var(--accent-hover, var(--blue-300));
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong, var(--slate-600));
  color: var(--text-secondary, var(--slate-300));
}

.btn-ghost:hover {
  background: var(--accent-soft, transparent);
  border-color: var(--accent, var(--blue-400));
  color: var(--accent, var(--blue-400));
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: var(--radius-full, 999px);
}

/* ==========================================================================
   7. SURFACES
   ========================================================================== */

.card {
  background: var(--bg-secondary, var(--slate-900));
  border: 1px solid var(--border-strong, var(--slate-600));
  border-radius: var(--radius-lg, 8px);
  padding: var(--space-5, 1.25rem);
  box-shadow: 0 1px 2px var(--shadow-color, transparent);
}

.panel {
  background: var(--bg-elevated, var(--slate-850));
  border: 1px solid var(--border-strong, var(--slate-600));
  border-radius: var(--radius-lg, 8px);
  padding: var(--space-5, 1.25rem);
}

/* ==========================================================================
   8. BADGES & CHIPS
   .badge is the small outlined tag the homepage uses for skill pills; it
   lives here (not in style.css) so it is defined exactly once for the site.
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  font-size: 0.7rem;
  border: 1px solid var(--border, var(--slate-600));
  border-radius: var(--radius-sm, 4px);
  color: var(--text-secondary, var(--slate-300));
  white-space: nowrap;
}

@media (min-width: 768px) {
  .badge {
    padding: 0.15rem 0.55rem;
    font-size: 0.8rem;
  }
}

@media (min-width: 1200px) {
  .badge {
    padding: 0.2rem 0.7rem;
    font-size: 0.9rem;
  }
}

@media (min-width: 1600px) {
  .badge {
    padding: 0.25rem 0.85rem;
    font-size: 1rem;
  }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1, 0.25rem);
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--border, var(--slate-600));
  border-radius: var(--radius-full, 999px);
  background: var(--accent-soft, transparent);
  color: var(--accent, var(--blue-400));
  font-size: var(--font-size-xs, 0.7rem);
  font-weight: 500;
  white-space: nowrap;
}

/* ==========================================================================
   9. FORM CONTROLS
   ========================================================================== */

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong, var(--slate-600));
  border-radius: var(--radius-md, 6px);
  background: var(--bg-inset, var(--slate-850));
  color: var(--text-primary, var(--slate-200));
  font-family: inherit;
  font-size: var(--font-size-base, 0.9rem);
  line-height: 1.4;
  transition: border-color var(--transition-fast, 150ms ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted, var(--slate-400));
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent, var(--blue-400));
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.textarea {
  min-height: 6rem;
  resize: vertical;
}

/* ==========================================================================
   10. THEME SWITCHER UI
   Moved here from themes.css. These are COMPONENT styles, not theme styles:
   themes.css now contains nothing but token remapping.
   The class names are a hard contract with js/theme-switcher.js — do not
   rename them:
       .theme-switcher  .theme-gear  .theme-dropdown  .theme-option
       .theme-active    .theme-random
   ========================================================================== */

.theme-switcher {
  position: fixed;
  bottom: 20px;
  right: 72px;
  z-index: var(--z-floating, 1000);
}

.theme-gear {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-secondary, var(--slate-900));
  border: 1px solid var(--border, var(--slate-600));
  color: var(--text-secondary, var(--slate-300));
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition-base, 200ms ease),
    transform var(--transition-slow, 300ms ease);
  opacity: 0.6;
  line-height: 1;
}

.theme-gear:hover {
  opacity: 1;
}

.theme-gear[aria-expanded='true'] {
  transform: rotate(90deg);
  opacity: 1;
}

.theme-dropdown {
  position: absolute;
  bottom: 52px;
  right: 0;
  background: var(--bg-secondary, var(--slate-900));
  border: 1px solid var(--border, var(--slate-600));
  border-radius: var(--radius-lg, 8px);
  padding: 6px;
  min-width: 160px;
  display: none;
  box-shadow: 0 8px 24px var(--shadow-color, transparent);
}

.theme-dropdown.open {
  display: block;
}

.theme-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-primary, var(--slate-200));
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI',
      Roboto, sans-serif);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm, 4px);
  transition: background var(--transition-fast, 150ms ease);
}

.theme-option:hover {
  background: var(--wash-hover, transparent);
}

.theme-active {
  background: var(--wash-active, transparent);
  font-weight: 600;
}

.theme-active::before {
  content: '●';
  margin-right: 6px;
  font-size: 0.7em;
}

.theme-random {
  border-bottom: 1px solid var(--border, var(--slate-600));
  margin-bottom: 4px;
  padding-bottom: 10px;
  color: var(--text-secondary, var(--slate-300));
}

/* ==========================================================================
   11. LIGHT THEME EXTRIDES
   The light palette in themes.css re-maps the 17 semantic tokens, and
   almost every other token in tokens.css is DERIVED from them — but a few
   of them are plain literals there, and all of them are wrong for a light
   theme:

     · --text-inverse is the text colour for INVERSE (dark) surfaces. The
       light theme still has dark surfaces, so their label has to stay
       light. Left at tokens.css's dark default it would be near-black on
       a dark fill (2.4:1).
     · --success-contrast is the label colour for a --success fill. The
       light theme's --success is GitHub's dark green (#1a7f37), so a
       white label is the readable one: 5.1:1. The dark default that
       tokens.css ships gives 3.8:1, which is not enough for button text.
     · --wash-hover / --wash-active are the theme picker's row washes.
       tokens.css defines them as a WHITE overlay, which is right for the
       nine dark themes and completely invisible on the light theme's
       white dropdown.

   They are re-pointed at tokens the light theme already sets, so there is
   no hardcoded colour here and no dark theme is touched: the rule only
   matches <html data-theme="light">.

   WHY NOT INSIDE THE THEME BLOCK
   The 17-token theme contract in themes.css is deliberately not widened
   for this. A theme block may re-map the 17 semantic tokens and nothing
   else, so the odd-one-out tokens live here, next to the components that
   read them.
   ========================================================================== */

:root[data-theme='light'] {
  --text-inverse: var(--white);
  --success-contrast: var(--white);
  --wash-hover: var(--bg-hover);
  --wash-active: var(--accent-soft-strong);
}
