:root {
  --bg: #faf8f3;
  --text: #2b2620;
  --accent: #4c6b3f;
  --accent-light: #a3c586;
  --nav-bg: #ffffff;
  --border: #e3ddce;
  --max-width: 960px;
  --sidebar-width: 220px;
  --bright-green: #16a34a;
  --muted-text: #6b6355;
}

html.dark-mode {
  --bg: #0a0f2c;
  --text: #e9ecfa;
  --accent: #9fd8b0;
  --accent-light: #4f7a63;
  --nav-bg: #121a42;
  --border: #262f5c;
  --bright-green: #4ade80;
  --muted-text: #a8acc4;
}

* {
  box-sizing: border-box;
}

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.floral-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.floral-item {
  position: absolute;
  overflow: visible;
}

.floral-sway {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: floral-sway 7s ease-in-out infinite;
}

@keyframes floral-sway {
  0%, 100% {
    transform: rotate(-1.5deg) translateX(-1px);
  }
  50% {
    transform: rotate(1.5deg) translateX(1px);
  }
}

/* Wind gusts (sudden rush, blow-away, damped wobble) are driven per-flower
   from JS via the Web Animations API, since each gust needs a random
   direction with per-flower jitter that plain CSS keyframes can't express.
   This group just needs to exist as the layer that JS animates. */
.floral-wind {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

.theme-toggle {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 9999;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--nav-bg);
  color: var(--text);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  transition: background 0.2s ease, transform 0.15s ease;
}

.theme-toggle:hover {
  transform: scale(1.08);
}

.help-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9999;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--nav-bg);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  transition: background 0.2s ease, transform 0.15s ease;
}

.help-fab:hover {
  transform: scale(1.08);
}

@media (min-width: 641px) {
  .help-fab {
    display: flex;
  }
}

.help-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1.5rem;
}

.help-modal-overlay.open {
  display: flex;
}

