/* Vesper. One layout for every size: the molecule fills the screen; a bar on top, the tools at the bottom
   where a thumb reaches them. Colours follow the system's light or dark setting. */
:root {
  color-scheme: light dark;
  --bg-top: #f7f5f0; --bg-bottom: #e6e2d9; --fog: #ece9e2;
  --ink: #1c2028; --soft: #646b78; --line: rgba(28, 32, 40, .12);
  --panel: rgba(255, 255, 255, .88); --panel-solid: #ffffff; --raised: #f1efea;
  --accent: #5a48d6; --accent-ink: #ffffff; --accent-soft: #e9e6ff;
  --edge: #252a33; --pair: #8f7cf2; --dot: #2a2060;
  --plus: #c9372c; --minus: #2f5fd0; --badge: #1c2028; --badge-ink: #ffffff;
  --shadow: 0 6px 24px rgba(30, 30, 60, .14), 0 1px 3px rgba(30, 30, 60, .10);
  --radius: 16px;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #0d1030; --bg-bottom: #221a46; --fog: #1a173b;
    --ink: #eef0fb; --soft: #a2a7c4; --line: rgba(238, 240, 251, .14);
    --panel: rgba(27, 28, 58, .86); --panel-solid: #1c1d3c; --raised: #2a2b52;
    --accent: #a596ff; --accent-ink: #14122e; --accent-soft: #343068;
    --edge: #05060f; --pair: #b9adff; --dot: #f4f1ff;
    --plus: #ff7a6b; --minus: #7da2ff; --badge: #eef0fb; --badge-ink: #14122e;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { background: var(--bg-bottom); color: var(--ink); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.grow { flex: 1; }
.plain { position: fixed; inset: 40% 10% auto; text-align: center; }

#gl, #over { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { touch-action: none; }
#over { pointer-events: none; }

svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.icon:hover { background: var(--line); }
.icon:disabled { opacity: .32; cursor: default; background: none; }

/* ---- top bar */
#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 6px calc(12px + env(safe-area-inset-left));
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; letter-spacing: .01em; color: var(--accent); }
.brand svg { width: 26px; height: 26px; }
.brand span { color: var(--ink); font-size: 17px; }
.pill {
  margin-left: 8px; display: flex; align-items: baseline; gap: 8px; padding: 7px 13px; border-radius: 999px; min-height: 36px;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  max-width: 46vw; overflow: hidden; white-space: nowrap;
}
.pill b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.pill span { color: var(--soft); font-size: 13px; }
@media (max-width: 430px) { .brand span { display: none; } .pill span { display: none; } }

/* ---- the buttons at the side */
#side {
  position: fixed; right: calc(8px + env(safe-area-inset-right)); top: calc(64px + env(safe-area-inset-top)); z-index: 3;
  display: flex; flex-direction: column; gap: 2px; padding: 3px; border-radius: 15px;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
#tidy.busy svg { animation: turn 1.2s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

/* ---- the dock: card, hint, what to build with, tools */
#dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0 calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  pointer-events: none;
}
#dock > * { pointer-events: auto; width: 100%; max-width: 560px; }
#hint { margin: 0; text-align: center; font-size: 13px; color: var(--soft); pointer-events: none; text-wrap: balance; min-height: 18px; text-shadow: 0 0 6px var(--bg-bottom), 0 0 2px var(--bg-bottom); }

#strip {
  display: flex; gap: 6px; padding: 6px; border-radius: var(--radius);
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
#strip .els {
  flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; border-radius: 12px;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
  padding-right: 16px;
}
#strip .els::-webkit-scrollbar { display: none; }
#strip:empty { display: none; }
.chip {
  flex: none; min-width: 44px; height: 44px; padding: 0 10px; border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 650; background: var(--raised); position: relative;
}
.chip .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28); flex: none; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.wide { padding: 0 14px; font-weight: 600; }
.chip small { font-weight: 500; opacity: .8; }

#tools {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 4px; border-radius: var(--radius);
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
#tools button { height: 54px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--soft); }
#tools button i { display: grid; }
#tools button.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

