/* Circadiano — vitrine Fable #7 · relógio biológico de 24h
   Dados ilustrativos, sem valor clínico. */

:root {
  --bg: #070a14;
  --bg-2: #0b1022;
  --ink: #eef2ff;
  --ink-dim: #aab3d4;
  --ink-faint: #8590b8;
  --line: rgba(150, 165, 220, 0.16);
  --line-soft: rgba(150, 165, 220, 0.09);
  --card: rgba(20, 26, 48, 0.55);
  --card-brd: rgba(150, 170, 235, 0.14);

  /* biomarker hues */
  --alerta: #34d5c4;
  --temperatura: #ff7a63;
  --cortisol: #f4b13e;
  --melatonina: #9a86ff;

  /* window hues */
  --w-luz: #ffbf5c;
  --w-foco: #4bc8f2;
  --w-refeicao: #f39a54;
  --w-exercicio: #59d98c;
  --w-desacelerar: #8f8bf0;
  --w-sono: #6b7bff;
  --w-cafeina: #ff6b7d;

  --radius: 16px;
  --sky-glow: #12203f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--sky-glow) 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 60%);
  transition: background 900ms ease;
}

/* ---------------- top bar ---------------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(14px, 3vw, 28px);
  flex: 0 0 auto;
  z-index: 6;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  align-self: center;
  background:
    conic-gradient(from -90deg, var(--w-luz), var(--alerta), var(--w-sono), var(--melatonina), var(--w-luz));
  box-shadow: 0 0 14px rgba(255, 200, 120, 0.4);
  flex: 0 0 auto;
}
.brand-name {
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-size: clamp(18px, 2.4vw, 23px);
  letter-spacing: 0.2px;
}
.brand-sub {
  color: var(--ink-faint);
  font-size: 12.5px;
  white-space: nowrap;
}
.topbar-right { flex: 0 0 auto; }
.disclaimer {
  font-size: 11.5px;
  color: #ffd9a8;
  background: rgba(255, 176, 92, 0.1);
  border: 1px solid rgba(255, 176, 92, 0.28);
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------------- main ---------------- */
#main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 0;
  gap: clamp(8px, 2vw, 26px);
  padding: 0 clamp(10px, 2.5vw, 30px);
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#dial {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#dial.grabbing { cursor: grabbing; }

#center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  width: 42%;
  max-width: 240px;
}
.c-tod {
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}
.c-time {
  font-family: "Fraunces", serif;
  font-weight: 300;
  font-size: clamp(38px, 7vw, 66px);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.c-phase {
  margin-top: 6px;
  font-size: clamp(12px, 1.6vw, 15px);
  color: var(--ink);
  font-weight: 500;
}
.c-rel {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-family: "Space Mono", monospace;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .5s ease;
}
.hint kbd {
  font-family: "Space Mono", monospace;
  font-size: 10.5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 4px;
  margin: 0 1px;
  color: var(--ink-dim);
}

/* ---------------- panel ---------------- */
#panel {
  flex: 0 0 clamp(280px, 26vw, 340px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 0 12px;
  overflow: hidden;
}

.rx-card {
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  padding: 15px 16px 16px;
  backdrop-filter: blur(6px);
  position: relative;
  overflow: hidden;
}
.rx-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--rx-color, var(--w-luz));
  box-shadow: 0 0 16px 1px var(--rx-color, var(--w-luz));
}
.rx-head { display: flex; align-items: flex-start; gap: 10px; }
.rx-dot {
  width: 26px; height: 26px; border-radius: 8px;
  flex: 0 0 auto; margin-top: 1px;
  background: var(--rx-color, var(--w-luz));
  box-shadow: 0 0 18px var(--rx-color, var(--w-luz));
  display: grid; place-items: center;
}
.rx-titles { flex: 1 1 auto; min-width: 0; }
.rx-kicker {
  font-size: 10.5px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-faint);
}
.rx-title {
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-size: 20px;
  margin: 1px 0 0;
  line-height: 1.1;
}
.rx-window {
  font-family: "Space Mono", monospace;
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;
  margin-top: 2px;
}
.rx-text {
  margin: 11px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-dim);
}
.rx-next {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 7px;
}
.rx-next b {
  color: var(--ink);
  font-weight: 500;
}
.rx-next .rx-next-in {
  margin-left: auto;
  font-family: "Space Mono", monospace;
  color: var(--ink-dim);
  white-space: nowrap;
}