.help-modal {
  background: var(--nav-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.help-modal-header h2 {
  margin: 0;
  color: var(--accent);
  font-size: 1.2rem;
}

.help-modal-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}

.help-refresh {
  margin: 0 0 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.help-refresh-title {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 700;
}

.help-refresh-link,
.help-refresh-link:visited {
  color: #3b82f6;
  text-decoration: underline;
  font-size: 0.95rem;
}

.help-refresh-link:hover {
  color: #60a5fa;
}

.help-refresh-or {
  color: var(--muted-text);
  font-size: 0.9rem;
  margin: 0 0.2rem 0 0.35rem;
}

.help-refresh .help-key {
  vertical-align: middle;
}

.help-group + .help-group {
  margin-top: 1.1rem;
}

.help-group-title {
  margin: 0 0 0.55rem;
  color: var(--muted-text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.help-key-sep {
  color: var(--muted-text);
  font-size: 0.8rem;
  padding: 0 0.1rem;
}

/* The shortcuts window must never need scrolling, so it tightens up on short
   and narrow screens, and lays the groups out as columns when it's wide but
   short (e.g. a phone held sideways). */
@media (max-height: 700px) {
  .help-modal-overlay {
    padding: 0.75rem;
  }

  .help-modal {
    padding: 1rem 1.25rem;
    max-height: 94vh;
  }

  .help-modal-header {
    margin-bottom: 0.6rem;
  }

  .help-refresh {
    margin-bottom: 0.7rem;
    padding-bottom: 0.6rem;
  }

  .help-refresh-title {
    margin-bottom: 0.25rem;
    font-size: 1rem;
  }

  .help-group + .help-group {
    margin-top: 0.7rem;
  }

  .help-group-title {
    margin-bottom: 0.35rem;
  }

  .help-shortcut-list {
    gap: 0.4rem;
  }
}

@media (max-height: 700px) and (min-width: 600px) {
  .help-modal {
    max-width: 800px;
  }

  .help-groups {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0 1.5rem;
  }

  .help-group + .help-group {
    margin-top: 0;
  }
}

@media (max-height: 600px) {
  .help-modal {
    padding: 0.8rem 1rem;
  }

  .help-modal-header h2 {
    font-size: 1.05rem;
  }

  .help-refresh-title {
    font-size: 0.95rem;
  }

  .help-shortcut-list {
    gap: 0.3rem;
  }

  .help-key {
    padding: 0.1rem 0.35rem;
    font-size: 0.72rem;
  }

  .help-shortcut-desc {
    font-size: 0.8rem;
    line-height: 1.25;
  }
}

@media (max-height: 440px) {
  .help-modal-overlay {
    padding: 0.5rem;
  }

  .help-modal {
    padding: 0.6rem 0.9rem;
    max-height: 96vh;
  }

  .help-modal-header {
    margin-bottom: 0.3rem;
  }

  .help-modal-header h2 {
    font-size: 0.95rem;
  }

  .help-refresh {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem 0.6rem;
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
  }

  .help-refresh-title {
    margin: 0;
    font-size: 0.9rem;
  }

  .help-group-title {
    margin-bottom: 0.25rem;
  }

  .help-shortcut-list {
    gap: 0.2rem;
  }
}

@media (max-width: 520px) {
  .help-modal-overlay {
    padding: 0.5rem;
  }

  .help-modal {
    padding: 0.85rem 1rem;
    max-height: 96vh;
  }

  .help-modal-header h2 {
    font-size: 1.05rem;
  }

  .help-refresh-title {
    font-size: 1rem;
  }

  .help-refresh-link,
  .help-refresh-link:visited {
    font-size: 0.85rem;
  }

  .help-shortcut-list {
    gap: 0.3rem;
  }

  .help-shortcut-list li {
    gap: 0.6rem;
  }

  .help-key {
    min-width: 1.4rem;
    padding: 0.1rem 0.35rem;
    font-size: 0.72rem;
  }

  .help-shortcut-desc {
    font-size: 0.8rem;
    line-height: 1.25;
  }
}

.help-shortcut-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.help-shortcut-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.help-shortcut-keys {
  align-items: center;
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

.help-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-family: monospace;
  font-size: 0.82rem;
}

.help-shortcut-desc {
  color: var(--muted-text);
  text-align: right;
  font-size: 0.9rem;
}

.firefly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9998;
}

.firefly {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #f8ffc0 0%, #d9ff6e 45%, rgba(217, 255, 110, 0) 70%);
  box-shadow: 0 0 6px 2px rgba(217, 255, 110, 0.85), 0 0 14px 5px rgba(180, 255, 120, 0.35);
  animation-name: firefly-float;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

@keyframes firefly-float {
  0% {
    transform: translate(0, 0);
    opacity: 0.15;
  }
  20% {
    opacity: 1;
  }
  25% {
    transform: translate(var(--tx1), var(--ty1));
  }
  45% {
    opacity: 0.25;
  }
  50% {
    transform: translate(var(--tx2), var(--ty2));
  }
  70% {
    opacity: 1;
  }
  75% {
    transform: translate(var(--tx3), var(--ty3));
  }
  100% {
    transform: translate(0, 0);
    opacity: 0.15;
  }
}

header {
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-width);
  flex-shrink: 0;
}

nav {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0 0.5rem;
  margin-bottom: 1.5rem;
  display: block;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
}

.nav-links a {
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  padding: 0.6rem 0.5rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  display: block;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-links a:hover {
  color: var(--accent);
  background: var(--bg);
}

.nav-links a.active {
  color: var(--accent);
  border-left-color: var(--accent-light);
  background: var(--bg);
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  width: 100%;
}

.hero {
  text-align: center;
}

.hero-img-toggle {
  display: inline-block;
  max-width: 320px;
  width: 100%;
  margin: 1.5rem 0;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.hero-img-toggle:hover {
  opacity: 0.92;
  transform: translateY(-2px);
}

.hero img {
  display: block;
  width: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.hero .hero-img-dark {
  display: none;
}

html.dark-mode .hero-img-light {
  display: none;
}

html.dark-mode .hero-img-dark {
  display: block;
}

.hero h1 {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}

.hero p {
  color: var(--bright-green);
  font-weight: 600;
  font-size: 1.1rem;
}

h1 {
  font-size: 1.8rem;
}

.tab-buttons {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin: 1.5rem 0 2rem;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .tab-buttons {
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0.25rem;
  }

  .tab-buttons button {
    padding: 0.5rem 0.4rem;
    font-size: 0.85rem;
  }
}

.tab-buttons button {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  padding: 0.6rem 1rem;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.tab-buttons button:hover {
  color: var(--accent);
}

.tab-buttons button.active {
  color: var(--accent);
  border-color: var(--accent-light);
  background: color-mix(in srgb, var(--accent-light) 25%, transparent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* The Fun page's head script sets data-fun-tab to the remembered tab, so the
   right tab is showing from the very first paint. script.js removes it once
   it has set the same state with classes. */
html[data-fun-tab] .tab-panel {
  display: none;
}

html[data-fun-tab="languages"] #languages,
html[data-fun-tab="music"] #music,
html[data-fun-tab="games"] #games,
html[data-fun-tab="food"] #food {
  display: block;
}

html[data-fun-tab] .tab-buttons button.active {
  color: var(--text);
  border-color: transparent;
  background: none;
}

html[data-fun-tab="languages"] .tab-buttons button[data-tab="languages"],
html[data-fun-tab="music"] .tab-buttons button[data-tab="music"],
html[data-fun-tab="games"] .tab-buttons button[data-tab="games"],
html[data-fun-tab="food"] .tab-buttons button[data-tab="food"] {
  color: var(--accent);
  border-color: var(--accent-light);
  background: color-mix(in srgb, var(--accent-light) 25%, transparent);
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (min-width: 641px) {
  .tile-grid > :last-child:nth-child(3n + 1) {
    grid-column: 1 / -1;
    max-width: calc((100% - 2rem) / 3);
    justify-self: center;
  }

  #games .tile-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
  }

  #games .tile-card {
    padding: 0.85rem 0.5rem;
    gap: 0.3rem;
  }

  #games .tile-emoji {
    font-size: 1.7rem;
  }

  #games .tile-grid > :last-child:nth-child(3n + 1) {
    grid-column: auto;
    max-width: none;
    justify-self: auto;
  }
}

.tile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.tile-card:hover {
  border-color: var(--accent-light);
  transform: translateY(-2px);
}

.tile-flag {
  width: 100%;
  max-width: 72px;
  height: auto;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--border);
}

.tile-emoji {
  font-size: 2.5rem;
  line-height: 1;
}

@media (max-width: 640px) {
  .tile-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.music-plus-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 150px));
  grid-template-rows: repeat(3, auto);
  gap: 0.6rem;
  justify-content: center;
}

#music .tile-card {
  padding: 1rem 0.6rem;
  gap: 0.35rem;
}

#music .tile-emoji {
  font-size: 1.8rem;
}

