/* First Words LIVE, the 3D page: cozy panels over the live Polyworld valley.
   Palette from the key art (client/shell.html): blue-hour sky, deep dusk, lantern cream and amber,
   the visitor's teal glow. Lantern-lit glass cards, rounded type, big touch targets. */
@font-face { font-family: Fraunces; src: url(art/fraunces-extrabold.woff2) format("woff2"); font-weight: 800; font-display: swap; }
@font-face { font-family: Fraunces; src: url(art/fraunces-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --sky: #13263a;
  --dusk: #0a121e;
  --glass: rgba(16, 32, 52, .94);
  --glass2: rgba(28, 51, 80, .92);
  --cream: #fff1d6;
  --muted: rgba(255, 241, 214, .74);
  --lantern: #ffc46b;
  --lantern-deep: #f0a640;
  --glow: #9ff0e0;
  --line: rgba(255, 241, 214, .16);
  --chip: #2c4a6c;
  --chip-native: #2f5a4a;
  --live: #6fe39a;
  --off: #a3acb8;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--dusk); color: var(--cream);
  font: 15px/1.4 var(--font); overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button, .btn { min-height: 44px; background: var(--chip); border: 0; border-radius: 16px; padding: 9px 15px; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; transition: transform .08s; }
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
button:disabled { opacity: .4; cursor: default; }
.primary { background: linear-gradient(180deg, var(--lantern), var(--lantern-deep)) !important; color: #3a2410 !important; }
button.small { min-height: 36px; min-width: 36px; padding: 4px 10px; border-radius: 12px; }
input, select { min-height: 44px; background: rgba(10, 18, 30, .75); border: 2px solid var(--line); border-radius: 14px; padding: 8px 12px; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--lantern); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 800; letter-spacing: .2px; margin: 0; }
svg { width: 22px; height: 22px; fill: currentColor; stroke: none; }

/* ---- the scene -------------------------------------------------------- */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: var(--sky); }
#speech { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.say { position: absolute; left: 0; top: 0; max-width: min(220px, 62vw); padding: 5px 10px 6px; border-radius: 14px;
  background: rgba(14, 26, 42, .86); border: 1px solid rgba(255, 241, 214, .18); border-bottom: 3px solid var(--pc, var(--lantern));
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35); font-size: 13.5px; line-height: 1.25; text-align: center;
  transform: translate(-50%, -100%); transition: opacity .35s; will-change: transform; }
.say::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent;
  border-top-color: var(--pc, var(--lantern)); border-bottom: 0; }
.say .w { display: inline-block; margin: 0 2px; font-weight: 700; }
.say .w i { display: block; font-size: 10.5px; font-weight: 400; font-style: italic; color: var(--lantern); line-height: 1.1; }
.say.fade { opacity: 0; }
.ripple { position: fixed; z-index: 2; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; pointer-events: none;
  border: 3px solid var(--lantern); animation: ripple .7s ease-out forwards; }
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

/* ---- top bar ---------------------------------------------------------- */
#top { position: fixed; left: 0; right: 0; top: 0; z-index: 4; padding: calc(var(--sat) + 8px) calc(var(--sar) + 12px) 10px calc(var(--sal) + 12px);
  background: linear-gradient(180deg, rgba(10, 18, 30, .78), rgba(10, 18, 30, .4) 70%, rgba(10, 18, 30, 0)); pointer-events: none; }
#top > * { pointer-events: auto; }
#top .row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-size: 21px; white-space: nowrap; text-shadow: 0 2px 12px rgba(255, 196, 107, .45); }
#top .row2 { display: flex; align-items: center; gap: 10px; margin-top: 2px; font-size: 12.5px; color: var(--muted); text-shadow: 0 1px 4px #000; }
#dayline { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lite { color: var(--lantern); text-decoration: none; border: 1px solid rgba(255, 196, 107, .5); border-radius: 999px; padding: 1px 9px;
  background: rgba(10, 18, 30, .5); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 5px 11px; font-size: 12px;
  font-weight: 700; white-space: nowrap; background: rgba(10, 18, 30, .66); }
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); flex: none; }
.pill.on { color: var(--live); box-shadow: inset 0 0 0 2px rgba(111, 227, 154, .45); }
.pill.on .dot { background: var(--live); animation: pulse 2s infinite; }
.pill.off { color: var(--off); box-shadow: inset 0 0 0 2px rgba(163, 172, 184, .3); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(111, 227, 154, .6); } 70% { box-shadow: 0 0 0 8px rgba(111, 227, 154, 0); } 100% { box-shadow: 0 0 0 0 rgba(111, 227, 154, 0); } }

