@font-face { font-family: 'EB Garamond'; src: url('../fonts/EBGaramond.ttf') format('truetype'); font-weight: 400 800; font-style: normal; font-display: block; }
@font-face { font-family: 'EB Garamond'; src: url('../fonts/EBGaramond-Italic.ttf') format('truetype'); font-weight: 400 800; font-style: italic; font-display: block; }
@font-face { font-family: 'Patrick Hand'; src: url('../fonts/PatrickHand-Regular.ttf') format('truetype'); font-display: swap; }

:root {
  --ink: #2a2723;
  --ink-soft: rgba(42, 39, 35, 0.55);
  --rule: rgba(42, 39, 35, 0.42);
  --linen: #f6f1e7;
  --linen2: #ece4d4;
  --ground: #1f2420;
  --forest: #2f4535;
  --olive: #626a3d;
  --brass: #a8894c;
  --terracotta: #a85a3c;
  --serif: 'EB Garamond', 'Iowan Old Style', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ground); color: var(--ink); font-family: var(--serif); }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* cards: linen stock, a hairline rule, a soft shadow */
.paper {
  background-color: rgba(246, 241, 231, 0.94);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .4  0 0 0 0 .35  0 0 0 0 .28  0 0 0 .06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 8px 24px rgba(20, 22, 18, 0.18);
}

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
body.no-ui #hud > *:not(#fps) { opacity: 0; pointer-events: none; }
#hud > * { transition: opacity .3s; }