.music-plus-top {
  grid-column: 2;
  grid-row: 1;
}

.music-plus-left {
  grid-column: 1;
  grid-row: 2;
}

.music-plus-center {
  grid-column: 2;
  grid-row: 2;
}

.music-plus-right {
  grid-column: 3;
  grid-row: 2;
}

.music-plus-bottom {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 640px) {
  .music-plus-grid {
    grid-template-columns: 1fr 1fr;
  }

  .music-plus-top,
  .music-plus-left,
  .music-plus-center,
  .music-plus-right,
  .music-plus-bottom {
    grid-column: auto;
    grid-row: auto;
  }

  .music-plus-grid > :last-child:nth-child(2n + 1) {
    grid-column: 1 / -1;
  }
}

.music-track-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.music-track-list[hidden] {
  display: none;
}

/* Phones: Singlez songs sit closer together (half the usual space between
   embeds: the list gap plus each embed's own top and bottom margin). */
@media (max-width: 640px) {
  #music-tracks[data-category="singles"] {
    gap: 0.625rem;
  }

  #music-tracks[data-category="singles"] .video-embed {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
  }
}

.embed-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.25rem;
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  transition: opacity 0.3s ease;
}

.embed-placeholder a {
  color: inherit;
  text-decoration: underline;
}

.embed-placeholder-done {
  opacity: 0;
  pointer-events: none;
}

.music-artist-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1.5rem;
}

.album-graph {
  position: relative;
  width: min(100%, 520px);
  margin: 0.5rem auto 2rem;
}

/* The Albumz graph page is exactly one viewport tall: the graph takes the
   room left under the title and scales down to fit, so it never scrolls. */
body.music-graph-page {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.music-graph-page .content {
  min-height: 0;
}

.music-graph-page main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 1rem;
}

