@import url("https://fonts.googleapis.com/css2?family=Caveat:wght@500;700&family=Geist:wght@400;500;600;700&display=swap");

/* Wrong Number: the scene is one canvas (#scene). Everything you read or press is plain DOM on top of it. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --ink: #f0e6d0;
  --panel: rgba(20, 24, 20, 0.78);
  --line: rgba(240, 225, 190, 0.2);
  --accent: #c9d77a;
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
}

*,*::before,*::after { box-sizing: border-box; }
html, body {
  -webkit-tap-highlight-color: transparent; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font); color: var(--ink); touch-action: none; background: #0f1d21; }

canvas { display: block; position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; z-index: 1; }
#scene.is-grab { cursor: grab; }
#scene.is-pick { cursor: pointer; }

.bar {
  position: fixed; z-index: 6; left: 50%; top: max(12px, var(--st)); transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.pill, .bar .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font);
  display: inline-flex; align-items: center; gap: 7px; height: 36px; margin: 0; padding: 0 14px 0 12px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; opacity: 1;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 6px 16px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease; touch-action: manipulation;
}
.pill svg { width: 15px; height: 15px; flex: none; }
.pill__n { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; font-size: 0.7rem; color: #14190a; background: var(--accent); }
.pill.is-new .pill__n { animation: pop 0.7s ease 2; }
@keyframes pop { 50% { transform: scale(1.35); } }
.pill:hover, .bar .opt-share.opt-share:hover { background: rgba(36, 42, 30, 0.92); border-color: rgba(240, 225, 190, 0.38); text-decoration: none; }
.pill:active, .bar .opt-share.opt-share:active { transform: scale(0.96); }
.pill:focus-visible, .bar .opt-share.opt-share:focus-visible, .sound-btn:focus-visible, .okbtn:focus-visible, .sheet__x:focus-visible, .book button:focus-visible { outline: 2px dashed rgba(220, 235, 150, 0.95); outline-offset: 2px; }
.share-host { display: inline-flex; }
.share-host:empty { display: none; }

.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0;
  top: max(12px, var(--st)); right: max(12px, var(--sr));
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); transition: transform 0.12s ease, opacity 0.15s ease;
}
.sound-btn:active { transform: scale(0.94); }
.sound-btn[aria-pressed="false"] { opacity: 0.55; }
.sound-btn[aria-pressed="false"] .sound-btn__wave { opacity: 0; }

.frame { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.frame__corner {
  position: absolute; font-size: clamp(0.58rem, 1.2vw, 0.7rem); font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase;
  color: rgba(240, 230, 205, 0.55); white-space: nowrap; font-family: var(--font); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
.frame__corner--tl { top: calc(max(12px, var(--st)) + 13px); left: max(18px, var(--sl)); }
.frame__corner--tr { top: calc(max(12px, var(--st)) + 13px); right: calc(max(12px, var(--sr)) + 54px); }
.frame__corner--bl { bottom: max(18px, var(--sb)); left: max(18px, var(--sl)); }
.frame__corner a { color: inherit; text-decoration: none; pointer-events: auto; border-bottom: 1px solid transparent; transition: color .14s, border-color .14s; }
.frame__corner a:hover { color: #fff3d0; border-bottom-color: rgba(255, 243, 208, 0.5); }

.hint {
  position: fixed; top: calc(max(12px, var(--st)) + 48px); left: 50%; transform: translateX(-50%);
  width: min(88vw, 560px); margin: 0; text-align: center; z-index: 9; pointer-events: none;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; line-height: 1.6;
  color: rgba(245, 232, 200, 0.74); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.95); transition: opacity .45s;
}
.hint.is-hidden { opacity: 0; }

/* the subtitles: what the other end is saying */
.subs {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%); bottom: calc(max(var(--sb), 10px) + 64px);
  width: min(92vw, 520px); display: flex; justify-content: center; pointer-events: none; min-height: 0;
}
.subs__line {
  display: inline-block; max-width: 100%; margin: 0; padding: 9px 16px 10px; border-radius: 14px; text-align: center;
  font-size: clamp(0.92rem, 3.6vw, 1.06rem); font-weight: 500; line-height: 1.38; letter-spacing: 0.005em; color: #fff6dc;
  background: rgba(14, 16, 12, 0.82); border: 1px solid rgba(240, 225, 190, 0.18); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); animation: subin 0.22s ease-out;
}
.subs__line.is-act { font-style: italic; color: #d9d4bd; }
.subs__line.is-end { color: rgba(255, 246, 220, 0.62); }
@keyframes subin { from { opacity: 0; transform: translateY(6px); } }

.toast {
  position: fixed; z-index: 11; left: 50%; top: calc(max(12px, var(--st)) + 92px); transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  padding: 7px 14px; border-radius: 999px; font-size: 0.74rem; font-weight: 600; letter-spacing: 0.02em; color: #14190a; background: var(--accent); white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45); transition: opacity 0.3s, transform 0.3s; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* dialogs */
.sheet { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: max(14px, var(--st)) max(14px, var(--sr)) max(14px, var(--sb)) max(14px, var(--sl)); background: rgba(6, 10, 10, 0.62); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); touch-action: manipulation; }
.sheet[hidden] { display: none; }
.sheet__card {
  width: min(100%, 440px); max-height: min(100%, 640px); display: flex; flex-direction: column; padding: 18px 18px 16px; border-radius: 18px;
  color: #f4ead2; background: linear-gradient(180deg, #243026, #172019); border: 1px solid rgba(240, 225, 190, 0.2); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65);
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet h2 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }
.sheet__x { appearance: none; border: 0; background: rgba(255, 255, 255, 0.08); color: inherit; width: 34px; height: 34px; border-radius: 50%; font-size: 1.3rem; line-height: 1; cursor: pointer; }
.sheet__sub { margin: 4px 0 10px; font-size: 0.78rem; color: rgba(244, 234, 210, 0.66); }
.book { list-style: none; margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.book li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; padding: 9px 2px; border-top: 1px dashed rgba(240, 225, 190, 0.2); }
.book li:first-child { border-top: 0; }
.book__name { font-weight: 600; font-size: 0.92rem; }
.book__note { grid-column: 1; font-size: 0.76rem; color: rgba(244, 234, 210, 0.6); }
.book__num { grid-column: 2; grid-row: 1; font-family: "Caveat", cursive; font-size: 1.35rem; font-weight: 700; color: var(--accent); letter-spacing: 0.04em; }
.book button { grid-column: 2; grid-row: 2; justify-self: end; appearance: none; border: 1px solid rgba(240, 225, 190, 0.3); background: transparent; color: #f4ead2; border-radius: 999px; font: 600 0.7rem var(--font); padding: 4px 10px; cursor: pointer; }
.book button:hover { background: rgba(255, 255, 255, 0.1); }
.book__empty { display: block !important; padding: 18px 2px !important; font-size: 0.9rem; color: rgba(244, 234, 210, 0.75); }
.sheet__card--calm { width: min(100%, 400px); text-align: left; background: linear-gradient(180deg, #f6ecd0, #ece0bd); color: #2a2a22; border-color: rgba(60, 50, 30, 0.2); }
.sheet__card--calm h2 { font-size: 1.15rem; line-height: 1.3; }
.sheet__card--calm p { margin: 10px 0 16px; font-size: 0.95rem; line-height: 1.55; }
.okbtn { appearance: none; align-self: flex-start; border: 0; border-radius: 999px; padding: 10px 22px; font: 700 0.9rem var(--font); color: #14190a; background: #b9c95f; cursor: pointer; }
.okbtn:active { transform: scale(0.97); }

.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, var(--sb)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: max(14px, var(--sb)); right: calc(max(14px, var(--sr)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

@media (max-width: 900px) {
  .bar { top: calc(max(12px, var(--st)) + 44px); }
  .hint { top: calc(max(12px, var(--st)) + 92px); }
  .toast { top: calc(max(12px, var(--st)) + 130px); }
}
@media (max-width: 520px) { .hint { width: 96vw; letter-spacing: 0.07em; font-size: 0.6rem; } }
@media (max-width: 380px) { .pill, .bar .opt-share.opt-share { font-size: 0.72rem; padding: 0 11px 0 10px; gap: 6px; } .bar { gap: 6px; } }
@media (orientation: landscape) and (max-height: 500px) and (min-width: 700px) {
  .bar { top: max(10px, var(--st)); }
  .hint { top: calc(max(10px, var(--st)) + 46px); }
  .toast { top: calc(max(10px, var(--st)) + 50px); }
  .sheet__card { max-height: 100%; padding: 14px 16px 12px; }
  .sheet__card--calm p { margin: 6px 0 12px; font-size: 0.88rem; line-height: 1.45; }
  .sheet__card--calm h2 { font-size: 1.02rem; }
}
@media (prefers-reduced-motion: reduce) { .pill, .sound-btn, .hint, .bar .opt-share.opt-share, .toast { transition: none; } .subs__line, .pill.is-new .pill__n { animation: none; } }
@media (orientation: landscape) and (max-height: 500px) { .subs__line { font-size: 0.82rem; padding: 7px 12px 8px; line-height: 1.3; } }