/* ---- camera buttons --------------------------------------------------- */
#cams { position: fixed; z-index: 4; right: calc(var(--sar) + 10px); top: calc(var(--sat) + 70px); display: flex; flex-direction: column; gap: 8px; }
.cam { flex-direction: column; gap: 0; width: 52px; min-height: 52px; padding: 4px 0; border-radius: 16px; font-size: 10.5px; font-weight: 700;
  background: rgba(14, 26, 42, .72); color: var(--cream); box-shadow: 0 2px 8px rgba(0, 0, 0, .35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.cam svg { width: 20px; height: 20px; }
.cam.on { background: rgba(255, 196, 107, .92); color: #3a2410; }

/* ---- bottom: chat strip, my status, dock ------------------------------ */
#bottom { position: fixed; z-index: 4; left: 0; right: 0; bottom: 0; padding: 0 calc(var(--sar) + 10px) calc(var(--sab) + 8px) calc(var(--sal) + 10px);
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
  background: linear-gradient(0deg, rgba(10, 18, 30, .72), rgba(10, 18, 30, .3) 75%, rgba(10, 18, 30, 0)); padding-top: 18px; }
#bottom > * { pointer-events: auto; }
.chat { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; cursor: pointer; min-height: 0; }
.chat .line { max-width: 100%; padding: 3px 10px; border-radius: 12px; background: rgba(14, 26, 42, .7); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .4s; }
.chat .line:nth-last-child(3) { opacity: .55; }
.chat .line:nth-last-child(2) { opacity: .8; }
.chat .who { font-weight: 800; margin-right: 6px; }
.chat .sys { color: var(--glow); font-style: italic; }
.mine { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.mine::-webkit-scrollbar { display: none; }
.mine .me { padding: 6px 11px; border-radius: 14px; background: rgba(14, 26, 42, .8); font-size: 13px; white-space: nowrap; }
.mine .me b { font-weight: 800; }
.mine button { min-height: 38px; padding: 5px 12px; border-radius: 14px; font-size: 13.5px; white-space: nowrap; }
#dock { display: flex; gap: 6px; background: var(--glass); border-radius: 20px; padding: 5px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid var(--line); }
#dock button { flex: 1; flex-direction: column; gap: 1px; min-height: 50px; padding: 4px 0; border-radius: 15px; background: transparent;
  box-shadow: none; font-size: 11.5px; color: var(--muted); }
#dock button svg { width: 21px; height: 21px; }
#dock button.on { background: rgba(255, 196, 107, .16); color: var(--lantern); }
#dock button .badge { position: absolute; }

/* ---- context card (what you tapped) ----------------------------------- */
.ctx { position: fixed; z-index: 6; max-width: min(320px, calc(100vw - 20px)); padding: 10px; border-radius: 18px; background: var(--glass2);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.ctx .what { flex-basis: 100%; font-weight: 800; padding: 0 4px 2px; }
.ctx .sub { flex-basis: 100%; font-size: 12.5px; color: var(--muted); padding: 0 4px 4px; }
.ctx button { min-height: 40px; padding: 6px 12px; font-size: 14px; }

/* ---- the sheet (panels) ----------------------------------------------- */
.sheet { position: fixed; z-index: 5; left: calc(var(--sal) + 6px); right: calc(var(--sar) + 6px); bottom: calc(var(--sab) + 72px);
  height: min(60dvh, calc(100dvh - var(--sab) - 150px)); display: flex; flex-direction: column;
  background: var(--glass); border-radius: 24px; border: 1px solid var(--line);
  box-shadow: 0 -10px 34px rgba(0, 0, 0, .5); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: up .22s ease-out; }
body.sheet-open #chat, body.sheet-open #mine { display: none; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheethead { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 18px; }
.grip { position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(255, 241, 214, .3); }
.sheethead h2 { font-size: 20px; color: var(--cream); }
.close { min-height: 40px; width: 40px; padding: 0; border-radius: 50%; background: rgba(255, 241, 214, .1); box-shadow: none; }
.sheetbody { flex: 1; min-height: 0; overflow-y: auto; padding: 0 14px 14px; -webkit-overflow-scrolling: touch; }
.panel h2 { font-size: 17px; margin: 14px 0 6px; color: var(--lantern); }
.panel h3 { font-size: 16px; }
.panel p { margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row label { display: inline-flex; gap: 6px; align-items: center; }

/* talk */
.feed { max-height: 26dvh; overflow-y: auto; padding: 4px 2px; display: flex; flex-direction: column; gap: 5px; border-bottom: 1px solid var(--line); }
.entry { font-size: 14px; }
.entry.sys { color: var(--glow); font-style: italic; font-size: 13px; }
.entry .who { font-weight: 800; margin-right: 6px; }
.w { display: inline-flex; flex-direction: column; align-items: center; margin: 2px; padding: 4px 9px; border-radius: 12px; background: var(--chip);
  cursor: pointer; font-weight: 700; line-height: 1.15; user-select: none; }
.w .g { font-size: 11px; font-weight: 400; font-style: italic; color: var(--muted); }
.w.native { background: var(--chip-native); }
.w.guess .g { color: var(--lantern); }
.sentence { min-height: 54px; padding: 6px; border-radius: 16px; border: 2px dashed var(--line); margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; }
.sentence .hint { color: var(--muted); padding: 0 6px; }
#wordsearch { width: 100%; }
.cats { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0; scrollbar-width: none; }
.cats button { min-height: 36px; padding: 4px 12px; border-radius: 12px; font-size: 13px; white-space: nowrap; background: rgba(44, 74, 108, .6); box-shadow: none; }
.cats button.on { background: var(--lantern); color: #3a2410; }
.words { display: flex; flex-wrap: wrap; }
.chip.ghost { background: transparent; border: 2px solid var(--glow); color: var(--glow); box-shadow: none; min-height: 36px; padding: 4px 10px; }
.coin summary { cursor: pointer; color: var(--lantern); font-weight: 700; margin-top: 10px; }

/* wish / bench */
.grid3 { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; margin: 10px 0; }
.cell { width: 64px; height: 64px; border-radius: 14px; background: rgba(255, 241, 214, .08); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 10.5px; text-align: center; cursor: pointer; }
.cell.on { background: var(--glow); box-shadow: 0 0 14px rgba(159, 240, 224, .6); }
.cell.fill { background: rgba(255, 196, 107, .2); }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .3); margin-bottom: 2px; }

/* valley / me */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.pcard { background: rgba(255, 241, 214, .06); border-radius: 16px; padding: 10px; }
.pcard .sub { font-size: 12.5px; color: var(--muted); }
.pcard button { margin-top: 6px; width: 100%; }
.events { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.events li { background: rgba(255, 241, 214, .05); border-radius: 12px; padding: 6px 10px; }
.events .when { display: block; font-size: 11.5px; color: var(--muted); }
.events .k-coin, .events .k-grant { border-left: 3px solid var(--lantern); }
.events .k-sound, .events .k-loan { border-left: 3px solid var(--glow); }
.stats { display: flex; flex-wrap: wrap; gap: 6px; }
.stat { background: rgba(255, 241, 214, .06); border-radius: 12px; padding: 6px 10px; font-size: 12.5px; }
.stat b { display: block; font-family: Fraunces, Georgia, serif; font-size: 20px; color: var(--lantern); }
.dict { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; font-size: 13px; }
.dict td { padding: 1px 6px 1px 0; }
.dict .old { color: var(--muted); text-decoration: line-through; }

/* ---- loading card, fallback, toast, modal ------------------------------ */
.loading { position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 9vh) 20px calc(var(--sab) + 34px); background: var(--sky); transition: opacity .9s, visibility 0s linear .9s; text-align: center; }
.loading.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading .art { position: absolute; inset: -2%; background: url(3d/intro/splash-art.jpg) center 40%/cover no-repeat, var(--sky);
  animation: drift 60s ease-in-out infinite alternate; }
@media (max-aspect-ratio: 3/4) { .loading .art { background-image: url(art/splash-art-tall.jpg); background-position: center 30%; } }
.loading .shade { position: absolute; inset: 0; background: linear-gradient(to top, rgba(10, 18, 30, .85), rgba(10, 18, 30, .2) 30%, rgba(10, 18, 30, .25) 70%, rgba(10, 18, 30, .7)); }
.loading .title { position: relative; }
.loading h1 { font-size: clamp(40px, 9vw, 72px); text-shadow: 0 0 28px rgba(255, 196, 107, .6), 0 4px 16px rgba(8, 16, 30, .7); }
.loading p { margin: 4px 0 0; font-family: Fraunces, Georgia, serif; font-style: italic; font-size: clamp(16px, 2.2vw, 22px); text-shadow: 0 2px 10px rgba(8, 16, 30, .9); }
.loading .load { position: relative; width: min(480px, 86vw); }
.bar { height: 6px; border-radius: 6px; background: rgba(10, 18, 30, .6); box-shadow: inset 0 0 0 1px rgba(255, 241, 214, .28); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--lantern), #ffe3a8); box-shadow: 0 0 14px var(--lantern);
  transform-origin: 0 50%; transform: scaleX(0); transition: transform .45s ease; }
.stage { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 15px; text-shadow: 0 1px 4px #000; }
.stage span { font-style: italic; color: var(--muted); }
@keyframes drift { from { transform: scale(1); } to { transform: scale(1.05) translate(-.9%, -.6%); } }
@media (max-height: 500px) { .loading { padding-top: calc(var(--sat) + 4vh); } .loading h1 { font-size: 38px; } }
.fallback { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 18, 30, .82); }
.card { width: min(560px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--glass2); border-radius: 22px; padding: 18px;
  border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(0, 0, 0, .6); }
.card h2 { font-size: 22px; margin-bottom: 6px; }
.card.hero .tagline { font-family: Fraunces, Georgia, serif; font-style: italic; color: var(--lantern); margin-top: 0; }
.modal { position: fixed; inset: 0; z-index: 7; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(10, 18, 30, .6); }
.toast { position: fixed; z-index: 9; left: 50%; top: calc(var(--sat) + 74px); transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: rgba(10, 18, 30, .92); border: 1px solid rgba(255, 196, 107, .5); color: var(--cream); padding: 9px 16px; border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); font-size: 14px; text-align: center; }

/* ---- landscape phones: compact top, dock and sheet on the right -------- */
@media (max-height: 500px) and (orientation: landscape) {
  #top { padding-top: calc(var(--sat) + 4px); padding-bottom: 6px; display: flex; align-items: center; gap: 14px; }
  #top .row1 { justify-content: flex-start; gap: 12px; flex: none; }
  .brand { font-size: 18px; }
  #top .row2 { flex: 1; min-width: 0; margin: 0; justify-content: flex-end; }
  #dayline { flex: 0 1 auto; }
  #cams { top: calc(var(--sat) + 44px); flex-direction: column; }
  .cam { min-height: 44px; width: 48px; }
  #bottom { right: auto; width: min(440px, 46vw); }
  body.sheet-open #chat, body.sheet-open #mine { display: flex; }
  #dock button { min-height: 42px; font-size: 10.5px; }
  #dock button svg { width: 18px; height: 18px; }
  .chat .line:nth-last-child(3) { display: none; }
  .sheet { left: auto; top: calc(var(--sat) + 6px); right: calc(var(--sar) + 6px); bottom: calc(var(--sab) + 6px); width: min(430px, 50vw);
    height: auto; }
  .feed { max-height: 34dvh; }
  body.sheet-open #cams { right: calc(var(--sar) + min(430px, 50vw) + 16px); }
}
@media (min-width: 900px) and (min-height: 501px) {
  #bottom { right: auto; width: 460px; }
  .sheet { left: auto; top: 80px; right: 12px; bottom: 12px; width: 440px; height: auto; }
  body.sheet-open #chat, body.sheet-open #mine { display: flex; }
  body.sheet-open #cams { right: 470px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
