:root {
  --ink: #3a332b; --muted: #8a8174; --paper: #f6f3ec; --glass: rgba(250, 247, 240, .82);
  --line: rgba(110, 100, 130, .22); --hover: rgba(110, 100, 130, .1); --accent: #6a52a8; --frame: #e2b73c;
  --shadow: 0 10px 30px rgba(60, 48, 30, .16), 0 2px 6px rgba(60, 48, 30, .1);
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gutter: 24px; --bottom: max(18px, env(safe-area-inset-bottom));
}
body.night {
  --ink: #efe7d8; --muted: #a79f92; --paper: #1d1f26; --glass: rgba(24, 26, 33, .8);
  --line: rgba(230, 220, 200, .14); --hover: rgba(230, 220, 200, .08); --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #edebe6; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body.night { background: #0b0d12; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
#app canvas { display: block; touch-action: none; }

/* ---------- title ---------- */
.title { position: fixed; left: var(--gutter); top: 20px; z-index: 5; pointer-events: none; user-select: none; transition: opacity .4s; }
.title h1 { margin: 0; font: 600 clamp(20px, 3.1vw, 30px)/1.1 var(--serif); letter-spacing: .2em; }
.title h1 a { color: inherit; text-decoration: none; pointer-events: auto; }
.title h1 a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }
#help .fine a { color: inherit; }
.title p { margin: 7px 0 0; font-size: 11px; letter-spacing: .2em; color: var(--muted); text-transform: uppercase; }
.title .short { display: none; }

/* ---------- control bars ---------- */
#dock, #views {
  position: fixed; z-index: 10; display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 16px;
  background: var(--glass); -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity .35s;
}
#dock { left: 50%; bottom: var(--bottom); transform: translateX(-50%); }
#views { right: var(--gutter); top: 18px; }
.grp { display: flex; align-items: center; gap: 2px; }
.grp + .grp { border-left: 1px solid var(--line); padding-left: 6px; margin-left: 2px; }
#dock button, #views button {
  appearance: none; border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 11px; border-radius: 11px;
  font: 500 12.5px/1 var(--sans); color: var(--ink); transition: background .15s, color .15s;
}
#dock button:hover, #views button:hover { background: var(--hover); }
#dock button[aria-pressed="true"], #views button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
#dock svg, #views svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#b-sound .mute { display: none; }
#b-sound[aria-pressed="false"] .wave { display: none; }
#b-sound[aria-pressed="false"] .mute { display: inline; }
.time input[type=range] { width: 118px; accent-color: var(--accent); cursor: pointer; }
.time output { min-width: 64px; font: 500 12px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }

#dock #pivot {
  margin-left: 6px; background: var(--accent); color: #fff8e4; padding: 10px 17px; border-radius: 11px;
  font: 600 13.5px/1 var(--serif); letter-spacing: .16em; box-shadow: inset 0 0 0 2px var(--frame), 0 6px 16px rgba(80, 55, 140, .32);
  transition: transform .12s ease, box-shadow .2s, background .15s;
}
#dock #pivot:hover { background: #765db8; transform: translateY(-1px); }
#dock #pivot:active { transform: scale(.96); }

#hint {
  position: fixed; left: var(--gutter); top: 86px; z-index: 5; margin: 0; max-width: 40vw;
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); pointer-events: none; transition: opacity .8s;
}
#hint.gone { opacity: 0; }

/* ---------- info card, tooltip, bubbles ---------- */
#card {
  position: fixed; left: var(--gutter); bottom: calc(var(--bottom) + 70px); z-index: 12; width: min(330px, calc(100vw - 2 * var(--gutter)));
  padding: 16px 44px 17px 18px; border-radius: 14px; background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
#card h2 { margin: 0 0 6px; font: 600 17px/1.2 var(--serif); }
#card p { margin: 0; font-size: 13.5px; line-height: 1.45; opacity: .86; }
.x { position: absolute; right: 8px; top: 8px; width: 30px; height: 30px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); }
.x:hover { background: var(--hover); color: var(--ink); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

#tip { position: fixed; left: 0; top: 0; z-index: 13; pointer-events: none; padding: 6px 9px; border-radius: 8px; background: var(--ink); color: var(--paper); font: 500 12px var(--sans); white-space: nowrap; }
#bubbles { position: fixed; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.bubble {
  position: absolute; left: 0; top: 0; padding: 9px 13px; border-radius: 14px; background: #fffdf8; color: #2b251e;
  font: italic 500 15px/1.25 var(--serif); white-space: nowrap; box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
  opacity: 0; transition: opacity .25s; margin-top: -10px;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: #fffdf8; }
.bubble.in { opacity: 1; }

/* ---------- walk ---------- */
#walk-ui { position: fixed; inset: 0; z-index: 14; pointer-events: none; }
#walk-ui .cross { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); transition: transform .15s; }
#walk-ui .cross.on { transform: scale(1.8); border-color: #ffd08a; }
.walk-help { position: absolute; left: 50%; top: 22px; transform: translateX(-50%); margin: 0; padding: 9px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow); }
#walk-exit, #sitcom-exit {
  position: absolute; right: var(--gutter); top: 18px; pointer-events: auto; cursor: pointer; border: 1px solid var(--line);
  background: var(--glass); padding: 10px 15px; border-radius: 11px; font: 500 12.5px var(--sans); box-shadow: var(--shadow);
}
#joy { position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: rgba(0, 0, 0, .12); display: none; }
#joy span { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255, 255, 255, .8); }
#joy.on { display: block; }

