:root {
  --ink: #15302e;
  --muted: #5d716f;
  --line: #d9e2e0;
  --panel: rgba(255, 255, 255, 0.92);
  --accent: #0f766e;
  --accent-soft: #e2f1ef;
  --danger: #c8102e;
  --warn: #b7791f;
  --ok: #2f855a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 42, 40, 0.14);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9eef0; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; height: 48px;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: .2px; }
.brand img { height: 24px; width: auto; }
.intro-mark { height: 64px; width: auto; display: block; margin-bottom: 10px; }
#patientChip { font-weight: 600; }
#patientChip small { color: var(--muted); font-weight: 500; margin-left: 6px; }
#phase { color: var(--muted); font-size: 14px; flex: 1; }
#scoreChip { background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 999px; font-size: 14px; }

#tray, #side {
  position: fixed; top: 72px; bottom: 84px; width: 248px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
#tray { left: 12px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
#side { right: 12px; width: 280px; }
#tray section + section { border-top: 1px solid var(--line); padding-top: 10px; }
h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.tool {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px;
  transition: border-color .15s, background .15s, transform .1s;
}
.tool:hover { border-color: #a9c4c0; }
.tool.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tool:active { transform: scale(.98); }
.tool b { display: block; font-size: 14px; }
.tool small { display: block; color: var(--muted); font-size: 12px; }
.tool .sw { width: 12px; height: 34px; border-radius: 4px; flex: none; }
.tool .stock { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

#dosePicker { margin-top: 4px; }
#dosePicker small { color: var(--muted); font-size: 12px; }
#doseChips { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
#doseChips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
#doseChips button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.card.grow { flex: 1; min-height: 120px; overflow-y: auto; }
#chart dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; }
#chart dt { color: var(--muted); }
#chart dd { margin: 0; }
#chart .alarm { color: var(--danger); font-weight: 700; }
#chart .req { font-size: 13px; font-style: italic; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
#log { margin: 0; padding-left: 18px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
#log li span { color: var(--muted); }
#log li.bad { color: var(--danger); }

#bottombar {
  position: fixed; left: 12px; right: 12px; bottom: 12px; height: 60px;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
}
.views { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.views button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 11px; font-size: 13px; }
.views button:hover { border-color: var(--accent); }
.toggle { font-size: 13px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.toggle small { color: var(--muted); }

button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.big { padding: 14px 26px; font-size: 16px; }

#alert {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 12px 18px; border-radius: 12px;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(200, 16, 46, .35);
  animation: pulse 1s infinite; z-index: 5; max-width: 640px;
}
#alert.calm { background: #2f855a; box-shadow: 0 10px 30px rgba(47, 133, 90, .3); animation: none; }
#alertTimer { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 22px; margin-left: 8px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(200, 16, 46, .18); } }

#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: #15302e; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 6;
}
#holdLabel {
  position: fixed; pointer-events: none; background: rgba(21, 48, 46, .88); color: #fff;
  padding: 4px 8px; border-radius: 6px; font-size: 13px; font-variant-numeric: tabular-nums; z-index: 6;
  transform: translate(16px, -28px);
}
#fade {
  position: fixed; inset: 0; background: #0d1b1a; color: #fff; display: grid; place-items: center;
  font-size: 34px; font-weight: 300; letter-spacing: .04em; z-index: 9; animation: fadein .6s;
}
@keyframes fadein { from { opacity: 0; } }
#loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(233, 238, 240, .85); z-index: 8; color: var(--muted); }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(13, 27, 26, .45); z-index: 10; padding: 16px; }
.sheet { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 28px 32px; max-width: 560px; width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto; }
.sheet.wide { max-width: 760px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }
h1 { margin: 6px 0 10px; font-size: 34px; }
h2 { margin: 4px 0 12px; font-size: 26px; }
.lead { font-size: 16px; line-height: 1.5; color: #2b4543; }
.rules { padding-left: 18px; line-height: 1.6; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); }
.credit { font-size: 11px; color: var(--muted); margin: 14px 0 0; }
blockquote { margin: 0 0 14px; padding: 12px 16px; background: #f4f8f7; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; font-size: 16px; line-height: 1.45; }
#cChart { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 10px; }
#cChart td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
#cChart td:first-child { color: var(--muted); width: 190px; }
#cChart .alarm { color: var(--danger); font-weight: 700; }
.q { font-weight: 600; margin: 14px 0 8px; }
.options { display: grid; gap: 8px; }
.options button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px 14px; font-size: 15px; }
.options button:hover { border-color: var(--accent); background: var(--accent-soft); }