.album-graph-wrap {
  flex: 1 1 0;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

.album-graph-wrap .album-graph {
  width: min(100cqw, 520px, calc(100cqh * var(--graph-ratio, 1)));
  margin: 0;
}

.album-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.album-lines line {
  stroke: var(--accent-light);
  stroke-width: 2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.album-node {
  position: absolute;
  display: block;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid var(--border);
  border-radius: 16%;
  background: var(--nav-bg);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.album-node img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-node:hover,
.album-node:focus-visible {
  transform: translate(-50%, -50%) scale(1.05);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-light) 45%, transparent), 0 4px 14px rgba(0, 0, 0, 0.18);
}

.music-artist-tab-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  padding: 0.5rem 1rem;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.music-artist-tab-btn:hover {
  color: var(--accent);
}

.music-artist-tab-btn.active {
  color: var(--accent);
  border-color: var(--accent-light);
  background: color-mix(in srgb, var(--accent-light) 25%, transparent);
}

.spotify-embed {
  position: relative;
  width: 100%;
  max-width: 640px;
  height: 152px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.spotify-embed.spotify-embed-album {
  height: 352px;
}

.spotify-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.fact-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.fact-list li {
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.fact-list .lang-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.basics-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.basics-section h2 {
  color: var(--accent);
  margin: 0 0 0.4rem;
  font-size: 1.3rem;
}

.basics-note {
  color: var(--muted-text);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  line-height: 1.5;
}

.basics-note code {
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
}

.basics-group {
  margin-bottom: 1.5rem;
}

.basics-group h3 {
  font-size: 0.95rem;
  color: var(--text);
  margin: 0 0 0.6rem;
}

.basics-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1.25rem;
}

.basics-tab-btn {
  background: none;
  border: none;
  font: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.basics-tab-btn:hover {
  color: var(--accent);
}

.basics-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.basics-tab-panel {
  display: none;
}

.basics-tab-panel.active {
  display: block;
}

.tone-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.tone-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--nav-bg);
  padding: 0.75rem 0.9rem;
}

.tone-card-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.tone-symbol {
  font-size: 1.2rem;
}

.tone-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
}

.tone-effect {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted-text);
  line-height: 1.4;
}

.tone-example {
  margin: 0;
  font-size: 0.85rem;
  font-style: italic;
}

.ocr-target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.ocr-target-word {
  font-size: 1.6rem;
  font-weight: 700;
  margin-right: 0.6rem;
}

.ocr-target-meta {
  color: var(--muted-text);
  font-size: 0.9rem;
}

.ocr-canvas {
  display: block;
  width: 100%;
  max-width: 440px;
  height: auto;
  aspect-ratio: 440 / 220;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.ocr-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.ocr-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.1s ease;
}

.ocr-btn:hover {
  transform: translateY(-1px);
}

.ocr-btn-secondary {
  background: var(--nav-bg);
  color: var(--text);
}

.ocr-btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.ocr-result {
  margin-top: 1rem;
}

.ocr-result p {
  margin: 0.3rem 0;
}

.ocr-result-status {
  font-weight: 700;
}

.ocr-result.match .ocr-result-status {
  color: var(--bright-green);
}

.ocr-result.nomatch .ocr-result-status {
  color: #d94f4f;
}

.ocr-result-row span {
  color: var(--muted-text);
  margin-right: 0.4rem;
}

.ocr-result.error {
  color: var(--muted-text);
  font-size: 0.9rem;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.char-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--nav-bg);
}

.char-chip .chip-char {
  font-size: 1.25rem;
  line-height: 1.3;
  white-space: nowrap;
}

.char-chip .chip-translit {
  font-size: 0.7rem;
  color: var(--muted-text);
  margin-top: 0.2rem;
  text-align: center;
  white-space: nowrap;
}

.vocab-table {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.5rem 1rem;
  align-items: baseline;
}

.vocab-word {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}

.vocab-translit {
  color: var(--muted-text);
  font-style: italic;
  font-size: 0.88rem;
  white-space: nowrap;
}

.vocab-meaning {
  color: var(--text);
}

@media (max-width: 640px) {
  .vocab-table {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }

  .vocab-table > div {
    margin-bottom: 0.1rem;
  }

  .vocab-meaning {
    margin-bottom: 0.6rem;
  }
}

.project-name {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.blog-date {
  font-size: 0.85rem;
  color: var(--bright-green);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

/* The whole card is clickable on the projects page, so the border/
   background moves from the <li> onto the link itself (letting it lift
   together on hover), and the <li> just becomes a plain wrapper. */
.fact-list li:has(> .project-link) {
  background: none;
  border: none;
  padding: 0;
}

.project-link {
  display: block;
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.project-link:hover {
  border-color: var(--accent-light);
  transform: translateY(-2px);
}

/* Dream Team Hub: a thick green border, with padding trimmed to match so the
   card stays the same size as its neighbours. */
.project-link-featured {
  border-width: 5px;
  border-color: var(--accent);
  padding: calc(1rem - 4px) calc(1.25rem - 4px);
}

.project-link-featured:hover {
  border-color: var(--accent);
}

.project-link .project-name {
  color: var(--accent);
}

.project-coauthors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.75rem 0 1.25rem;
}

.coauthor-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  padding: 0.3rem 0.75rem 0.3rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--nav-bg);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.coauthor-chip:hover {
  border-color: var(--accent-light);
  transform: translateY(-2px);
}

.coauthor-photo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.coauthor-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-light) 35%, transparent);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 1rem;
}