.bio {
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  padding: 13px 15px 11px;
}
.bio-row {
  display: grid;
  grid-template-columns: 1fr 76px auto;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
}
.bio-row:last-of-type { border-bottom: 0; }
.bio-name {
  font-size: 12.5px;
  color: var(--ink-dim);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.bio-swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.bio-row[data-bio="alerta"] .bio-swatch { background: var(--alerta); }
.bio-row[data-bio="temperatura"] .bio-swatch { background: var(--temperatura); }
.bio-row[data-bio="cortisol"] .bio-swatch { background: var(--cortisol); }
.bio-row[data-bio="melatonina"] .bio-swatch { background: var(--melatonina); }
.bio-bar {
  position: relative;
  height: 5px;
  border-radius: 3px;
  background: rgba(150,165,220,0.14);
  overflow: hidden;
}
.bio-bar > i {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%;
  border-radius: 3px;
  transition: width .25s ease;
}
.bio-row[data-bio="alerta"] .bio-bar > i { background: var(--alerta); }
.bio-row[data-bio="temperatura"] .bio-bar > i { background: var(--temperatura); }
.bio-row[data-bio="cortisol"] .bio-bar > i { background: var(--cortisol); }
.bio-row[data-bio="melatonina"] .bio-bar > i { background: var(--melatonina); }
.bio-val {
  font-family: "Space Mono", monospace;
  font-size: 12px;
  color: var(--ink);
  text-align: right;
  min-width: 62px;
  white-space: nowrap;
}
.bio-note {
  margin: 9px 0 0;
  font-size: 10.5px;
  color: var(--ink-faint);
  line-height: 1.4;
}

.agenda-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  padding: 11px 8px 6px 14px;
  overflow: hidden;
}
.agenda-head {
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-right: 6px;
  margin-bottom: 4px;
}
.agenda-head span { letter-spacing: 0.02em; text-transform: none; font-size: 10.5px; opacity: 0.7; }
.agenda {
  list-style: none;
  margin: 0;
  padding: 0 6px 0 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(150,165,220,0.3) transparent;
}
.agenda::-webkit-scrollbar { width: 6px; }
.agenda::-webkit-scrollbar-thumb { background: rgba(150,165,220,0.28); border-radius: 3px; }
.agenda li {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.agenda li:hover { background: rgba(150,165,220,0.08); }
.agenda li.active { background: rgba(150,165,220,0.12); }
.agenda li.active .ag-label { color: var(--ink); font-weight: 500; }
.ag-time {
  font-family: "Space Mono", monospace;
  font-size: 11.5px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.ag-label {
  font-size: 12.5px;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ag-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.ag-label .ag-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-now {
  font-size: 9px; letter-spacing: .1em; text-transform: uppercase;
  color: #0a0e1c; background: #ffd9a8; border-radius: 999px; padding: 1px 6px;
  margin-left: auto; flex: 0 0 auto;
}

.patient {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.patient-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ink);
  font-family: "Inter", sans-serif;
  font-size: 13px;
  outline: none;
}
.patient-input:focus { border-color: rgba(120, 200, 255, 0.5); }
.patient-input::placeholder { color: var(--ink-faint); }

/* ---------------- controls ---------------- */
#controls {
  flex: 0 0 auto;
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: center;
  gap: 9px 11px;
  padding: 8px clamp(12px, 3vw, 28px) max(12px, env(safe-area-inset-bottom));
  z-index: 6;
}

.seg {
  display: inline-flex;
  flex-wrap: nowrap;
  background: rgba(16, 22, 44, 0.7);
  border: 1px solid var(--card-brd);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.seg button[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.05));
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }

