/* Par Excellence - UI styles. Locked palette, system fonts, no external assets. */
:root {
  --white: #F7F9FB;
  --teal: #2BA6A0;
  --teal-d: #1F8782;
  --navy: #1F3247;
  --coral: #FF7A66;
  --yellow: #FFC94D;
  --mint: #BDE8D5;
  --ground: #DCEBF5;
  --line: #E3EAF1;
  --muted: #62748A;
  --card: #FFFFFF;
  --shadow: 0 6px 18px rgba(31, 50, 71, 0.16);
  --r: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--ground); color: var(--navy);
  font-family: var(--font); font-size: 15px; line-height: 1.35;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }
#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

button {
  font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0;
  touch-action: manipulation;
}
button:disabled { cursor: default; opacity: 0.5; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 999px;
  background: var(--white); color: var(--navy); font-weight: 800; letter-spacing: 0.03em; font-size: 13px;
  box-shadow: inset 0 0 0 2px var(--line); transition: transform 0.08s, background 0.12s;
}
.btn:hover:not(:disabled) { background: #fff; box-shadow: inset 0 0 0 2px var(--teal); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--teal); color: #fff; box-shadow: 0 3px 0 var(--teal-d); }
.btn.primary:hover:not(:disabled) { background: #31b5ae; box-shadow: 0 3px 0 var(--teal-d); }
.btn.warn { background: var(--coral); color: #fff; box-shadow: 0 3px 0 #d95f4c; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 12px; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 52px; font-size: 16px; padding: 12px 26px; }
.ib {
  min-width: 36px; height: 36px; padding: 0 8px; border-radius: 12px; background: var(--white);
  font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 2px var(--line);
}
.ib:hover { box-shadow: inset 0 0 0 2px var(--teal); }
.ib.on { background: var(--teal); color: #fff; box-shadow: none; }
.ib-wide { padding: 0 12px; }
.ib svg, .tool svg { width: 18px; height: 18px; display: block; }

/* ---- HUD ---- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; left: 8px; right: 8px; top: 8px; top: calc(8px + env(safe-area-inset-top));
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px;
  padding: 6px 8px; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
}
.tb-stats { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.stat {
  padding: 5px 10px; border-radius: 999px; background: var(--white); font-weight: 700; font-size: 13px;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
#tb-day { background: var(--navy); color: #fff; }
.stat-budget { background: #FFF3D1; }
.stat.bad { background: #FFE2DC; color: #B03A28; }
.stat.good { background: #E2F5EC; color: #17726D; }
.tb-ctl { display: flex; gap: 4px; align-items: center; margin-left: auto; }

#tb-time { order: 2; }
.tb-ctl { order: 3; }
.stat-time { background: #EEF4F8; }
#goalcard {
  position: absolute; left: 8px; top: 66px; top: calc(var(--tb-h, 58px) + 8px); max-width: min(420px, calc(100vw - 16px));
  padding: 8px 12px; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  font-size: 13px; font-weight: 700;
}
#goalcard .ticks { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.tick { width: 16px; height: 16px; border-radius: 50%; background: var(--line); }
.tick.on { background: var(--teal); box-shadow: inset 0 0 0 3px var(--mint); }
.tick.miss { background: #FFD3CB; }
#goalcard .coach.over { color: #B03A28; }
#goalcard .coach { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); font-weight: 600; font-size: 12.5px; color: #3C4E63; }

#toolbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 6px; padding: 6px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  max-width: calc(100vw - 16px);
}
.tool {
  min-height: 44px; padding: 0 16px; border-radius: 16px; background: var(--white); font-weight: 800;
  letter-spacing: 0.04em; font-size: 13px; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 2px var(--line); white-space: nowrap;
}
.tool:hover { box-shadow: inset 0 0 0 2px var(--teal); }
.tool.on { background: var(--navy); color: #fff; box-shadow: none; }
.tool.primary { background: var(--teal); color: #fff; box-shadow: 0 3px 0 var(--teal-d); padding: 0 20px; }
.tool.primary.run { background: var(--yellow); color: var(--navy); box-shadow: 0 3px 0 #dba92f; }
.tool-icon { padding: 0 12px; }
.tool.primary.pulse { animation: callout 1.6s ease-in-out infinite; }
@keyframes callout {
  0%, 100% { box-shadow: 0 3px 0 var(--teal-d), 0 0 0 0 rgba(43, 166, 160, 0.55); }
  55% { box-shadow: 0 3px 0 var(--teal-d), 0 0 0 9px rgba(43, 166, 160, 0); }
}

#hintbar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 76px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; max-width: calc(100vw - 16px);
  background: var(--navy); color: #fff; border-radius: 999px; box-shadow: var(--shadow); font-weight: 700; font-size: 13px;
}
#hintbar .hint-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hintbar .hint-text.bad { color: #FFB8AC; }
#hintbar .btn { min-height: 34px; padding: 4px 12px; box-shadow: none; }

/* ---- side panel (bottom sheet on phones) ---- */
#panel {
  position: absolute; right: 8px; top: 66px; top: calc(var(--tb-h, 58px) + 8px); bottom: 76px; width: 360px; max-width: calc(100vw - 16px);
  display: flex; flex-direction: column; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  overflow: hidden;
}
#panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 10px 16px;
  background: var(--navy); color: #fff;
}
#panel-head h2 { margin: 0; font-size: 15px; letter-spacing: 0.04em; font-weight: 800; }
#panel-head .ib { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: none; }
#panel-body { flex: 1; overflow-y: auto; padding: 10px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.sec { margin: 12px 2px 6px; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.sec:first-child { margin-top: 2px; }
.card { background: var(--white); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 800; }
.sub { font-size: 12px; color: var(--muted); }
.price { font-weight: 800; color: #9A6A00; background: #FFF3D1; border-radius: 999px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.lock { font-weight: 700; font-size: 12px; color: var(--muted); background: var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.badge { display: inline-block; font-weight: 800; font-size: 11px; letter-spacing: 0.05em; border-radius: 999px; padding: 3px 9px; background: var(--line); }
.badge.bad { background: var(--coral); color: #fff; }
.badge.warnb { background: var(--yellow); color: var(--navy); }
.badge.good { background: var(--mint); color: #17726D; }
.icon { flex: none; display: block; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv b { font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; background: var(--teal); border-radius: 999px; }
.bar.hot > i { background: var(--coral); }
.stack > * + * { margin-top: 6px; }
.note { font-size: 12px; color: var(--muted); padding: 2px 4px 6px; }

/* build menu */
.build-item { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.build-item > .grow { flex: 1 1 150px; }
.build-item > .lock, .build-item > .badge { margin-left: auto; }
.build-item.locked { opacity: 0.72; }
.build-item .btn { flex: none; }

/* pocket editor */
.pocket { padding: 8px; }
.pocket .steps { display: flex; align-items: center; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.pocket .steps span { font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 2px 0 4px; }
.step {
  width: 32px; height: 32px; border-radius: 10px; background: #fff; font-weight: 900; font-size: 16px;
  box-shadow: inset 0 0 0 2px var(--line); display: inline-flex; align-items: center; justify-content: center;
}
.step:hover { box-shadow: inset 0 0 0 2px var(--teal); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px 4px 6px; border-radius: 999px; background: #fff;
  font-weight: 700; font-size: 12px; box-shadow: inset 0 0 0 2px var(--line);
}
.chip:hover { box-shadow: inset 0 0 0 2px var(--teal); }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg button { text-align: left; padding: 8px 10px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); }
.seg button.on { box-shadow: inset 0 0 0 2px var(--teal); background: #EAF7F5; }
.switch { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.switch i { flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.15s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(31, 50, 71, 0.3); transition: left 0.15s; }
.switch.on i { background: var(--teal); }
.switch.on i::after { left: 21px; }

/* stock table */
.stock-row { display: grid; grid-template-columns: 26px 1fr repeat(4, 48px); gap: 4px; align-items: center; padding: 6px 2px; border-bottom: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
.stock-row.head { font-size: 10px; font-weight: 800; letter-spacing: 0.04em; color: var(--muted); text-transform: uppercase; }
.stock-row > span { text-align: right; }
.stock-row > span.l { text-align: left; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cover-low { color: #B03A28; font-weight: 800; }
.cover-high { color: #9A6A00; font-weight: 800; }
.chart { display: block; width: 100%; height: 54px; margin: 2px 0 6px; }
.legend { font-size: 11px; color: var(--muted); display: flex; gap: 12px; padding: 0 2px 4px; }
.legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ---- toasts ---- */
#toasts { position: fixed; z-index: 45; left: 50%; top: 116px; top: calc(var(--tb-h, 58px) + 58px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: var(--navy); color: #fff; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; box-shadow: var(--shadow); animation: pop 0.18s ease-out; text-align: center; }
.toast.bad { background: var(--coral); }
.toast.good { background: var(--teal); }
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes pop { from { transform: translateY(-6px) scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- overlays ---- */
#overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(31, 50, 71, 0.38); padding: 12px; overflow-y: auto;
}
#overlay.solid { background: var(--ground); }
.sheet {
  width: 100%; max-width: 520px; max-height: 100%; overflow-y: auto; background: var(--card); border-radius: 24px;
  box-shadow: var(--shadow); padding: 20px; animation: pop 0.2s ease-out; margin: auto;
}
.sheet.wide { max-width: 640px; }
.sheet h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.04em; text-align: center; }
.sheet h1.fail { color: #C94A36; }
.sheet h3 { margin: 14px 0 4px; font-size: 13px; letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
.sheet p { margin: 6px 0; }
.center { text-align: center; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.btn-row .btn { flex: 1 1 140px; }

.menu { text-align: center; background: transparent; box-shadow: none; padding: 8px; }
.menu canvas { width: 100%; max-width: 460px; height: auto; display: block; margin: 0 auto; }
.menu .subtitle { font-weight: 800; letter-spacing: 0.22em; font-size: 13px; color: var(--teal-d); margin: 6px 0 22px; }
.menu .btn-col { max-width: 300px; margin: 0 auto; }
.menu footer { margin-top: 26px; font-size: 12px; color: var(--muted); }
.menu .menu-mute { margin-top: 14px; }

.chapter { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 16px; background: var(--white); margin-bottom: 8px; box-shadow: inset 0 0 0 2px transparent; }
.chapter:not(:disabled):hover { box-shadow: inset 0 0 0 2px var(--teal); }
.chapter .num { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--teal); color: #fff; font-weight: 900; display: flex; align-items: center; justify-content: center; }
.chapter:disabled .num { background: #A9B6C4; }
.stars { display: inline-flex; gap: 2px; flex: none; }
.stars svg { width: 20px; height: 20px; }
.stars.big svg { width: 54px; height: 54px; }
.stars.big { display: flex; justify-content: center; gap: 8px; margin: 10px 0; }
.star-on { fill: var(--yellow); }
.star-off { fill: var(--line); }
.stars.big .star-on { animation: starpop 0.5s ease-out backwards; }
.stars.big svg:nth-child(2) .star-on { animation-delay: 0.25s; }
.stars.big svg:nth-child(3) .star-on { animation-delay: 0.5s; }
@keyframes starpop { from { transform: scale(0.2); opacity: 0; } 60% { transform: scale(1.25); } to { transform: none; opacity: 1; } }
.stars svg path { transform-origin: 50% 50%; transform-box: fill-box; }
.checks { list-style: none; padding: 0; margin: 8px 0; }
.checks li { padding: 4px 0 4px 26px; position: relative; font-size: 14px; }
.checks li::before { content: ""; position: absolute; left: 2px; top: 7px; width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.checks li.ok::before { background: var(--teal); box-shadow: inset 0 0 0 3px var(--mint); }
.real { background: #EAF7F5; border-radius: 16px; padding: 12px 14px; margin-top: 12px; font-size: 14px; }
.real .tag { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--teal-d); }
.real h4 { margin: 2px 0 6px; font-size: 15px; }
.report .kv { font-size: 15px; padding: 7px 2px; }
.gloss dt { font-weight: 800; margin-top: 8px; }
.gloss dd { margin: 0; color: #3C4E63; font-size: 14px; }
.mentor { display: flex; align-items: center; gap: 12px; margin: 10px 0 12px; padding: 10px; border-radius: 16px; background: #EEF7F4; font-size: 14px; }
.mentor .icon { border-radius: 50%; flex: none; background: var(--mint); }
.loopchain { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto; }
.card.loop.closed { box-shadow: inset 0 0 0 2px var(--mint); }
.warn-text { color: #C2503E; font-weight: 700; }
.howto { padding-left: 20px; margin: 6px 0; }
.howto li { margin: 5px 0; }
table.ctl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ctl th, table.ctl td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.ctl th { font-size: 11px; letter-spacing: 0.05em; color: var(--muted); text-transform: uppercase; }

/* ---- Arthur speech card ---- */
#speech {
  position: fixed; z-index: 50; left: 12px; bottom: 80px; bottom: calc(80px + env(safe-area-inset-bottom));
  width: 440px; max-width: calc(100vw - 24px);
  display: flex; align-items: flex-start; gap: 10px; padding: 10px; background: var(--card); border-radius: 20px;
  box-shadow: var(--shadow), inset 0 0 0 2px var(--mint); animation: pop 0.2s ease-out;
}
#speech-face { border-radius: 50%; flex: none; width: 64px; height: 64px; background: var(--mint); object-fit: cover; object-position: 50% 22%; }
.speech-main { flex: 1; min-width: 0; }
.speech-name { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--teal-d); }
#speech-text { font-size: 15px; line-height: 1.35; user-select: text; -webkit-user-select: text; }
.speech-btns { display: flex; flex-direction: column; gap: 4px; flex: none; }
.speech-btns .ib { height: 30px; font-size: 11px; }

/* placement and tube-link modes show the hint bar: Arthur's card moves up so ROTATE, PLACE and X stay reachable */
body.hint-on #speech { bottom: 132px; bottom: calc(132px + env(safe-area-inset-bottom)); }
@media (min-width: 721px) {
  body.sheet-open #speech { max-width: max(250px, calc(100vw - 396px)); }
}
/* ---- phones: panels become bottom sheets ---- */
@media (max-width: 720px) {
  body { font-size: 14px; }
  #topbar { left: 4px; right: 4px; top: 4px; top: calc(4px + env(safe-area-inset-top)); padding: 4px; gap: 4px; border-radius: 14px; }
  .stat { padding: 4px 7px; font-size: 12px; }
  .ib { min-width: 32px; height: 32px; padding: 0 6px; font-size: 12px; border-radius: 10px; }
  #goalcard { left: 4px; top: 88px; top: calc(var(--tb-h, 84px) + 4px); padding: 6px 10px; font-size: 12px; }
  #tb-time { order: 3; flex: 1 1 100%; text-align: center; padding: 3px 8px; font-size: 11.5px; }
  .tb-ctl { order: 2; }
  #goalcard .ticks { margin-top: 4px; }
  .tick { width: 12px; height: 12px; }
  #toolbar { left: 4px; right: 4px; transform: none; bottom: 4px; bottom: calc(4px + env(safe-area-inset-bottom)); gap: 4px; padding: 4px; border-radius: 18px; }
  .tool { flex: 1 1 auto; padding: 0 8px; font-size: 12px; min-height: 44px; }
  .tool.primary { padding: 0 10px; flex: 1.6 1 auto; }
  .tool-icon { flex: 0 0 40px; padding: 0; }
  #hintbar { bottom: 58px; bottom: calc(58px + env(safe-area-inset-bottom)); }
  #panel {
    left: 0; right: 0; top: auto; bottom: 62px; bottom: calc(62px + env(safe-area-inset-bottom));
    width: auto; max-width: none; height: 46vh; border-radius: 20px 20px 0 0;
    box-shadow: 0 -6px 18px rgba(31, 50, 71, 0.18);
  }
  #panel-head { padding: 8px 8px 8px 14px; }
  #panel-head::before { content: ""; position: absolute; left: 50%; top: 4px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); }
  #panel-head { position: relative; }
  body.sheet-open #hintbar { bottom: calc(46vh + 68px); }
  #speech { left: 6px; right: 6px; width: auto; max-width: none; bottom: 62px; bottom: calc(62px + env(safe-area-inset-bottom)); padding: 8px; }
  body.sheet-open #speech { bottom: calc(46vh + 68px); bottom: calc(46vh + 68px + env(safe-area-inset-bottom)); }
  body.hint-on #speech { bottom: 112px; bottom: calc(112px + env(safe-area-inset-bottom)); }
  body.sheet-open.hint-on #speech { bottom: calc(46vh + 122px); bottom: calc(46vh + 122px + env(safe-area-inset-bottom)); }
  /* a report or menu sheet is open: Arthur's card sits at the very bottom and the sheet ends above it, so
     NEXT DAY and the other buttons are never under the card */
  body.overlay-on #speech { bottom: 6px; bottom: calc(6px + env(safe-area-inset-bottom)); }
  body.overlay-on.speech-on #overlay { padding-bottom: calc(var(--speech-h, 120px) + 14px); padding-bottom: calc(var(--speech-h, 120px) + 14px + env(safe-area-inset-bottom)); }
  /* long placement hints wrap to a second line instead of losing the instruction */
  /* (centred with auto margins: left 50% plus a transform would cap the bar at half the screen width) */
  #hintbar { left: 8px; right: 8px; transform: none; margin: 0 auto; width: -moz-fit-content; width: fit-content; border-radius: 20px; }
  #hintbar .hint-text { white-space: normal; overflow: visible; line-height: 1.2; min-width: 0; }
  #hintbar .btn { flex: none; }
  #goalcard .coach { max-width: none; font-size: 12px; }
  #speech-face { width: 48px; height: 48px; }
  #speech-text { font-size: 14px; }
  #toasts { top: 205px; top: calc(var(--tb-h, 84px) + 120px); }
  body.sheet-open #goalcard { display: none; }
  body.sheet-open #toasts { top: 92px; top: calc(var(--tb-h, 84px) + 8px); }
  .sheet { padding: 16px 14px; border-radius: 20px; }
  .sheet h1 { font-size: 19px; }
  .stars.big svg { width: 44px; height: 44px; }
  .stock-row { grid-template-columns: 22px 1fr repeat(4, 42px); font-size: 12px; }
}
@media (max-width: 400px) {
  .tb-ctl { gap: 3px; }
  .stat { padding: 4px 6px; font-size: 11.5px; }
  .ib-wide { padding: 0 7px; }
}

/* ---- third pass: illustrations, medication rooms, stock taking, time ---- */
img.gone { display: none !important; }
#panel-hero { margin: -10px -10px 10px; height: 150px; background: linear-gradient(#B7DBF3, #D3EAF8); overflow: hidden; }
/* The illustrations are square with their own painted background. The picture is shown whole in the middle of the
   banner; behind it a blurred, enlarged copy of the same picture fills the banner, and the picture's left and right
   edges fade into it, so there is no lighter square with hard vertical seams. */
#panel-hero { position: relative; --hh: 150px; }
#panel-hero .hero-bg { position: absolute; left: -16px; top: -16px; width: calc(100% + 32px); height: calc(100% + 32px); object-fit: cover; filter: blur(14px); }
#panel-hero .hero-bg.fb { display: none; }
#panel-hero .hero { position: relative; display: block; width: 100%; height: 100%; object-fit: contain;
  -webkit-mask-image: linear-gradient(90deg, transparent calc(50% - var(--hh) / 2), #000 calc(50% - var(--hh) / 2 + 22px), #000 calc(50% + var(--hh) / 2 - 22px), transparent calc(50% + var(--hh) / 2));
  mask-image: linear-gradient(90deg, transparent calc(50% - var(--hh) / 2), #000 calc(50% - var(--hh) / 2 + 22px), #000 calc(50% + var(--hh) / 2 - 22px), transparent calc(50% + var(--hh) / 2)); }
#panel-hero .hero.fb { padding: 12px; -webkit-mask-image: none; mask-image: none; }
.saves { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 2px 2px; }
.note.tnote { font-size: 11px; padding-bottom: 8px; }
.sub.rec { color: #8A5A00; }
.name.big { font-size: 17px; }
.name.sm { font-size: 13px; }
.dot { flex: none; display: inline-block; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(31, 50, 71, 0.15); }
.link { color: var(--teal-d); font-weight: 800; text-decoration: underline; font-size: inherit; }
.chip.on { background: var(--teal); color: #fff; box-shadow: none; }
.chip.no { opacity: 0.6; background: var(--line); box-shadow: none; text-decoration: line-through; }
.chip:disabled { opacity: 0.45; }
.ivl { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ivl .chip { padding: 6px 12px; min-height: 32px; }
.card.count.over { box-shadow: inset 0 0 0 2px var(--coral); }
.check { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 6px 8px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); min-height: 44px; }
.check.on { box-shadow: inset 0 0 0 2px var(--teal); background: #EAF7F5; }
.check i { flex: none; width: 22px; height: 22px; border-radius: 7px; box-shadow: inset 0 0 0 2px #A9B6C4; position: relative; }
.check.on i::after { content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg); }
.build-item.tap { cursor: pointer; }
.build-item.tap:hover { box-shadow: inset 0 0 0 2px var(--line); }
.tabs { display: flex; gap: 4px; padding: 3px; margin-bottom: 10px; background: var(--white); border-radius: 12px; }
.tabs button { flex: 1; min-height: 34px; border-radius: 9px; font-weight: 800; font-size: 12.5px; letter-spacing: 0.02em; color: var(--muted); }
.tabs button.on { background: var(--navy); color: #fff; }
.concept { display: flex; gap: 10px; align-items: center; padding: 8px; margin-bottom: 8px; border-radius: 14px; background: #EEF7F4; }
.concept-pic { flex: none; width: 96px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--ground); }
.card .concept { margin-bottom: 0; background: #fff; }
.timebars { display: block; width: 100%; max-width: 320px; height: auto; margin: 8px auto 0; }
.worth { margin-top: 8px; padding: 6px 10px; border-radius: 10px; background: #FFF3D1; color: #7A5300; font-weight: 800; text-align: center; font-size: 14px; }
.timesec { background: var(--white); border-radius: 16px; padding: 8px; }
.timesec .concept { background: #fff; }
.trow { display: flex; gap: 10px; align-items: center; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.trow.zero { opacity: 0.6; }
.tnum { text-align: right; flex: none; max-width: 55%; font-variant-numeric: tabular-nums; }
.tnum .pos { color: #17726D; }
.tnum .neg { color: #B03A28; }
.kv.tt { align-items: center; }
.kv.tt b { white-space: nowrap; }
.ttot { margin-top: 4px; }
.ttot .kv { font-weight: 700; }

/* main menu backdrop: the picture fills the screen, a soft scrim and a frosted card keep logo and buttons readable */
.backdrop { position: fixed; inset: 0; z-index: 0; background: var(--ground); overflow: hidden; pointer-events: none; }
.backdrop-img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 100%; display: block; }
.backdrop-img.fb { object-fit: contain; }
.backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(220, 235, 245, 0.55), rgba(220, 235, 245, 0.05) 55%, rgba(31, 50, 71, 0.12)); }
#overlay > .sheet { position: relative; z-index: 1; }
.backdrop + .menu { background: rgba(247, 249, 251, 0.86); box-shadow: var(--shadow); padding: 22px 22px 16px; max-width: 460px; border-radius: 28px; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.backdrop + .menu footer { color: #46586C; }

/* chapter picker thumbnails and the chapter intro */
.thumb { position: relative; flex: none; width: 96px; height: 64px; border-radius: 12px; overflow: hidden; background: var(--ground); }
.thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .num { position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; font-size: 12px; box-shadow: 0 0 0 2px #fff; }
.chapter:disabled .thumb-img { filter: grayscale(1); opacity: 0.6; }
.intro { padding: 0 0 18px; overflow-x: hidden; }
.intro > *:not(.intro-pic) { margin-left: 18px; margin-right: 18px; }
.intro h1 { margin-top: 14px; }
.intro-pic { position: relative; background: linear-gradient(#B7DBF3, #D3EAF8); aspect-ratio: 1024 / 688; max-height: 46vh; width: 100%; overflow: hidden; border-radius: 24px 24px 0 0; }
.intro-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro-img.fb { object-fit: contain; }
.intro-tag { position: absolute; left: 14px; top: 14px; padding: 4px 12px; border-radius: 999px; background: var(--navy); color: #fff; font-weight: 800; font-size: 12px; letter-spacing: 0.1em; }
.mentor .face { width: 64px; height: 64px; object-fit: cover; object-position: 50% 22%; }
.real-pic { float: right; width: 120px; height: 80px; margin: 0 0 6px 10px; border-radius: 12px; object-fit: cover; background: var(--ground); }
.real::after { content: ""; display: block; clear: both; }

@media (max-width: 720px) {
  #panel-hero { height: 104px; margin: -10px -10px 8px; --hh: 104px; }
  .concept-pic { width: 76px; height: 52px; }
  .thumb { width: 72px; height: 48px; }
  .real-pic { width: 84px; height: 56px; margin-top: 18px; }
  .backdrop + .menu { padding: 16px 16px 12px; }
  .trow { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- scale-model renderer (render3d.js): the playing field is a WebGL canvas under the overlay canvas */
#world3d { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.px-gl body, html.px-gl { background: #dfe6ee; }
/* main menu: the live model is the backdrop; the still picture stays as the fallback when the model is not running */
.px-gl #overlay.solid { background: transparent; }
.px-gl .backdrop { display: none; }
#soundgate { position: fixed; right: 14px; bottom: 14px; z-index: 60; font: inherit; font-weight: 800; font-size: 13px; letter-spacing: 0.02em; color: #1F3247;
  background: #FFC94D; border: 0; border-radius: 6px; padding: 10px 14px; box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 6px 16px rgba(31,50,71,0.28); cursor: pointer; }
#soundgate:hover { filter: brightness(1.05); }
#soundgate.hidden { display: none; }
@media (max-width: 720px) { #soundgate { bottom: 78px; right: 8px; padding: 8px 10px; } }

/* ---- fixes after review: goal conditions, why a day did not count, shelves outside the time total ---- */
#goalcard .goal-detail { margin-top: 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); max-width: 420px; }
.whynot { margin: 2px auto 10px; padding: 8px 12px 8px 28px; max-width: 520px; border-radius: 12px; background: #FFF3D1; color: #5E4200; font-size: 13px; font-weight: 600; text-align: left; }
.whynot li { margin: 2px 0; }
.aside-row { margin-top: 8px; padding: 8px 10px; border-radius: 10px; border: 1px dashed var(--line); background: #F7F9FB; font-size: 13px; }
.save-warn { color: #8A5A00; font-weight: 700; }
/* panels as printed card beside the model: no frosted glass over the live picture */
.px-gl .backdrop + .menu, .px-gl #overlay.solid > .sheet.menu { background: #F7F9FB; -webkit-backdrop-filter: none; backdrop-filter: none; border-radius: 10px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.9) inset, 0 18px 40px rgba(31,50,71,0.28), 0 2px 4px rgba(31,50,71,0.18); }

/* ---- staff: fatigue bars, the next dosing time ---- */
.stat-next { background: #EAF7F5; cursor: pointer; order: 2; }
@media (max-width: 720px) {
  /* phones: the next dosing time shares the last row of the top bar with the staff time saved */
  #tb-next { order: 3; padding: 3px 8px; font-size: 11.5px; }
  #tb-next .wide { display: none; }
  #tb-time { flex: 1 1 40%; }
}
.stat-next:empty { display: none; }
.fats { display: inline-flex; gap: 3px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.fat { display: inline-block; width: 26px; height: 8px; border-radius: 999px; background: #D3DDE7; overflow: hidden; }
.fat > i { display: block; height: 100%; background: var(--teal); border-radius: 999px; }
.fat.tired > i { background: var(--coral); }
.fat.rest > i { background: var(--yellow); }
.sub.pad { padding: 4px 4px 2px; }
.tabs button { padding: 0 4px; }
@media (max-width: 720px) { .tabs button { font-size: 11.5px; } }

/* ---- The Sandbox: setup screen ---- */
.sheet.still { animation: none; }   /* drawn again after a change: no entrance */
.sandbox .card { padding: 4px 10px; }
.sb-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sb-row:last-child { border-bottom: 0; }
.sb-row .grow { flex: 1 1 150px; min-width: 0; }
.sb-num { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.sb-num b { min-width: 62px; text-align: center; font-size: 15px; font-variant-numeric: tabular-nums; }
.sb-num .step:disabled { opacity: 0.35; cursor: default; }
.sb-seg { display: inline-flex; flex: none; border-radius: 12px; background: var(--line); padding: 2px; gap: 2px; }
.sb-seg button { min-height: 34px; padding: 0 11px; border-radius: 10px; font-weight: 800; font-size: 12px; color: var(--navy); background: transparent; white-space: nowrap; }
.sb-seg button:hover:not(:disabled):not(.on) { background: rgba(255, 255, 255, 0.6); }
.sb-seg button.on { background: var(--teal); color: #fff; }
.sb-seg button:disabled { opacity: 0.4; cursor: default; }
.sb-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sb-presets .chapter { margin: 0; align-items: flex-start; }
.sb-preset.on { box-shadow: inset 0 0 0 2px var(--teal); }
.sb-saved { align-items: center; gap: 8px; padding: 8px 10px !important; }
.sb-name { flex: 1 1 160px; min-width: 0; height: 40px; padding: 0 12px; border: 0; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 2px var(--line);
  font: inherit; font-weight: 700; color: var(--navy); }
.sb-name:focus { outline: 3px solid var(--yellow); outline-offset: 1px; }
.sb-sum { margin-top: 14px; padding: 10px !important; }
@media (max-width: 560px) {
  .sb-presets { grid-template-columns: 1fr; }
  .sb-seg button { padding: 0 9px; }
}

/* ---- the review after a chapter ---- */
.review { background: var(--white); border-radius: 16px; padding: 12px 14px; margin-top: 6px; border-left: 5px solid var(--teal); }
.review.great { border-left-color: var(--yellow); }
.review.tough { border-left-color: #8FB8D9; }
.review .mentor { margin: 0 0 4px; }
.review .sec { margin: 10px 0 2px; }
.review .checks { margin: 2px 0; }
.review .checks.held li::before { background: var(--yellow); border-radius: 4px; }
.review .hints { margin: 4px 0 2px; padding-left: 22px; font-size: 14px; }
.review .hints li { padding: 3px 0; }
.review .hints li::marker { font-weight: 800; color: var(--teal-d); }

/* ---- music volume (main menu, pause menu) ---- */
.vol { display: flex; align-items: center; gap: 10px; max-width: 300px; margin: 14px auto 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.vol-name { flex: none; }
.vol input { flex: 1 1 auto; min-width: 0; height: 28px; accent-color: var(--teal); cursor: pointer; }
.vol b { flex: none; width: 40px; text-align: right; color: var(--navy); font-variant-numeric: tabular-nums; }
