/* Shared styling for the landing page (index.html) and any non-canvas tool pages
   (e.g. expansion.html) - deliberately separate from style.css, which is specific
   to the triangle explorer (explore.html) and its fixed-viewport canvas layout. */

* {
  box-sizing: border-box;
}

:root {
  /* iOS only reports non-zero safe-area-inset-* once viewport-fit=cover is set on the
     viewport meta tag - see src/style.css / fixIOSViewportBug() in main.js. */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);

  /* Light/dark theme toggle (src/theme.js sets data-theme="light" on <html>). These only affect
     text/backgrounds that sit directly on the page (headings, subtitle, footer, plain body text) -
     dark chips/cards (buttons, .card, step boxes, info card etc.) keep their own fixed dark
     background + light text in both themes, so the interactive triangle/canvas UI and any teaching
     colour-coding (e.g. the binomial expansion coefficient colours) are unaffected either way. */
  --page-bg: #000000;
  --text-primary: #e8e8f0;
  --text-heading: #f0c93a;
  --text-muted: #a9adc1;
  --accent-cyan: #22e8f0;
  --chip-bg: #171a28;
  --chip-hover-bg: #2a2f47;
  --card-bg: #12141f;
  --heading-glow: none;
  --badge-text: #1a1608;
  --btn-text-color: var(--text-primary);
  --btn-text-weight: 400;
}

[data-theme="light"] {
  --page-bg: #d8dbe6;
  --text-primary: #20232f;
  --text-heading: #7a1fa2;
  --text-muted: #585c74;
  --accent-cyan: #0a5a5e;
  --chip-bg: #eef0f7;
  --chip-hover-bg: #c7cbdb;
  --card-bg: #e4e7f0;
  --heading-glow: none;
  --badge-text: #ffffff;
  --btn-text-color: #000000;
  --btn-text-weight: 700;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Stop Android Chrome's "font boosting" auto-inflating font-size on narrow text
     blocks it guesses are the main reading column - KaTeX's absolutely-positioned
     spans (e.g. a \binom fraction) are exactly what that heuristic misfires on. */
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  font-size: 100%; /* explicit root anchor, so nested %/em sizing (KaTeX's own cascade included) has a well-defined base */
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: inherit;
}

.portal-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: calc(16px + var(--safe-area-top, 0px)) calc(20px + var(--safe-area-right, 0px)) 16px calc(20px + var(--safe-area-left, 0px));
}

.portal-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-heading);
  text-shadow: var(--heading-glow);
  letter-spacing: 0.5px;
}

.home-link {
  font-size: 13px;
  line-height: 1.2;
  color: var(--btn-text-color);
  font-weight: var(--btn-text-weight);
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent-cyan);
  background: var(--chip-bg);
}

@media (hover: hover) and (pointer: fine) {
  .home-link:hover {
    background: var(--chip-hover-bg);
    color: var(--btn-text-color);
  }
}

.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: calc(24px + var(--safe-area-top, 0px)) calc(24px + var(--safe-area-right, 0px)) 24px calc(24px + var(--safe-area-left, 0px));
  text-align: center;
}

.landing-footer {
  padding: 16px calc(24px + var(--safe-area-right, 0px)) calc(24px + var(--safe-area-bottom, 0px)) calc(24px + var(--safe-area-left, 0px));
  text-align: center;
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 600;
}

.landing-footer p {
  margin: 4px 0;
}

.landing-footer a {
  color: var(--accent-cyan);
  font-weight: 700;
  text-decoration: none;
}

[data-theme="light"] .landing-footer a {
  /* --accent-cyan is deliberately dark/muted here for border legibility - the footer link
     wants a bolder, more eye-catching pop instead, so reuse the neon heading colour. */
  color: var(--text-heading);
}

@media (hover: hover) and (pointer: fine) {
  .landing-footer a:hover {
    text-decoration: underline;
  }
}

.landing h1 {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3em;
  font-size: clamp(32px, 6vw, 56px);
  color: var(--text-heading);
  text-shadow: var(--heading-glow);
  letter-spacing: 0.5px;
}

.landing-logo {
  height: 1em;
  width: auto;
  position: relative;
  top: 3px; /* nudge down slightly - the cropped logo's anti-aliased edge reads a touch high otherwise */
}

.landing .subtitle {
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 600;
  color: var(--text-primary);
}

.narrow-break {
  display: none;
}

@media (max-width: 600px) {
  .narrow-break {
    display: inline;
  }
}

.card-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  max-width: 900px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 320px;
  text-decoration: none;
  background: var(--card-bg);
  border: 1px solid var(--accent-cyan);
  border-radius: 12px;
  padding: 28px 26px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.card:focus-visible {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transform: translateY(-2px);
}

@media (hover: hover) and (pointer: fine) {
  .card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    transform: translateY(-2px);
  }
}

.card.disabled {
  border-color: #3a3d55;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: not-allowed;
  opacity: 0.6;
}

@media (hover: hover) and (pointer: fine) {
  .card.disabled:hover {
    transform: none;
  }
}

.card h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text-primary);
}

.card p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.5;
}

.card .card-tag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--badge-text);
  background: var(--text-heading);
  padding: 3px 8px;
  border-radius: 999px;
}

.card.disabled .card-tag {
  color: var(--text-muted);
  background: var(--chip-hover-bg);
}

.theme-toggle {
  font-size: 13px;
  line-height: 1.2;
  color: var(--btn-text-color);
  font-weight: var(--btn-text-weight);
  padding: 7px 16px;
  border-radius: 6px;
  border: 1px solid var(--accent-cyan);
  background: var(--chip-bg);
  cursor: pointer;
  font-family: inherit;
}

@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover {
    background: var(--chip-hover-bg);
  }
}

.placeholder-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.placeholder-page h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  color: var(--text-heading);
  text-shadow: var(--heading-glow);
}

.placeholder-page p {
  margin: 0;
  max-width: 480px;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
}