.project-links:empty {
  display: none;
}

.project-links a {
  color: var(--accent);
  font-weight: 600;
}

.coauthor-name {
  font-size: 1.5rem;
  font-weight: 600;
}

.video-embed {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
  margin: 1.5rem auto;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.video-embed:empty {
  display: none;
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Project pages with a video (SnowSocial) are exactly one viewport tall:
   the video takes the space left under the text and keeps its 16:9 shape,
   shrinking to fit so the page never scrolls. */
body.project-fit {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.project-fit .content {
  min-height: 0;
}

.project-fit main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 1.5rem;
  padding-bottom: 1rem;
}

.project-fit .project-video-wrap {
  flex: 1 1 0;
  min-height: 9rem;
  container-type: size;
  margin-top: 1rem;
}

.project-fit .video-embed {
  width: min(100cqw, calc(100cqh * 16 / 9));
  max-width: none;
  margin: 0 auto;
}

.project-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
}

.project-gallery img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

@media (min-width: 641px) {
  .project-gallery > :last-child:nth-child(2n + 1) {
    grid-column: 1 / -1;
    max-width: calc((100% - 1rem) / 2);
    justify-self: center;
  }
}

@media (max-width: 640px) {
  .project-gallery {
    grid-template-columns: 1fr;
  }
}

.recipe-image {
  width: 100%;
  max-width: 420px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  margin: 1rem 0 1.5rem;
  display: block;
}

.recipe-steps {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-emoji {
  font-size: 3rem;
  line-height: 1;
  margin: 0.5rem 0 1.25rem;
}

/* Game detail pages are sized to exactly fit the viewport: the image takes
   whatever space is left under the text and scales down (never up, never
   cropped) so the whole picture is always visible without scrolling. */
body.game-page {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.game-page .content {
  min-height: 0;
}

.game-page main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 1.5rem;
  padding-bottom: 1rem;
}

.game-page .game-emoji {
  margin: 0.25rem 0 0.75rem;
}

.game-image-wrap {
  flex: 1 1 0;
  min-height: 9rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin-top: 1rem;
}

.game-image {
  display: none;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.game-image[src] {
  display: block;
}

.recipe-author {
  margin-top: 2rem;
  font-style: italic;
  color: var(--muted-text);
}

.back-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  margin-bottom: 1rem;
}

.back-link:hover {
  text-decoration: underline;
}

.placeholder-box {
  background: var(--nav-bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  color: var(--muted-text);
}

footer {
  text-align: center;
  padding: 2rem 1.5rem;
  color: #948c7a;
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  /* Phones: the top bar holds just the brand and the theme toggle; the six
     site links become an icon bar fixed to the bottom of the screen. */
  :root {
    --bottom-nav-height: 3.5rem;
  }

  body {
    flex-direction: column;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  header {
    position: sticky;
    top: 0;
    z-index: 8000;
    height: auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  nav {
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 4rem 0.75rem 1rem;
    min-height: 3.5rem;
  }

  .brand {
    margin-bottom: 0;
  }

  .nav-toggle {
    display: none;
  }

  .theme-toggle {
    position: fixed;
    top: 0.5rem;
    right: 0.75rem;
    bottom: auto;
    left: auto;
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
    box-shadow: none;
  }

  .nav-links {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    display: flex;
    flex-direction: row;
    gap: 0;
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    background: var(--nav-bg);
    border-top: 1px solid var(--border);
  }

  .nav-links li {
    flex: 1 1 0;
    min-width: 0;
  }

  .nav-links a {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--bottom-nav-height);
    padding: 0;
    width: 100%;
    border-radius: 0;
    border-left: 0;
    background: none;
    font-size: 0; /* icon only; the link text stays for screen readers */
    -webkit-tap-highlight-color: transparent;
  }

  .nav-links a::before {
    content: "";
    width: 1.65rem;
    height: 1.65rem;
    background: currentColor;
    -webkit-mask: center / contain no-repeat;
    mask: center / contain no-repeat;
  }

  .nav-links a.active {
    background: none;
  }

  /* Slimmer footer and a smaller minimum picture on short phones, so the
     one-screen game and project pages still fit above the bottom bar. */
  footer {
    padding: 1.25rem 1.5rem;
  }

  .game-image-wrap,
  .project-fit .project-video-wrap {
    min-height: 5.5rem;
  }

  .nav-links a.active::after {
    content: "";
    position: absolute;
    top: -1px;
    left: 25%;
    right: 25%;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--accent);
  }

  .nav-links a[href="/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11l9-8 9 8v9a2 2 0 0 1-2 2h-4v-7H9v7H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11l9-8 9 8v9a2 2 0 0 1-2 2h-4v-7H9v7H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E");
  }

  .nav-links a[href="/projects/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='3' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='3' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3C/svg%3E");
  }

  .nav-links a[href="/blog/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3h8l5 5v12a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z'/%3E%3Cpath d='M14 3v5h5M8.5 13h7M8.5 17h5'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3h8l5 5v12a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z'/%3E%3Cpath d='M14 3v5h5M8.5 13h7M8.5 17h5'/%3E%3C/svg%3E");
  }

  .nav-links a[href="/experience/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='7' width='18' height='13' rx='2'/%3E%3Cpath d='M9 7V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2M3 13h18'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='7' width='18' height='13' rx='2'/%3E%3Cpath d='M9 7V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2M3 13h18'/%3E%3C/svg%3E");
  }

  .nav-links a[href="/research/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5L21 21'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5L21 21'/%3E%3C/svg%3E");
  }

  .nav-links a[href="/fun/"]::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M8 14.2s1.5 2.2 4 2.2 4-2.2 4-2.2M9 9.5h.01M15 9.5h.01'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M8 14.2s1.5 2.2 4 2.2 4-2.2 4-2.2M9 9.5h.01M15 9.5h.01'/%3E%3C/svg%3E");
  }
}