/* clock */
#clock { position: absolute; top: 18px; left: 22px; display: flex; align-items: center; gap: 12px; padding: 9px 18px 9px 11px; }
#clock-face { width: 56px; height: 56px; }
.clock-row { display: flex; align-items: baseline; gap: 9px; }
#clock-time { font-size: 30px; line-height: 1; letter-spacing: .01em; }
.badge { font-size: 12px; letter-spacing: .14em; padding: 1px 6px 0; border: 1px solid var(--brass); color: #7d6537; border-radius: 1px; display: inline-block; }
#clock-weather { font-size: 17px; color: var(--ink-soft); }
#clock-phase { font-size: 16px; font-style: italic; color: var(--ink-soft); margin-top: 3px; }

/* toggles */
#toggles { position: absolute; top: 20px; right: 22px; display: flex; gap: 8px; }
.tog { font-family: var(--serif); color: var(--ink); cursor: pointer; width: 42px; height: 42px; display: grid; place-items: center; font-size: 21px; padding: 0; transition: background-color .2s; }
.tog:hover { background-color: #fffaf1; }
.tog svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.tog .on { display: none; } .tog[aria-pressed='true'] .on { display: block; } .tog[aria-pressed='true'] .off { display: none; }
.tog[aria-pressed='true'] { background-color: #e7e3cf; }
.tog[aria-pressed='true'] svg { stroke: var(--forest); }
#btn-voice { position: relative; }
#btn-voice[data-clone='on']::after { content: ''; position: absolute; right: 7px; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: #b0533a; opacity: .55; }
#btn-voice[data-clone='on'][aria-pressed='true']::after { opacity: .95; }
.tog.wide { width: auto; padding: 3px 18px; height: 36px; font-size: 17px; font-style: italic; }
.tog.small { width: 38px; height: 30px; font-size: 11px; border: 1px solid var(--rule); border-radius: 1px; background: transparent; color: var(--ink); }
.tog.small.active { background: var(--forest); color: var(--linen); }

/* bottom: time strip + chat */
#bottom { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; width: min(1040px, calc(100vw - 40px)); }
#timebar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex: 1 1 52%; }
#chat { display: flex; align-items: center; gap: 6px; padding: 3px 5px 3px 16px; flex: 1 1 48%; }
#chat input { flex: 1; border: 0; background: transparent; font-family: var(--serif); font-size: 19px; color: var(--ink); padding: 8px 4px; outline: none; min-width: 0; }
#chat input::placeholder { color: var(--ink-soft); font-style: italic; }
#chat button { border: 1px solid var(--forest); border-radius: 1px; background: var(--forest); width: 40px; height: 34px; cursor: pointer; display: grid; place-items: center; }
#chat button svg { width: 18px; height: 18px; fill: none; stroke: var(--linen); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
#chat.thinking button[type='submit'] { animation: breathe 1.2s infinite; }
/* voice: hold-to-talk mic + hands-free toggle */
#chat .vbtn { --lvl: 0; background: transparent; border: 1px solid var(--rule); width: 36px; color: var(--ink); font-family: var(--serif); font-size: 21px; line-height: 1; touch-action: none; user-select: none; -webkit-user-select: none; position: relative; transition: background-color .2s, border-color .2s; }
#chat .vbtn svg { stroke: var(--ink); }
#chat .vbtn:hover { background: #fffaf1; }
#chat .vbtn[aria-pressed='true'], #chat .vbtn.live { background: #e7e3cf; border-color: var(--forest); color: var(--forest); }
#chat .vbtn[aria-pressed='true'] svg, #chat .vbtn.live svg { stroke: var(--forest); }
#chat #btn-mic.live { box-shadow: 0 0 0 calc(2px + var(--lvl) * 7px) rgba(168, 90, 60, .28); }
#chat #btn-handsfree[aria-pressed='true'] { animation: pulse 2.4s infinite; }
#voice-live { --lvl: 0; position: absolute; right: 0; bottom: calc(100% + 10px); max-width: min(460px, 92vw); padding: 7px 16px 8px; font-size: 17px; line-height: 1.3; display: flex; gap: 10px; align-items: baseline; }
#voice-live .vl-status { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
#voice-live .vl-status:empty { display: none; }
#voice-live .vl-text { font-style: italic; color: var(--ink); }
#voice-live[data-kind='live'] .vl-status::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--terracotta); transform: scale(calc(.8 + var(--lvl) * 1.2)); vertical-align: 1px; }
#voice-live[data-kind='error'] { border-color: var(--terracotta); }
#voice-live[data-kind='error'] .vl-text { font-style: normal; }
@keyframes breathe { 50% { opacity: .55; } }
#nik-typing { position: absolute; left: 0; bottom: calc(100% + 10px); padding: 5px 14px 6px; font-size: 14px; font-style: italic; color: var(--ink-soft); letter-spacing: .03em; }
#nik-typing .dots { display: inline-flex; gap: 3px; margin-left: 6px; }
#nik-typing .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-soft); animation: typing 1.2s infinite; }
#nik-typing .dots i:nth-child(2) { animation-delay: .2s; }
#nik-typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%, 60%, 100% { opacity: .25; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
.live { display: flex; align-items: center; gap: 7px; font-family: var(--serif); font-size: 15px; letter-spacing: .06em; border: 1px solid var(--rule); border-radius: 1px; background: transparent; padding: 4px 10px; cursor: pointer; white-space: nowrap; color: var(--ink); }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: #9a958a; }
.live.is-live .dot { background: var(--terracotta); animation: pulse 2.4s infinite; }
.live:not(.is-live) { background: #ebe5d2; font-style: italic; }
@keyframes pulse { 50% { opacity: .35; } }

#time-slider { -webkit-appearance: none; appearance: none; flex: 1; height: 22px; background: transparent; cursor: pointer; --track: linear-gradient(90deg, #1d2752, #8bbfea 30%, #ffb066 75%, #1d2752); }
#time-slider::-webkit-slider-runnable-track { height: 6px; border: 0; border-radius: 3px; background: var(--track); opacity: .9; }
#time-slider::-moz-range-track { height: 6px; border: 0; border-radius: 3px; background: var(--track); }
#time-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -4px; border-radius: 50%; border: 1px solid var(--ink); background: var(--linen); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
#time-slider::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; border: 1px solid var(--ink); background: var(--linen); }

/* help */
#help { position: absolute; top: 90px; right: 22px; width: 340px; padding: 18px 22px 18px; font-size: 17px; line-height: 1.38; }
#help h3 { font-size: 26px; font-style: italic; margin: 0 0 8px; font-weight: normal; border-bottom: 1px solid var(--rule); padding-bottom: 6px; }
#help p { margin: 0 0 8px; }
#help ul { margin: 0 0 14px; padding-left: 16px; }
#help li { margin: 3px 0; }
#help b { font-weight: 600; }
.hidden { display: none !important; }

#tooltip { position: fixed; pointer-events: none; font-family: var(--serif); font-style: italic; font-size: 16px; padding: 2px 10px; background: rgba(246,241,231,.95); border: 1px solid var(--rule); border-radius: 1px; box-shadow: 0 4px 12px rgba(0,0,0,.15); opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; white-space: nowrap; z-index: 5; }
#tooltip.show { opacity: 1; transform: none; }

#fps { position: absolute; left: 22px; bottom: 86px; font-size: 13px; color: var(--linen); opacity: .7; pointer-events: none; }

/* loader */
#loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ground); transition: opacity .8s; z-index: 10; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-card { background: var(--linen); border: 1px solid var(--rule); padding: 28px 46px 22px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.loader-title { font-size: 40px; font-style: italic; }
.loader-sub { font-size: 15px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); margin-top: 4px; }
#loader-status { font-size: 16px; font-style: italic; margin-top: 2px; color: var(--ink-soft); }

@media (max-width: 760px) {
  #bottom { flex-direction: column; bottom: 10px; }
  #timebar, #chat { width: 100%; }
  #clock { transform: scale(.82); transform-origin: top left; }
  #help { width: calc(100vw - 48px); }
}