.stars { font-size: 26px; letter-spacing: 3px; color: #e2a400; margin-bottom: 8px; }
.stars .off { color: #d6dcdb; }
.ba { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 6px 0 14px; }
.ba figure { margin: 0; }
.ba img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: #dde5e4; display: block; }
.ba figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; text-align: center; }
.findings { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; font-size: 14px; line-height: 1.4; }
.findings li { display: flex; gap: 8px; }
.findings li::before { flex: none; font-weight: 800; }
.findings li.ok::before { content: "✓"; color: var(--ok); }
.findings li.bad::before { content: "✗"; color: var(--danger); }
.findings li.warn::before { content: "!"; color: var(--warn); width: 10px; text-align: center; }
.rfoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
#rScore { font-size: 15px; }
.btns { display: flex; gap: 8px; }
.btns button:not(.primary) { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 11px 16px; }
#fStock { font-size: 13px; color: var(--muted); margin: 8px 0 18px; line-height: 1.5; }

#coach {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 4; pointer-events: none;
  background: rgba(21, 48, 46, .86); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 13px;
  white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
}
@media (min-width: 821px) { #coach { display: none !important; } }
@media (pointer: coarse) { #holdLabel { transform: translate(-50%, -78px); } }
.hint.touch { display: none; }
@media (pointer: coarse) { .hint.touch { display: block; } .hint.desktop { display: none; } }
#trayTabs { display: none; }
.tool .short { display: none; }
#chartBtn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; }

@media (max-width: 820px) {
  #topbar { top: 6px; left: 6px; right: 6px; height: 44px; gap: 8px; padding: 0 10px; padding-top: env(safe-area-inset-top); }
  .brand { font-size: 0; gap: 0; }
  .brand img { height: 26px; }
  #phase { display: none; }
  #patientChip { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #patientChip small { font-size: 11px; }
  #scoreChip { font-size: 12px; padding: 5px 9px; }
  #chartBtn { display: block; }
  #doctorChip span { display: none; }
  .doctors { grid-template-columns: repeat(2, 1fr); }

  #tray {
    top: auto; left: 6px; right: 6px; bottom: 64px; width: auto;
    gap: 6px; padding: 6px; overflow: visible;
  }
  #trayTabs { display: flex; gap: 4px; }
  #trayTabs [data-tab-btn] {
    flex: 1; border: 0; background: #eef3f2; color: var(--muted); border-radius: 9px; padding: 8px 4px;
    font-size: 13px; font-weight: 600; white-space: nowrap;
  }
  #tray[data-tab="filler"] [data-tab-btn="filler"],
  #tray[data-tab="toxin"] [data-tab-btn="toxin"],
  #tray[data-tab="rescue"] [data-tab-btn="rescue"] { background: var(--accent); color: #fff; }
  #trayTabs .tool { flex: none; width: 44px; min-height: 0; justify-content: center; padding: 0; font-size: 17px; }
  #tray section { display: none; padding: 0; }
  #tray section + section { border-top: 0; padding-top: 0; }
  #tray[data-tab="filler"] section[data-tab="filler"],
  #tray[data-tab="toxin"] section[data-tab="toxin"],
  #tray[data-tab="rescue"] section[data-tab="rescue"] { display: block; }
  #tray h3, .tool small, .tool .full, .stock .more { display: none; }
  .tool .short { display: inline; }
  #fillerTools, #toxinTools, #rescueTools { display: flex; gap: 5px; }
  #fillerTools { flex-wrap: wrap; }
  #tray #fillerTools .tool { flex: 1 1 30%; }
  #tray section .tool {
    flex: 1 1 0; min-width: 0; width: auto; margin: 0; padding: 6px 4px 5px; min-height: 50px;
    flex-direction: column; align-items: center; gap: 3px; text-align: center;
  }
  #tray section .tool .sw { width: 26px; height: 5px; border-radius: 3px; }
  #tray section .tool b { font-size: 12.5px; white-space: nowrap; }
  #tray section .tool .stock { margin: 0; font-size: 10.5px; }
  #dosePicker { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
  #dosePicker small { display: inline; white-space: nowrap; }
  #doseChips { flex: 1; flex-wrap: nowrap; margin: 0; }
  #doseChips button { flex: 1; padding: 8px 4px; white-space: nowrap; }

  #side { display: none; top: 58px; left: 6px; right: 6px; bottom: 246px; width: auto; z-index: 7; }
  body.show-side #side { display: flex; }
  #bottombar { left: 6px; right: 6px; bottom: 6px; height: 52px; gap: 8px; padding: 0 8px; margin-bottom: env(safe-area-inset-bottom); }
  .views { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .views { gap: 4px; }
  .views button { flex: none; padding: 9px 7px; font-size: 13px; }
  .views [data-view="overview"], .views [data-view="right"], .views [data-view="left"] { display: none; }
  .toggle small, #finishBtn span { display: none; }
  .toggle span { font-size: 0; }
  .toggle span::after { content: 'Hartă'; font-size: 12px; }
  button.primary { padding: 10px 10px; }
  #bottombar { gap: 6px; }

  #legend { right: auto; left: 6px; bottom: 246px; font-size: 11px; padding: 8px 10px; }
  #alert { left: 6px; right: 6px; top: 56px; transform: none; padding: 10px 12px; font-size: 13px; gap: 8px; }
  #toast { bottom: 246px; width: max-content; max-width: 92vw; text-align: center; font-size: 13px; }
  #fade { font-size: 24px; }
  .modal { padding: 8px; }
  .sheet { padding: 18px 16px; border-radius: 14px; }
  h1 { font-size: 26px; }
  h2 { font-size: 21px; }
  .lead { font-size: 15px; }
  blockquote { font-size: 15px; padding: 10px 12px; }
  #cChart td:first-child { width: 112px; }
  .options button { padding: 13px 12px; }
  .rfoot { flex-direction: column; align-items: stretch; }
  .btns button { flex: 1; }
  #coach { top: 56px; }
}