.wake {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink-dim);
  background: rgba(16, 22, 44, 0.7);
  border: 1px solid var(--card-brd);
  border-radius: 999px;
  padding: 6px 14px 6px 15px;
  white-space: nowrap;
}
.wake-label { white-space: nowrap; }
.wake output {
  font-family: "Space Mono", monospace;
  color: var(--ink);
  font-size: 13px;
  min-width: 42px;
}
.wake input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 108px;
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--w-luz), var(--alerta));
  outline: none;
}
.wake input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
.wake input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 0; cursor: pointer;
}

.btn {
  appearance: none;
  border: 1px solid var(--card-brd);
  background: rgba(16, 22, 44, 0.7);
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  padding: 8px 15px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .2s, border-color .2s, background .2s;
}
.btn:hover { color: var(--ink); border-color: rgba(150,170,235,0.32); }
.btn[aria-pressed="true"] {
  color: var(--ink);
  border-color: rgba(120, 200, 255, 0.5);
  background: rgba(75, 200, 242, 0.14);
}
.play-ico {
  width: 0; height: 0;
  border-left: 8px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
.btn.is-playing .play-ico {
  width: 8px; height: 9px;
  border: 0;
  border-left: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

.btn-ghost {
  appearance: none;
  border: 1px solid var(--card-brd);
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color .2s, border-color .2s;
}
.btn-ghost:hover { color: var(--ink); border-color: rgba(150,170,235,0.32); }
.btn-ghost.copied { color: var(--w-exercicio); border-color: rgba(89,217,140,0.5); }

.guide-link {
  position: fixed;
  right: 14px;
  bottom: 10px;
  font-size: 11.5px;
  color: var(--ink-faint);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(10, 14, 28, 0.6);
  backdrop-filter: blur(4px);
  z-index: 7;
  transition: color .2s, border-color .2s;
}
.guide-link:hover { color: var(--ink); border-color: rgba(150,170,235,0.35); }

/* focus visibility */
:focus-visible {
  outline: 2px solid #8fd6ff;
  outline-offset: 2px;
  border-radius: 6px;
}
.dial-a11y {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(66vmin, 60%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  pointer-events: none; /* canvas below handles drag; still focusable via Tab */
}
.dial-a11y:focus-visible {
  outline: 2px dashed #8fd6ff;
  outline-offset: 8px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.sr-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  #main {
    flex-direction: column;
    gap: 6px;
    padding: 0 12px;
  }
  #stage { flex: 1 1 auto; }
  #panel {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 8px;
    padding: 0 0 4px;
  }
  .rx-text { font-size: 13px; }
  .bio-row { padding: 5px 0; }
  .hint { display: none; }
  .agenda-wrap { display: none; }
}

@media (max-width: 560px) {
  #topbar { padding: 10px 13px; }
  .brand-sub { display: none; }
  .brand-name { font-size: 18px; }
  .disclaimer { font-size: 10px; padding: 4px 9px; }
  .dc-more { display: none; }
  #main { padding: 0 10px; }
  #panel { gap: 8px; }
  .rx-card { padding: 12px 13px; }
  .rx-title { font-size: 18px; }
  .rx-text { margin-top: 8px; font-size: 13px; }
  .bio { padding: 10px 12px 9px; }
  .bio-row { grid-template-columns: 1fr 58px 66px; gap: 8px; }
  .bio-name { font-size: 11.5px; }
  .bio-val { min-width: 0; }
  /* stack the patient row so nothing overflows */
  .patient { flex-direction: column; align-items: stretch; gap: 8px; }
  .btn-ghost { width: 100%; text-align: center; padding: 9px 12px; }
  .seg button { padding: 7px 12px; font-size: 12.5px; }
  .wake input[type="range"] { width: 84px; }
  .wake { padding: 6px 12px; }
  .guide-link { display: none; }
  /* play button: icon only on mobile to fit the control row */
  #play .play-txt { display: none; }
  #play { padding: 8px 13px; }
}

@media (max-width: 380px) {
  .seg button { padding: 6px 10px; font-size: 12px; }
  .btn { padding: 7px 12px; font-size: 12.5px; }
  .wake { padding: 6px 11px; }
  .wake input[type="range"] { width: 72px; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  #app, .bio-bar > i, .hint { transition: none; }
}
