@font-face { font-family: "QB Caveat"; src: url("assets/fonts/web/caveat.woff") format("woff"); font-weight: 500; font-display: swap; }
@font-face { font-family: "QB Cedarville"; src: url("assets/fonts/web/cedarville.woff") format("woff"); font-display: swap; }
@font-face { font-family: "QB Oswald"; src: url("assets/fonts/web/oswald.woff") format("woff"); font-display: swap; }
@font-face { font-family: "QB Kalam"; src: url("assets/fonts/web/kalam.woff") format("woff"); font-display: swap; }

:root {
  --glass: rgba(24, 18, 13, 0.62);
  --glass-strong: rgba(30, 23, 17, 0.9);
  --line: rgba(255, 236, 205, 0.12);
  --text: #f3e9d8;
  --muted: #b5a48a;
  --brass: #d8ad55;
  --brass-2: #b98a35;
  --red: #e0533f;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b0806; color: var(--text); font-family: var(--sans); overflow: hidden; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.35; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; text-align: center; gap: 10px;
  background: radial-gradient(ellipse at 50% 45%, #241912 0%, #0b0806 70%);
  transition: opacity 1.1s ease 0.2s, visibility 0s linear 1.4s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-title { font-family: var(--serif); font-style: italic; font-size: clamp(42px, 7vw, 72px); color: #efe2c8; }
.loader-sub { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 17px; }

/* ---------- top bars ---------- */
.bar { position: fixed; top: max(14px, env(safe-area-inset-top)); z-index: 5; display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 999px; }
.bar-left { left: 14px; }
.bar-right { right: 14px; }
.icon { width: 38px; height: 38px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 999px; transition: background 0.2s; }
.icon:hover:not(:disabled) { background: rgba(255, 236, 205, 0.1); }
.title-block { padding: 0 8px; min-width: 150px; text-align: center; line-height: 1.15; }
.eyebrow { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.label { font-family: var(--serif); font-style: italic; font-size: 16px; border: 0; background: none; padding: 0 4px; border-radius: 6px; }
.label:hover { background: rgba(255, 236, 205, 0.08); }
#gotoForm input { width: 90px; height: 22px; text-align: center; font-family: var(--serif); font-size: 15px; padding: 0 6px; border-radius: 6px; }
#soundBtn .off { display: none; }
#soundBtn[aria-pressed="false"] .on { display: none; }
#soundBtn[aria-pressed="false"] .off { display: block; }

.menu { position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px; padding: 6px; border-radius: 14px; display: flex; flex-direction: column; background: var(--glass-strong); }
.menu[hidden] { display: none; }
.menu button { text-align: left; padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; }
.menu button:hover { background: rgba(255, 236, 205, 0.08); }

/* ---------- dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 6;
  transform: translateX(-50%); width: min(720px, calc(100vw - 24px));
  padding: 10px; border-radius: 22px; transition: width 0.45s cubic-bezier(.2,.8,.2,1);
}
.dock[data-state="writing"], .dock[data-state="sending"] { width: min(520px, calc(100vw - 24px)); }
.dock > * { display: none; }
.dock[data-state="compose"] > .composer { display: flex; }
.dock[data-state="writing"] > .status-row, .dock[data-state="sending"] > .status-row { display: flex; }
.dock[data-state="sending"] .speeds, .dock[data-state="sending"] #skipBtn, .dock[data-state="sending"] .progress { display: none; }
.dock[data-state="done"] > .done-panel { display: flex; }
.dock[data-state="full"] > .full-panel { display: flex; }

.composer { flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.quote-row { align-items: flex-end; }
.composer .more, .composer .submit-row .fine { display: none; }
.composer.expanded .more { display: flex; flex-direction: column; gap: 8px; }
.composer.expanded .submit-row .fine { display: block; }
.composer:not(.expanded) .submit-row { display: none; }
#cancelEditBtn { display: none; margin-left: auto; }
.composer.editing #cancelEditBtn { display: inline-flex; align-items: center; }
.composer.editing .fine { color: var(--brass); }

textarea, input {
  font: inherit; color: var(--text); background: rgba(0, 0, 0, 0.28); border: 1px solid var(--line);
  border-radius: 14px; outline: none; transition: border-color 0.2s, background 0.2s;
}
textarea:focus, input:focus { border-color: rgba(216, 173, 85, 0.55); background: rgba(0, 0, 0, 0.36); }
textarea::placeholder, input::placeholder { color: rgba(243, 233, 216, 0.42); }
textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 150px; padding: 12px 14px; line-height: 1.45;
  font-family: var(--serif); font-size: 17px;
}
input { height: 42px; padding: 0 14px; font-size: 14.5px; flex: 1; min-width: 0; }
#goalInput { flex: 1.3; }

.mic-group { display: flex; align-items: center; gap: 4px; flex: none; }
.mic { width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.28); display: grid; place-items: center; position: relative; transition: background 0.2s, color 0.2s; }
.mic:hover:not(:disabled) { background: rgba(255, 236, 205, 0.08); }
.mic[aria-pressed="true"] { background: var(--red); color: #fff; border-color: transparent; }
.mic[aria-pressed="true"]::after { content: ""; position: absolute; inset: -4px; border-radius: 17px; border: 2px solid var(--red); animation: pulse 1.3s ease-out infinite; }
@keyframes pulse { from { opacity: 0.8; transform: scale(1); } to { opacity: 0; transform: scale(1.25); } }
.lang { height: 48px; min-width: 40px; padding: 0 6px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.2); font-size: 12.5px; color: var(--muted); }
.lang:hover { color: var(--text); }

.listen-hint { display: none; font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.listen-hint em { color: var(--text); }
.composer.is-listening .listen-hint { display: block; }

.hand-row { justify-content: space-between; }
.hands { display: flex; flex-wrap: wrap; align-items: center; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.hands button { border: 0; background: transparent; height: 34px; padding: 0 12px; border-radius: 9px; color: var(--muted); line-height: 1; }
.hands button[aria-checked="true"] { background: rgba(255, 236, 205, 0.14); color: var(--text); }
.hands [data-hand="script"] { font-family: var(--serif); font-style: italic; font-size: 15px; }
.hands [data-hand="caveat"] { font-family: "QB Caveat", cursive; font-size: 21px; }
.hands [data-hand="cedarville"] { font-family: "QB Cedarville", cursive; font-size: 17px; }
.hands [data-hand="oswald"] { font-family: "QB Oswald", sans-serif; font-size: 15px; letter-spacing: 0.02em; }
.hindi-chip { display: none; padding: 0 12px; height: 34px; align-items: center; border-radius: 9px; background: rgba(255, 236, 205, 0.14); font-family: "QB Kalam", sans-serif; font-size: 15px; }
.composer.is-hindi .hands button { display: none; }
.composer.is-hindi .hindi-chip { display: inline-flex; }
.counter { font-size: 12.5px; color: var(--muted); padding-right: 4px; }
.counter.over { color: #f0907e; }

.submit-row { justify-content: space-between; }
.fine { font-size: 12px; color: var(--muted); padding-left: 4px; }

.write {
  flex: none; height: 42px; padding: 0 18px 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; font-weight: 600; letter-spacing: 0.02em; color: #24180a;
  background: linear-gradient(180deg, #e6c06c, var(--brass-2));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 14px rgba(185, 138, 53, 0.25);
  position: relative; overflow: hidden;
}
.write:hover:not(:disabled) { filter: brightness(1.06); }
.write.arming::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; background: #24180a; opacity: 0.6; animation: arm 1.8s linear forwards; }
@keyframes arm { from { width: 0; } to { width: 100%; } }
.x-logo { width: 14px; height: 14px; stroke-width: 2.4; }

.status-row { align-items: center; gap: 10px; padding: 4px 6px 4px 10px; position: relative; flex-wrap: wrap; }
#statusText { font-family: var(--serif); font-style: italic; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ink-dot { width: 9px; height: 9px; border-radius: 50%; background: #5b78c9; animation: inkpulse 1.4s infinite; }
@keyframes inkpulse { 0% { box-shadow: 0 0 0 0 rgba(91, 120, 201, 0.6); } 70% { box-shadow: 0 0 0 9px rgba(91, 120, 201, 0); } 100% { box-shadow: 0 0 0 0 rgba(91, 120, 201, 0); } }
.speeds { display: flex; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.speeds button { border: 0; background: transparent; padding: 5px 9px; border-radius: 8px; font-size: 12.5px; color: var(--muted); }
.speeds button[aria-pressed="true"] { background: rgba(255, 236, 205, 0.12); color: var(--text); }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 10px; height: 36px; padding: 0 12px; font-size: 13px; }
.ghost:hover { background: rgba(255, 236, 205, 0.08); }
.progress { position: absolute; left: 12px; right: 12px; bottom: -6px; height: 2px; background: rgba(255, 236, 205, 0.08); border-radius: 2px; overflow: hidden; }
#progressBar { height: 100%; background: var(--brass); transform-origin: left; transform: scaleX(0); transition: transform 0.1s linear; }

.done-panel, .full-panel { align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 4px 10px; flex-wrap: wrap; }
.done-title { font-family: var(--serif); font-style: italic; font-size: 20px; }
.done-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.done-actions { display: flex; gap: 8px; align-items: center; }

.shake { animation: shake 0.38s; }
@keyframes shake { 20%, 60% { transform: translateX(calc(-50% - 6px)); } 40%, 80% { transform: translateX(calc(-50% + 6px)); } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 210px; z-index: 7; transform: translate(-50%, 10px);
  display: flex; align-items: center; gap: 12px;
  max-width: min(560px, calc(100vw - 32px)); padding: 10px 12px 10px 16px; border-radius: 12px;
  background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toastAction { border: 0; border-radius: 8px; padding: 6px 10px; font-weight: 600; font-size: 13px; color: #24180a; background: var(--brass); }

/* ---------- about ---------- */
.about { max-width: min(460px, calc(100vw - 32px)); border-radius: 18px; padding: 22px 24px; color: var(--text); background: var(--glass-strong); }
.about::backdrop { background: rgba(0, 0, 0, 0.45); }
.about h2 { font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 26px; margin: 0 0 10px; }
.about p { font-size: 14.5px; line-height: 1.55; margin: 0 0 12px; color: #e6dac6; }
.about .small { font-size: 13px; color: var(--muted); }

/* ---------- admin ---------- */
.admin-only { display: none; }
body.is-admin .menu .admin-only { display: block; color: var(--brass); }
.danger { color: #f0907e; }
.admin-login { display: flex; gap: 8px; margin: 4px 0 12px; }
.admin { width: min(620px, calc(100vw - 24px)); max-height: min(86vh, 760px); overflow: auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; }
.admin section { border-top: 1px solid var(--line); padding: 12px 0; }
.admin h3 { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.admin-page { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-style: italic; font-size: 17px; }
.admin-page input { width: 90px; height: 36px; text-align: center; }
.admin-preview { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, 0.25); font-size: 14px; line-height: 1.45; min-height: 44px; }
.admin-preview .q { font-family: var(--serif); font-size: 16px; }
.admin-preview .g, .admin-preview .m, .muted { color: var(--muted); font-size: 13px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; }
.admin-row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e6dac6; }
.admin-row em { color: #f0b27e; font-style: normal; font-size: 12px; white-space: nowrap; }
.admin-row .ghost { height: 30px; padding: 0 9px; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .bar { top: max(10px, env(safe-area-inset-top)); }
  .bar-left { left: 10px; }
  .bar-right { right: 10px; }
  .icon { width: 34px; height: 34px; }
  .title-block { min-width: 104px; padding: 0 2px; }
  .label { font-size: 14px; }
  .meta-row { flex-direction: column; align-items: stretch; }
  .meta-row input, #goalInput, #authorInput { flex: none; }
  .hands { flex: 1; }
  .hands button { flex: 1; padding: 0 6px; }
  .counter { display: none; }
  .composer.expanded .submit-row .fine { display: none; }
  .composer.expanded .submit-row .write { flex: 1; }
  .toast { bottom: 150px; }
  .status-row .speeds { display: none; }
  .done-actions { width: 100%; }
  .done-actions .write { flex: 1; }
  .done-actions .ghost { padding: 0 9px; }
  .admin-row { flex-wrap: wrap; }
  .admin-row .t { flex-basis: 100%; order: 2; }
}
@media (max-width: 400px) {
  #snapBtn { display: none; }
}
