:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f6fb, #0a0e1a);
  --panel: light-dark(#ffffff, #121a2e);
  --ink: light-dark(#141a2b, #f3f5fb);
  --muted: light-dark(#4d5670, #b4bdd4);
  --line: light-dark(#dbe1ee, #263152);
  --accent: light-dark(#3b5bdb, #8ea8ff);
  --accent-ink: light-dark(#ffffff, #0a0e1a);
  --halo: light-dark(rgba(244,246,251,.6), rgba(10,14,26,.5));
}
/* Safari before 17.5 has no light-dark(): give it plain colors so the page isn't blank white */
@supports not (color: light-dark(#000, #fff)) {
  :root { --bg: #f4f6fb; --panel: #ffffff; --ink: #141a2b; --muted: #4d5670; --line: #dbe1ee; --accent: #3b5bdb; --accent-ink: #ffffff; --halo: rgba(244,246,251,.6); }
  @media (prefers-color-scheme: dark) {
    :root { --bg: #0a0e1a; --panel: #121a2e; --ink: #f3f5fb; --muted: #b4bdd4; --line: #263152; --accent: #8ea8ff; --accent-ink: #0a0e1a; --halo: rgba(10,14,26,.5); }
  }
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }
* { box-sizing: border-box; min-width: 0; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  overflow-x: clip;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Hero */
.hero { position: relative; height: 100vh; height: 100svh; min-height: 480px; overflow: hidden; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-text {
  position: relative; z-index: 1; height: 100%;
  display: grid; place-items: center; text-align: center; padding: 2rem;
  pointer-events: none;
  text-shadow: 0 0 6px var(--bg), 0 0 18px var(--bg), 0 0 36px var(--bg);
}
.hero h1 { margin: 0; font-size: clamp(2rem, 6.5vw, 3.75rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; text-wrap: balance; }
.name { position: relative; display: inline-block; }
.thermo {
  position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 1.25rem;
  display: flex; align-items: center; gap: .4rem; pointer-events: auto; text-shadow: none; white-space: nowrap;
}
.thermo[hidden] { display: none; }
/* While the BaTiO3 controls are in use, clear the name and profile links so the structure shows */
.hero h1, .hero .links { transition: opacity .35s, visibility .35s; }
.hero.focus h1, .hero.focus .links { opacity: 0; visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .hero h1, .hero .links { transition: none; } }
.treading { display: grid; justify-items: center; min-width: 4.6rem; line-height: 1.15; }
.tval { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); transition: color .3s; }
.tval.hot { color: #ff7a2f; }
.tval.cold { color: light-dark(#1c74d9, #6cb8ff); }
.tphase { font-size: .75rem; color: var(--muted); }
.tnote { font-size: .65rem; color: var(--muted); opacity: .75; }
.tbtn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0;
  border: 1px solid var(--line); background: light-dark(rgba(255,255,255,.75), rgba(18,26,46,.65));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: box-shadow .2s, border-color .2s;
}
.tbtn svg { width: 22px; height: 22px; pointer-events: none; }
.tbtn.heat { color: #ff7a2f; border-color: rgba(255,122,47,.6); }
.tbtn.cool { color: light-dark(#1c74d9, #6cb8ff); }
.tbtn.heat:not(.used) { animation: ember 1.6s ease-in-out infinite; }
.tbtn.heat.on { box-shadow: 0 0 22px 4px rgba(255,110,30,.75); border-color: #ff7a2f; }
.tbtn.cool.on { box-shadow: 0 0 22px 4px rgba(80,160,255,.7); border-color: #6cb8ff; }
.tbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes ember { 0%, 100% { box-shadow: 0 0 6px 0 rgba(255,110,30,.35); } 50% { box-shadow: 0 0 20px 4px rgba(255,110,30,.8); } }
@media (prefers-reduced-motion: reduce) { .tbtn.heat:not(.used) { animation: none; box-shadow: 0 0 14px 2px rgba(255,110,30,.6); } }
@media (max-width: 900px) {
  .name { display: block; position: static; }
  /* Sit in the empty band at the top of the hero, above the spinning structure */
  .thermo { top: max(1.25rem, env(safe-area-inset-top), calc(50% - 55vw - 2.5rem)); left: 50%; transform: translateX(-50%); margin: 0; }
}
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem; margin-top: 1.5rem; pointer-events: auto; text-shadow: none; }
.pill {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .6rem 1.3rem;
  border-radius: 999px; border: 1px solid var(--line); text-decoration: none; font-weight: 500;
  background: light-dark(rgba(255,255,255,.7), rgba(18,26,46,.6)); color: var(--ink);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.pill:hover { border-color: var(--accent); color: var(--accent); }
.crystals { position: absolute; z-index: 2; left: 1rem; bottom: 1rem; font-size: .85rem; color: var(--muted); }
.crystals p { margin: 0 0 .3rem .5rem; }
.crystals .bar { text-decoration: overline; }
.crystals ul { list-style: none; margin: 0; padding: 0; }
.crystals button {
  font: inherit; color: var(--muted); background: transparent; border: 0; border-radius: 8px;
  padding: .3rem .5rem; min-height: 32px; cursor: pointer; text-align: left; opacity: .8;
  transition: color .2s, background-color .2s, opacity .2s;
}
.crystals button:hover { opacity: 1; color: var(--ink); }
.crystals button[aria-pressed="true"] {
  opacity: 1; color: light-dark(#0a0e1a, #ffffff); font-weight: 600;
  background: light-dark(rgba(255,255,255,.75), rgba(255,255,255,.1));
  text-shadow: 0 0 14px light-dark(rgba(255,255,255,0), rgba(255,255,255,.45));
}
.crystals .star { font-style: normal; margin-left: .3rem; color: #f5b82e; text-shadow: 0 0 8px rgba(245,184,46,.55); }
/* InSb doping tabs, above the structure */
.dope {
  position: absolute; z-index: 2; left: 50%; transform: translateX(-50%);
  top: max(1.25rem, env(safe-area-inset-top)); display: grid; justify-items: center; gap: .45rem;
}
.dope[hidden] { display: none; }
.seg {
  display: flex; gap: .25rem; padding: .25rem; border-radius: 999px; border: 1px solid var(--line);
  background: light-dark(rgba(255,255,255,.75), rgba(18,26,46,.65));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.seg button {
  font: inherit; font-size: .95rem; font-weight: 500; color: var(--muted); background: transparent;
  border: 0; border-radius: 999px; padding: .5rem 1.1rem; min-height: 40px; cursor: pointer; white-space: nowrap;
  transition: color .25s, background-color .25s, box-shadow .25s;
}
.seg button:hover { color: var(--ink); }
.seg button[data-k="0"][aria-selected="true"] { background: light-dark(#1d8f60, #34c68a); color: light-dark(#ffffff, #0a0e1a); font-weight: 600; }
.seg button[data-k="1"][aria-selected="true"] { background: #d43aa8; color: #ffffff; font-weight: 600; box-shadow: 0 0 22px 4px rgba(255,70,200,.6); }
.seg button[data-k="1"]:not(.used) { animation: nickel 1.8s ease-in-out infinite; }
@keyframes nickel { 0%, 100% { box-shadow: 0 0 4px 0 rgba(255,70,200,.3); } 50% { box-shadow: 0 0 18px 3px rgba(255,70,200,.75); } }
@media (prefers-reduced-motion: reduce) { .seg button[data-k="1"]:not(.used) { animation: none; } }
.dnote {
  position: relative; margin: 0; width: min(34rem, calc(100vw - 2rem)); font-size: .8rem; line-height: 1.45;
  color: var(--muted); text-align: center; text-wrap: balance; text-shadow: 0 0 6px var(--bg), 0 0 14px var(--bg);
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s;
}
.dnote.on { opacity: 1; visibility: visible; transition: opacity .6s 2.8s, visibility 0s 2.8s; }
@media (prefers-reduced-motion: reduce) { .dnote.on { transition: none; } }
.dnote b { color: var(--ink); font-weight: 600; }
.dnote .rtext { display: none; }
.dnote.real .atext { display: none; }
.dnote.real .rtext { display: inline; }
.reality {
  font: inherit; font-size: .9rem; font-weight: 600; min-height: 40px; padding: .5rem 1.3rem; cursor: pointer;
  border-radius: 999px; border: 1px solid rgba(255,70,200,.55); color: var(--ink);
  background: light-dark(rgba(255,255,255,.75), rgba(18,26,46,.65));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s, box-shadow .25s, background-color .25s;
}
.reality.on { opacity: 1; visibility: visible; transition: opacity .6s 3.2s, visibility 0s 3.2s, box-shadow .25s, background-color .25s; }
.reality.on:not(.used) { animation: nickel 1.8s 3.2s ease-in-out infinite; }
.reality:hover { background: rgba(255,70,200,.18); }
.reality[aria-pressed="true"] { background: #d43aa8; color: #ffffff; border-color: #d43aa8; }
.reality:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .reality.on { transition: none; } .reality.on:not(.used) { animation: none; } }
.cite {
  font: inherit; font-size: .7rem; font-weight: 600; line-height: 1; vertical-align: super; cursor: pointer;
  margin-left: .15rem; padding: .1rem .3rem; border-radius: 5px; border: 1px solid rgba(255,70,200,.5);
  color: light-dark(#b0268a, #ff8ae0); background: rgba(255,70,200,.12); text-shadow: none;
}
.cite:hover, .cite[aria-expanded="true"] { background: rgba(255,70,200,.28); }
.cref {
  position: absolute; left: 50%; top: calc(100% + .6rem); transform: translate(-50%, -4px);
  width: min(24rem, calc(100vw - 2rem)); padding: .9rem 1.1rem; text-align: left; text-shadow: none;
  border-radius: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
  opacity: 0; visibility: hidden; transition: opacity .2s, transform .2s, visibility .2s;
}
.cref::before { content: ""; position: absolute; left: 50%; top: -6px; width: 10px; height: 10px; transform: translateX(-50%) rotate(45deg); background: var(--panel); border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.cref.open { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
@media (hover: hover) { .cite:hover + .cref, .cref:hover { opacity: 1; visibility: visible; transform: translate(-50%, 0); } }
.cref .num { display: block; font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .35rem; }
.cref a { display: block; font-size: .95rem; font-weight: 600; font-style: italic; line-height: 1.3; color: var(--accent); text-decoration: none; }
.cref a:hover { text-decoration: underline; }
.cref .by { display: block; margin-top: .3rem; font-size: .85rem; }
.cref .pub { display: block; margin-top: .15rem; font-size: .78rem; color: var(--muted); }
@media (max-width: 560px) {
  .crystals { left: .5rem; bottom: .5rem; font-size: .8rem; }
  /* Short scrolling list: two items in full view, the third peeking out */
  .crystals ul {
    max-height: 96px; overflow-y: auto; overscroll-behavior: contain;
    scroll-snap-type: y proximity; scrollbar-width: none;
  }
  .crystals ul::-webkit-scrollbar { display: none; }
  /* Soft fade at whichever edge has more items beyond it, instead of a hard clip */
  .crystals ul {
    --ft: 0px; --fb: 0px;
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.2) 0, #000 var(--ft), #000 calc(100% - var(--fb)), rgba(0,0,0,.2) 100%);
    mask-image: linear-gradient(to bottom, rgba(0,0,0,.2) 0, #000 var(--ft), #000 calc(100% - var(--fb)), rgba(0,0,0,.2) 100%);
  }
  .crystals li { scroll-snap-align: start; }
  .crystals li { transition: filter .15s, opacity .15s; }
  .hero .cue { left: auto; right: .75rem; transform: none; }
}
.cue {
  position: absolute; z-index: 2; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; color: var(--muted); text-decoration: none;
}
.cue svg { width: 22px; height: 22px; }

/* Apps */
.apps { max-width: 56rem; margin: 0 auto; padding: clamp(3rem, 8vw, 6rem) 1.5rem 5rem; scroll-margin-top: 0; }
.switch { display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem; }
.tab {
  font: inherit; font-weight: 600; font-size: 1.25rem;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 1rem 2rem; min-height: 56px; cursor: pointer;
  transition: font-size .35s ease, padding .35s ease, background-color .2s, color .2s;
}
.tab:hover { border-color: var(--accent); }
.switch.chosen { align-items: center; }
.switch.chosen .tab { order: 2; font-size: 1rem; padding: .6rem 1.25rem; min-height: 44px; }
.switch.chosen .tab[aria-selected="true"] {
  order: 1; flex-basis: 100%;
  font-size: clamp(1.9rem, 5vw, 2.75rem); letter-spacing: -0.02em;
  padding: 1.1rem 1.5rem;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  cursor: default;
}
@media (prefers-reduced-motion: reduce) { .tab { transition: none; } }

.panel { margin-top: 2.5rem; }
.panel[hidden] { display: none; }
.panel.show { animation: rise .4s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .panel.show { animation: none; } }

.app {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: clamp(1.25rem, 4vw, 2rem);
}
.app + .app { margin-top: 1.25rem; }
.app-head { display: flex; align-items: center; gap: 1rem; }
.app-head .icon { width: 72px; height: 72px; border-radius: 22%; flex: none; box-shadow: 0 1px 0 var(--line); }
.app h3 { margin: 0; font-size: 1.6rem; line-height: 1.15; letter-spacing: -0.01em; }
.app .where { margin: .25rem 0 0; color: var(--muted); font-size: .95rem; }
.app p.lead { margin: 1rem 0 0; max-width: 40rem; }
.app ul { margin: 1rem 0 0; padding-left: 1.2rem; max-width: 40rem; }
.app li + li { margin-top: .35rem; }
.app .note { margin: 1rem 0 0; font-size: .9rem; color: var(--muted); max-width: 40rem; }
.go {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  margin-top: 1.5rem; min-height: 48px; padding: .75rem 1.4rem;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; text-decoration: none;
}
.go:hover { filter: brightness(1.08); }
.go.soon { background: transparent; color: var(--muted); border: 1px dashed var(--line); cursor: default; }

footer { text-align: center; color: var(--muted); font-size: .9rem; padding: 0 1.5rem 3rem; }

/* Buy Me a Coffee link, between the app tabs and the app cards */
.coffee { display: flex; justify-content: center; margin: 1.25rem 0 0; }
.coffee a {
  display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; padding: .55rem 1.2rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font-weight: 600; text-decoration: none; transition: border-color .2s, background-color .2s;
}
.coffee a:hover { border-color: #f5b82e; background: rgba(245,184,46,.12); }
.coffee a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.coffee svg { width: 20px; height: 20px; color: #f5b82e; }