#toast {
  width: auto !important; max-width: min(92vw, 520px) !important; padding: 9px 14px; border-radius: 12px; font-size: 14px; text-align: center;
  background: var(--ink); color: var(--bg-top); box-shadow: var(--shadow); opacity: 0; transform: translateY(6px); transition: opacity .18s, transform .18s; pointer-events: none !important;
}
#toast.on { opacity: 1; transform: none; }

#card {
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px; user-select: text; -webkit-user-select: text;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
#card h3 { margin: 0 0 2px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
#card h3 .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28); }
#card p { margin: 2px 0; color: var(--soft); }
#card p b, #card .big b { color: var(--ink); font-weight: 650; }
#card .big { font-size: 22px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
#card .big small { font-size: 13px; font-weight: 500; color: var(--soft); margin-left: 6px; }
#card .row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
#card .step { display: inline-flex; align-items: center; background: var(--raised); border-radius: 10px; }
#card .step button { width: 40px; height: 36px; font-size: 18px; font-weight: 600; }
#card .step output { min-width: 34px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
#card canvas { width: 100%; height: 96px; display: block; margin-top: 8px; border-radius: 10px; background: var(--raised); touch-action: none; cursor: ew-resize; }
.btn { height: 38px; padding: 0 14px; border-radius: 10px; background: var(--raised); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.btn.main { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; }

/* ---- sheets */
#shade { position: fixed; inset: 0; z-index: 8; background: rgba(10, 10, 30, .38); }
#sheet {
  position: fixed; z-index: 9; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 620px); max-height: min(86dvh, 760px);
  display: flex; flex-direction: column; background: var(--panel-solid); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom); animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } }
@media (min-width: 700px) { #sheet { bottom: 50%; transform: translate(-50%, 50%); border-radius: 20px; animation: none; } }
#sheet > header { display: flex; align-items: center; padding: 8px 8px 4px 18px; }
#sheet h2 { margin: 0; font-size: 17px; flex: 1; }
#sheet-body { overflow-y: auto; padding: 4px 14px 16px; overscroll-behavior: contain; user-select: text; -webkit-user-select: text; }
#sheet-body h3 { margin: 16px 4px 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); font-weight: 650; }
#sheet-body p { margin: 8px 4px; color: var(--soft); }
#sheet-body p b { color: var(--ink); }
#sheet-body a { color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 2px; }
.item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 10px; border-radius: 12px; text-align: left; width: 100%; }
.item:hover { background: var(--raised); }
.item svg.i { color: var(--accent); flex: none; }
.item span { flex: 1; }
.item small { display: block; color: var(--soft); font-size: 12.5px; }
.item .x { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--soft); }
.switch { width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.item[aria-checked="true"] .switch { background: var(--accent); }
.item[aria-checked="true"] .switch::after { transform: translateX(18px); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; border-radius: 12px; background: var(--raised); margin: 4px 0; }
.seg button { height: 38px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--panel-solid); box-shadow: 0 1px 3px rgba(0, 0, 0, .16); color: var(--accent); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.tile { padding: 10px 12px; border-radius: 12px; background: var(--raised); text-align: left; min-height: 58px; }
.tile:hover { outline: 2px solid var(--accent); }
.tile b { display: block; font-weight: 650; }
.tile small { color: var(--soft); font-size: 12.5px; }

.ptable { display: grid; grid-template-columns: repeat(18, minmax(0, 1fr)); gap: 2px; min-width: 560px; }
.ptable-wrap { overflow-x: auto; padding-bottom: 6px; }
.ptable button { aspect-ratio: 1; border-radius: 6px; font-size: 12px; font-weight: 650; background: var(--raised); position: relative; }
.ptable button::after { content: ""; position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; border-radius: 2px; background: var(--c); }
.ptable button.on { background: var(--accent); color: var(--accent-ink); }
.ptable .gap { visibility: hidden; }

.field { display: flex; gap: 8px; margin: 8px 0; }
.field input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised); color: var(--ink); padding: 0 14px; font: inherit; font-size: 16px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 6px 4px; }
.facts dt { color: var(--soft); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--raised); margin: 8px 4px 4px; }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 4px; font-size: 12.5px; color: var(--soft); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.note { font-size: 12.5px; }
kbd { font: inherit; font-size: 12px; padding: 1px 6px; border-radius: 5px; background: var(--raised); border: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