/* Phones: on a game page the title and emoji share one line, lined up with
   the description's edges (JS sizes the title to fit), which frees up room
   for a bigger picture. */
@media (max-width: 640px) {
  .game-page .game-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 2.4rem;
    margin: 0.25rem 0 0;
  }

  .game-page .game-head h1 {
    margin: 0;
    font-size: 1.6rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  .game-page .game-head .game-emoji {
    margin: 0 0 0 0.5rem;
    font-size: 1.8rem;
    line-height: 1;
  }

  /* A wide picture can't grow past the screen width, so split the spare
     height above and below it instead of leaving it all at the bottom. */
  .game-page .game-image-wrap {
    margin-top: 0.75rem;
    align-items: center;
  }
}

@media (max-width: 640px) and (max-height: 700px) {
  .game-page main,
  .project-fit main {
    padding-top: 0.75rem;
    padding-bottom: 0.5rem;
  }

  .game-page .back-link,
  .project-fit .back-link {
    margin-bottom: 0.25rem;
  }

  .project-fit h1 {
    font-size: 1.6rem;
    margin: 0.25rem 0;
  }

  .game-page main p,
  .project-fit main p {
    font-size: 0.95rem;
    line-height: 1.45;
    margin-top: 0.4rem;
    margin-bottom: 0.4rem;
  }
}

/* Too short to squeeze the text and picture into one screen: let the page
   scroll instead of letting the footer sit on top of the picture. */
@media (max-width: 640px) and (max-height: 600px) {
  body.game-page,
  body.project-fit {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .game-image-wrap,
  .project-fit .project-video-wrap {
    min-height: 13rem;
  }
}

/* Phones: a lone last tile (like Chicken Noodle Soup) sits centred under the
   two-column grid, matching the wider layouts. */
@media (max-width: 640px) {
  .tile-grid > :last-child:nth-child(2n + 1) {
    grid-column: 1 / -1;
    width: calc((100% - 1rem) / 2);
    justify-self: center;
  }

  /* Home page: exactly one screen. The picture takes whatever room is left
     between the heading and the footer, so nothing scrolls. */
  body.home-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .home-page .content {
    min-height: 0;
  }

  .home-page main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-top: 1rem;
    padding-bottom: 0.5rem;
  }

  .home-page .hero {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .home-page .hero h1 {
    margin-top: 0;
  }

  .home-page .hero-img-toggle {
    flex: 1 1 0;
    min-height: 0;
    width: auto;
    max-width: 100%;
    margin: 0.75rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .home-page .hero img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
}