#legend {
  position: fixed; bottom: 84px; right: 304px; display: flex; flex-direction: column; gap: 4px;
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 12px;
}
#legend span { display: flex; align-items: center; gap: 8px; }
#legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; opacity: .8; }

#cine { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#cine .bar { position: absolute; left: 0; right: 0; height: 9vh; background: #000; }
#cine .bar.top { top: 0; }
#cine .bar.bottom { bottom: 0; }
#cine .fade { position: absolute; inset: 0; background: #000; }
#cine button {
  position: absolute; right: 22px; bottom: calc(9vh + 18px); pointer-events: auto;
  background: rgba(0, 0, 0, .45); color: #fff; border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 999px; padding: 9px 18px; font-size: 14px; backdrop-filter: blur(6px);
}
#cine button:hover { background: rgba(255, 255, 255, .18); }
@media (max-aspect-ratio: 1/1) { #cine .bar { display: none; } #cine button { bottom: 24px; } }

.doctors { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0 0 16px; }
.doctors .muted { color: var(--muted); font-size: 14px; }
.doctor {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 10px 12px; text-align: center;
  background: #fff; border: 2px solid var(--line); border-radius: 14px; transition: border-color .15s, transform .1s;
}
.doctor:hover { border-color: #a9c4c0; }
.doctor.active { border-color: var(--accent); background: var(--accent-soft); }
.doctor img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #dde5e4; margin-bottom: 4px; }
.doctor b { font-size: 15px; }
.doctor small { color: var(--muted); font-size: 12px; }
button.primary:disabled { opacity: .5; cursor: default; filter: none; }
#doctorChip { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; white-space: nowrap; }
#doctorChip img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; object-position: 50% 20%; }
#closing { border-top: 1px solid var(--line); margin: 4px 0 18px; padding-top: 14px; }
#closing h3 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0 0 10px; line-height: 1.3; }
#closing p { font-size: 14px; line-height: 1.5; color: #2b4543; margin: 10px 0 0; }
#closing .ask { margin: 0 0 12px; }
#closing .cta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
#closing .cta a {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; text-decoration: none; flex: 1 1 auto;
}
#closing .review { background: #2e2647; color: #fff; }
#closing .review span { color: #f2c94c; letter-spacing: 2px; }
#closing .booking { background: #fff; color: #2e2647; border: 2px solid #2e2647; }
#closing .cta a:hover { filter: brightness(1.12); }
