:root {
  --bg: #f3f1ea;
  --card: #ffffff;
  --text: #22251f;
  --muted: #6b6f65;
  --line: #dedbd0;
  --green: #3f7d28;
  --green-soft: #e3f0d9;
  --amber: #b26a00;
  --amber-soft: #fbecd2;
  --red: #b3261e;
  --red-soft: #f9dedc;
  --grey-soft: #ecebe6;
  --code-bg: #f1efe8;
  --glass: rgba(160, 205, 230, .3);
  --glass-lip: #d6e8f1;
  --glass-line: #7fa9bf;
  --ghost: #f4fbff;
  --ghost-line: #8fb8d0;
  --ghost-glow: rgba(120, 190, 235, .7);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171914;
    --card: #23261f;
    --text: #e8e9e3;
    --muted: #a2a69a;
    --line: #373b31;
    --green: #7cc35a;
    --green-soft: #2a3b22;
    --amber: #f0b44c;
    --amber-soft: #3d3220;
    --red: #f2827a;
    --red-soft: #46241f;
    --grey-soft: #30332b;
    --code-bg: #1c1e18;
    --glass: rgba(150, 200, 230, .14);
    --glass-lip: #3a4a52;
    --glass-line: #8fb8cf;
    --ghost: #e4f5ff;
    --ghost-line: #a9d2ea;
    --ghost-glow: rgba(140, 210, 255, .8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.top { display: flex; align-items: center; gap: 12px; max-width: 980px; margin: 0 auto 16px; }
.top img { flex: none; }
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: .02em; }
.top .user { margin: 0 0 0 auto; display: flex; align-items: center; gap: 10px; color: var(--muted); }
button.link { width: auto; padding: 6px 12px; background: none; color: var(--muted); border: 1px solid var(--line); font-size: .9rem; }

.login { max-width: 360px; margin: 8vh auto 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; }
.login h1 { margin: 0 0 16px; font-size: 1.4rem; display: flex; align-items: center; gap: 12px; }
.login h1 img { flex: none; }
.login label { display: block; margin: 0 0 14px; color: var(--muted); font-size: .95rem; }
.login input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.login .banner { margin-bottom: 14px; }
.top h1 a { color: inherit; text-decoration: none; }
.top .user a { color: var(--muted); }
.banner.ok { background: var(--green-soft); color: var(--green); }
.form-page { max-width: 560px; }
.form-page h2 { margin: 0 0 16px; font-size: 1.3rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin: 0 0 16px; }
.panel h3 { margin: 8px 0 12px; font-size: 1.05rem; }
.panel h3:first-child { margin-top: 0; }
.panel label { display: block; margin: 0 0 14px; color: var(--muted); font-size: .95rem; }
.panel input:not([type=checkbox]) { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.panel label.check { display: flex; gap: 10px; align-items: center; color: var(--text); }
.panel label.check input { width: 20px; height: 20px; }
.panel .hint { color: var(--muted); font-size: .9rem; }

main { max-width: 980px; margin: 0 auto; }

.banner { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; }
.banner.dry { background: var(--amber-soft); color: var(--amber); }
.banner.err { background: var(--red-soft); color: var(--red); }
.offline { max-width: 980px; margin: 16px auto 0; color: var(--red); }

.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.head { display: flex; align-items: center; gap: 12px; }
.head-text { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.head h2 { margin: 0; font-size: 1.3rem; }

/* The bottle (templates/bottle.html). Off: cork in. Starting: cork wobbles,
   the ghost slowly comes out. Ready: cork beside the bottle, the ghost
   floats. Stopping/held: the ghost slowly goes back in. app.js sets --t so
   the loops keep their rhythm although the cards are replaced every 2 s. */
.bottle { flex: none; overflow: visible; }
/* only the moving parts turn around their own box; the ghost's fixed
   scale in the template must stay around the neck (svg coordinates) */
.bottle .cork, .bottle .ghost-move, .bottle .ghost-blink, .bottle .ghost, .bottle .puffs { transform-box: fill-box; }
.bottle .glass { fill: var(--glass); stroke: var(--glass-line); stroke-width: 2; }
.bottle .lip { fill: var(--glass-lip); stroke: var(--glass-line); stroke-width: 1.5; }
.bottle .shine { fill: none; stroke: #fff; stroke-opacity: .65; stroke-width: 3; stroke-linecap: round; }
.bottle .qblock { fill: #f2c230; stroke: #b8860b; stroke-width: 1.5; }
.bottle .qmark { font: 800 17px system-ui, sans-serif; fill: #fff; stroke: #9a6c00; stroke-width: 1; paint-order: stroke; }
.bottle .cork-body { fill: #c08a55; stroke: #8a5a2b; stroke-width: 1.5; }
.bottle .cork circle, .bottle .cork rect:not(.cork-body):not(.cork-hit) { fill: #8a5a2b; }
.bottle .shine-px { fill: #fff; opacity: .6; }
.bottle.mc .glass { stroke-linejoin: miter; }
.bottle .face-angry { display: none; }
.bottle.spit .face-angry { display: inline; }
.bottle.spit .face-calm { display: none; }
.bottle .ghast-red { fill: #b3261e; }
.bottle .ghast-mouth { fill: #3a1010; }
.bottle .ghost-body.pixel-ghost { fill: var(--ghost); fill-opacity: .8; stroke: var(--ghost-line); stroke-width: 1; }
.bottle .eye-shine { fill: #fff; }
/* the stardew ghost leans away from the mouse (app.js); it turns around the
   tip of its tail, so it stays in the neck */
.bottle .ghost-blink { transform-origin: 50% 100%; transition: transform .7s ease-in-out; }
.card:not(.phase-off) .bottle.sd .ghost { animation-name: ghost-sway; }
@keyframes ghost-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.bottle .ghost-eye { transition: transform .15s ease-out; }
.bottle .leaves { fill: #5fa043; }
.bottle .cork rect.twine { fill: #e6cf96; }

/* fireball the ghast spits at the mouse (app.js) */
.fireball { position: fixed; left: 0; top: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; pointer-events: none;
  z-index: 10; background: #ffcf3a; box-shadow: inset 0 0 0 3px #f07a12, inset 0 0 0 5px #ffa21f, 0 0 12px 3px rgba(255, 120, 0, .7); }
.bottle .cork-hit { fill: transparent; }
.bottle .cork { transform-origin: 50% 50%; transition: transform .5s ease; }
.bottle[data-cork] .cork { cursor: grab; touch-action: none; }
.bottle .cork.dragging { cursor: grabbing; transition: none; }
.bottle .ghast-shade { fill: var(--ghost-line); opacity: .35; }
.bottle .ghast-tear { fill: #9aa3a8; }
.bottle .ghost { pointer-events: none; }
/* --out (0 = in the bottle, 1 = out) comes from the server with the progress
   of a start or stop (data-out); app.js sets it and lets it glide from the
   old value to the new one. Without JavaScript: these fixed values. */
.bottle { --out: 1; }
.phase-off .bottle { --out: 0; }
.phase-starting .bottle, .phase-stopping .bottle { --out: .5; }
.phase-held .bottle { --out: .15; }
/* Out = 0: the ghost sits below the neck (clipped away, templates/bottle.html).
   On its way out it rises through the neck, squeezed narrow, and widens
   once it is above the opening; going back in is the same in reverse. */
.bottle .ghost-move { transform-origin: 50% 100%;
  transform: translateY(calc((1 - var(--out, 0)) * 40px))
             scale(calc(.3 + .7 * var(--out, 0)), calc(.75 + .25 * var(--out, 0)));
  opacity: calc(var(--out, 0) * 20);
  transition: transform 2.2s ease-in-out, opacity .3s linear; }
.bottle .ghost { transform-origin: 50% 100%; }
.bottle .ghost-body { fill: var(--ghost); stroke: var(--ghost-line); stroke-width: 1.2; }
.bottle .ghost-eye { fill: #2b3a44; }
.bottle .ghost-mouth { fill: none; stroke: #2b3a44; stroke-width: 1.5; stroke-linecap: round; }
.bottle .puffs { fill: var(--ghost); stroke: var(--ghost-line); opacity: 0; }

.phase-off .bottle .contents { opacity: .85; }

/* cork out: lying beside the bottle */
.card:not(.phase-off) .bottle .cork { transform: translate(38px, 64px) rotate(80deg); }
.card:not(.phase-off) .bottle .ghost { filter: drop-shadow(0 0 5px var(--ghost-glow));
  animation: ghost-float 3.2s ease-in-out infinite var(--t, 0ms); }

.card.phase-starting .bottle .cork { transform: translate(0, -6px);
  animation: cork-wobble .8s ease-in-out infinite var(--t, 0ms); }
.phase-starting .bottle .puffs,
.phase-stopping .bottle .puffs { animation: puffs 1.6s ease-out infinite var(--t, 0ms); }

.card.phase-unknown .bottle .ghost,
.card.phase-error .bottle .ghost { opacity: .45; filter: grayscale(1); }

@keyframes ghost-float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-4px) rotate(2deg); } }
@keyframes cork-wobble { 0%, 100% { transform: translate(0, -6px) rotate(-10deg); } 50% { transform: translate(0, -9px) rotate(10deg); } }
@keyframes puffs { 0% { opacity: .9; transform: translateY(4px); } 100% { opacity: 0; transform: translateY(-10px); } }

@media (prefers-reduced-motion: reduce) {
  .bottle *, .bottle .ghost, .bottle .ghost-move { animation: none !important; transition: none !important; }
}

.pill { padding: 3px 12px; border-radius: 999px; font-size: .9rem; font-weight: 600; background: var(--grey-soft); color: var(--muted); }
.phase-ready .pill { background: var(--green-soft); color: var(--green); }
.phase-starting .pill, .phase-stopping .pill, .phase-held .pill { background: var(--amber-soft); color: var(--amber); }
.phase-ready { border-color: var(--green); }

.host { margin: 0; display: flex; flex-direction: column; gap: 2px; }
.hint { font-size: .8rem; color: var(--muted); }
code { font: .95rem ui-monospace, "Cascadia Mono", Consolas, monospace; overflow-wrap: anywhere; }
.host code { background: var(--code-bg); padding: 6px 10px; border-radius: 8px; user-select: all; -webkit-user-select: all; }

progress { width: 100%; height: 10px; accent-color: var(--amber); }
.step { margin: 0; display: flex; justify-content: space-between; gap: 8px; }
.time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.result { margin: 0; padding: 8px 12px; border-radius: 8px; }
.result.ok { background: var(--green-soft); color: var(--green); }
.result.bad { background: var(--red-soft); color: var(--red); }
.result.warn { background: var(--amber-soft); color: var(--amber); font-size: .9rem; }
.result.neutral { background: var(--grey-soft); color: var(--muted); }

.buttons { display: flex; gap: 10px; }
.buttons form { flex: 1; margin: 0; }
.buttons:empty { display: none; }
button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 650;
  font-size: 1.1rem;
  cursor: pointer;
}
button.start { background: var(--green); color: #fff; }
button.stop { background: var(--grey-soft); color: var(--red); border: 1px solid var(--red); }
button:disabled { opacity: .5; cursor: wait; }
@media (prefers-color-scheme: dark) { button.start { color: #10200a; } }

.meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: .85rem; color: var(--muted); }

details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
details pre {
  margin: 8px 0 0;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  background: var(--code-bg);
  border-radius: 8px;
  font: .8rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
}

.total { margin: 20px 0 0; font-size: 1.05rem; }
.updated { color: var(--muted); font-size: .85rem; margin-left: 8px; }

.weblog { max-width: 980px; margin: 24px auto 0; }
.weblog summary { cursor: pointer; color: var(--muted); }
.weblog pre { max-height: 50vh; overflow: auto; font-size: .8rem; white-space: pre-wrap; word-break: break-word; }
.panel fieldset { border: 1px solid var(--line, #ccc); border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; }
.panel legend { font-weight: 600; padding: 0 .25rem; }