/* ---------- sitcom ---------- */
#sitcom-ui { position: fixed; inset: 0; z-index: 14; pointer-events: none; color: #e9e2d2; font: 600 12px var(--sans); letter-spacing: .16em; }
#sitcom-ui .live, #sitcom-ui #camlabel { position: absolute; bottom: 22px; }
#sitcom-ui .live { left: var(--gutter); }
#sitcom-ui #camlabel { left: calc(var(--gutter) + 72px); opacity: .7; }
#sitcom-ui .live i { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #e0352a; animation: blink 1.4s infinite; }
#sitcom-exit { color: #e9e2d2; background: rgba(20, 20, 22, .6); border-color: rgba(255, 255, 255, .15); }
@keyframes blink { 50% { opacity: .25; } }
body.sitcom .title, body.sitcom #views, body.sitcom #hint, body.sitcom #card, body.sitcom #dock .grp { display: none; }
body.sitcom #dock { background: rgba(20, 20, 22, .55); border-color: rgba(255, 255, 255, .12); }
body.walking .title, body.walking #hint, body.walking #views, body.walking #dock { opacity: 0; pointer-events: none; }

/* ---------- help ---------- */
#help {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 22px 24px 18px; border-radius: 16px; background: var(--glass); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise .2s ease-out;
}
#help h2 { margin: 0 0 12px; font: 600 20px var(--serif); }
#help dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 13.5px; line-height: 1.4; }
#help dt { font-weight: 600; white-space: nowrap; }
#help dd { margin: 0; opacity: .86; }
#help .fine { margin: 16px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }

/* ---------- loader, errors ---------- */
#loader { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: #f3f1ec; transition: opacity .9s ease; text-align: center; }
#loader h1 { margin: 0; font: 600 clamp(22px, 4vw, 34px) var(--serif); letter-spacing: .24em; color: #3c362e; }
#loader p { margin: 12px 0 0; font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: #8a8174; animation: breathe 1.8s ease-in-out infinite; }
.failed #loader p { animation: none; color: #7e2c22; letter-spacing: .06em; text-transform: none; font-size: 14px; }
body.ready #loader { opacity: 0; pointer-events: none; }
@keyframes breathe { 50% { opacity: .45; } }
#err { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 50; max-width: 80vw; padding: 8px 14px; border-radius: 8px; background: #7e2c22; color: #fff; font: 12px ui-monospace, Menlo, monospace; }
#flash { position: fixed; inset: 0; z-index: 25; background: #fff; pointer-events: none; animation: flash .45s ease-out forwards; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }

body.clean .title, body.clean #dock, body.clean #views, body.clean #hint, body.clean #card, body.clean #tip { display: none !important; }

/* ---------- narrow screens ---------- */
@media (max-width: 1180px) { #views span { display: none; } #views button { padding: 9px; } }
@media (max-width: 860px) { #dock .modes span { display: none; } #dock .modes button { padding: 9px; } }
@media (max-width: 640px) {
  :root { --gutter: 12px; --bottom: max(10px, env(safe-area-inset-bottom)); }
  .title { top: 14px; left: 16px; }
  .title .full { display: none; }
  .title .short { display: inline; }
  .title p { letter-spacing: .14em; }
  #views { left: 12px; right: 12px; top: 72px; justify-content: space-between; }
  #views .grp { width: 100%; justify-content: space-between; }
  #hint { top: 128px; left: 16px; max-width: none; font-size: 10px; }
  #dock { left: 12px; right: 12px; transform: none; flex-wrap: wrap; justify-content: space-between; row-gap: 4px; }
  .grp + .grp { border-left: 0; padding-left: 0; margin-left: 0; }
  .grp.time { width: 100%; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
  .time input[type=range] { flex: 1; width: auto; }
  #dock #pivot { margin-left: auto; padding: 10px 14px; font-size: 12.5px; }
  #card { bottom: calc(var(--bottom) + 116px); }
  #sitcom-ui #camlabel { left: calc(var(--gutter) + 64px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
