/* Decant — an apothecary's shelf by candlelight. Self-contained. */

@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600;700&family=Geist+Mono:wght@400;500;600&display=swap");

:root{
  --ink: #f6ead7;
  --dim: rgba(246, 234, 215, 0.66);
  --faint: rgba(246, 234, 215, 0.36);
  --candle: #ffb54a;
  --glow: #ffd27a;
  --line: rgba(255, 214, 160, 0.18);
  --panel: rgba(9, 12, 16, 0.9);
  --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after{ box-sizing: border-box; }
html, body{
  height: 100%; margin: 0; overflow: hidden;
  color: var(--ink);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
body{ background: #06090d; }
#c{
  position: fixed; inset: 0; display: block; width: 100%; height: 100%;
  touch-action: none;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}

/* ---------- HUD ---------- */
.hud{
  position: fixed; z-index: 5; pointer-events: none;
  top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 22px; align-items: flex-end;
  padding: 7px 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(9, 12, 16, 0.62);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.hud[hidden]{ display: none; }
.hud__cell{ display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 50px; }
.hud__k{ font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--faint); }
.hud__cell > span:not(.hud__k){ font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
#moves{ color: var(--glow); }
#best.is-target{ color: var(--candle); }

/* ---------- Tip ---------- */
.tip{
  position: fixed; z-index: 5; pointer-events: none;
  left: 50%; transform: translateX(-50%);
  top: max(74px, calc(env(safe-area-inset-top) + 64px));
  width: max-content; max-width: min(92vw, 520px);
  padding: 8px 14px; border-radius: 10px;
  font-size: 0.72rem; line-height: 1.45; letter-spacing: 0.02em; text-align: center;
  color: var(--ink);
  background: rgba(20, 16, 12, 0.82); border: 1px solid rgba(255, 196, 120, 0.3);
  box-shadow: 0 8px 30px -10px rgba(0, 0, 0, 0.8);
  transition: opacity 500ms ease;
}
.tip[hidden]{ display: none; }
.tip.is-out{ opacity: 0; }

/* ---------- Toolbar ---------- */
.bar{
  position: fixed; z-index: 6;
  left: 50%; transform: translateX(-50%);
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
  display: flex; gap: 8px;
}
.bar[hidden]{ display: none; }
.bar__btn{
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.04em;
  padding: 11px 14px; border-radius: 999px;
  color: var(--ink);
  background: rgba(14, 16, 20, 0.74); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  touch-action: manipulation;
}
.bar__btn span{ font-size: 0.95rem; line-height: 1; }
.bar__btn:hover{ border-color: var(--candle); }
.bar__btn:active{ transform: scale(0.95); }
.bar__btn:disabled{ opacity: 0.35; pointer-events: none; }
.bar__btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(255, 181, 74, 0.45); }
.bar__btn.is-on{ border-color: var(--candle); background: rgba(70, 44, 14, 0.7); }

/* ---------- Sound ---------- */
.sound-btn{
  position: fixed; z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(9, 12, 16, 0.6); color: var(--ink);
  font-size: 15px; cursor: pointer; backdrop-filter: blur(8px);
  transition: transform 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.sound-btn:hover{ transform: translateY(-1px); border-color: var(--candle); }
.sound-btn[aria-pressed="false"]{ opacity: 0.45; }
.sound-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(255, 181, 74, 0.45); }

/* ---------- Overlay ---------- */
.overlay{
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  background: radial-gradient(90% 70% at 50% 46%, rgba(10, 8, 6, 0.45), rgba(3, 4, 6, 0.9));
  transition: opacity 260ms ease;
  overflow-y: auto;
  touch-action: pan-y;
}
.overlay[hidden]{ display: none; }
.overlay.is-out{ opacity: 0; pointer-events: none; }
.panel{
  max-width: 500px; width: 100%; text-align: center; margin: auto;
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.85), 0 0 80px -30px rgba(255, 170, 70, 0.45);
}
.panel__eyebrow{ margin: 0 0 4px; font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--candle); }
.panel__title{
  margin: 0 0 12px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.8rem, 12vw, 4.2rem); letter-spacing: 0.02em; line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  background: linear-gradient(180deg, #fff7e8 10%, #ffd9a0 55%, #e8a24a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 170, 70, 0.35));
}
.panel__text{ margin: 0 0 18px; font-size: 0.8rem; line-height: 1.7; color: var(--dim); }
.panel__text b{ color: var(--ink); font-weight: 600; }
.panel__text .win{ color: var(--glow); font-weight: 700; }
.panel__text .short{ color: var(--candle); }
.panel__text .big{ display: block; font-family: var(--font-display); font-size: 2.4rem; font-weight: 700; color: var(--ink); line-height: 1.1; margin: 2px 0 6px; }
.badge{
  display: inline-block; margin: 0 0 10px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: #2a1a02; background: linear-gradient(180deg, #ffe7a6, #ffb840);
}
.demo{ margin: 0 auto 18px; display: block; width: min(320px, 82vw); height: auto; }
.demo[hidden]{ display: none; }
.play-btn{
  appearance: none; font-family: var(--font-mono); font-weight: 600; font-size: 0.95rem; letter-spacing: 0.04em;
  padding: 13px 32px; border-radius: 999px; cursor: pointer;
  border: 0; background: linear-gradient(180deg, #fff3dc, #ffc977);
  color: #2b1704; box-shadow: 0 10px 30px -8px rgba(255, 170, 70, 0.6);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.play-btn:hover{ transform: translateY(-2px); box-shadow: 0 16px 38px -10px rgba(255, 170, 70, 0.8); }
.play-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(255, 220, 160, 0.6); }
.ghost-btn{
  appearance: none; display: block; margin: 12px auto 0;
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em;
  padding: 9px 18px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255, 181, 74, 0.45); background: rgba(255, 181, 74, 0.1); color: var(--ink);
  transition: background 160ms ease, border-color 160ms ease;
}
.ghost-btn[hidden], .text-btn[hidden]{ display: none; }
.ghost-btn:hover{ background: rgba(255, 181, 74, 0.2); border-color: var(--candle); }
.ghost-btn:focus-visible, .text-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(255, 220, 160, 0.45); }
.text-btn{
  appearance: none; display: block; margin: 12px auto 0; padding: 4px 8px;
  border: 0; background: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.06em;
  color: var(--faint); text-decoration: underline; text-underline-offset: 3px; border-radius: 6px;
}
.text-btn:hover{ color: var(--ink); }
.panel__keys{ margin: 16px 0 0; font-size: 0.64rem; letter-spacing: 0.06em; color: var(--faint); }

/* ---------- Level picker ---------- */
.levels{
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px;
  margin: 14px 0 0; max-height: 40vh; overflow-y: auto; padding: 2px;
  touch-action: pan-y;
}
.levels[hidden]{ display: none; }
.levels__stage{
  grid-column: 1 / -1; margin: 8px 0 0; text-align: left;
  font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint);
}
.lv{
  appearance: none; cursor: pointer; position: relative;
  aspect-ratio: 1; border-radius: 9px;
  font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600;
  color: var(--ink); background: rgba(30, 26, 20, 0.75); border: 1px solid var(--line);
  transition: border-color 120ms ease, transform 120ms ease;
}
.lv:hover{ border-color: var(--candle); }
.lv:active{ transform: scale(0.94); }
.lv:disabled{ opacity: 0.28; cursor: default; }
.lv.is-done{ background: rgba(70, 48, 18, 0.6); }
.lv.is-here{ border-color: var(--glow); }
.lv:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(255, 181, 74, 0.5); }

/* ---------- Frame corners ---------- */
.frame{ position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.frame__corner{ position: fixed; font-size: 0.6rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint); }
.frame__corner--tl{ top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
.frame__corner--tr{ top: max(14px, env(safe-area-inset-top)); right: max(58px, calc(env(safe-area-inset-right) + 58px)); }
.frame__corner--bl{ bottom: max(14px, env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); pointer-events: auto; }
.frame__corner--bl a{ color: var(--faint); text-decoration: none; }
.frame__corner--bl a:hover{ color: var(--candle); }

@media (max-width: 620px){
  .frame__corner--tr, .frame__corner--tl{ display: none; }
  .hud{ gap: 14px; padding: 6px 12px; }
  .hud__cell{ min-width: 44px; }
  .hud__k{ font-size: 7px; letter-spacing: 0.12em; }
  .hud__cell > span:not(.hud__k){ font-size: 16px; }
  /* above the tickets pill, which owns the bottom-left corner */
  .bar{ gap: 5px; bottom: max(62px, calc(env(safe-area-inset-bottom) + 54px)); }
  .bar__btn{ padding: 11px 10px; font-size: 0.66rem; }
  .frame__corner--bl{ display: none; }
  /* the badges move to the top-left on a phone: on the right they sat on
     the top row of bottles */
  .opt-tipjar.opt-tipjar{ top: max(10px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: auto; }
  .opt-fs.opt-fs{ top: max(58px, calc(env(safe-area-inset-top) + 48px)); left: max(10px, env(safe-area-inset-left)); right: auto; }
}
@media (max-width: 400px){
  .bar__btn{ padding: 10px 9px; }
  .bar__btn span{ display: none; }
}
@media (max-height: 520px){
  .hud{
    top: 50%; left: max(12px, env(safe-area-inset-left)); transform: translateY(-50%);
    flex-direction: column; align-items: flex-start; gap: 8px; padding: 9px 12px;
  }
  .hud__cell{ align-items: flex-start; }
  .bar{ left: auto; right: max(12px, env(safe-area-inset-right)); transform: none; flex-direction: column; bottom: 50%; translate: 0 50%; }
  .tip{ top: max(12px, env(safe-area-inset-top)); }
  .frame__corner--tl{ display: none; }
}
@media (prefers-reduced-motion: reduce){
  .play-btn, .sound-btn, .overlay, .tip, .bar__btn{ transition: none; }
}

/* The shared tip-jar / fullscreen badges default to right-CENTER, over the
   shelf. Dock them under the sound button. Doubled classes out-specify the
   components' own injected styles. */
.opt-tipjar.opt-tipjar{ top: max(60px, calc(env(safe-area-inset-top) + 48px)); transform: none; }
.opt-fs.opt-fs{ top: max(112px, calc(env(safe-area-inset-top) + 100px)); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge{ animation: none; }

/* ⚠ These must come AFTER the docking rules above: same specificity, so the
   later rule wins. Landscape phone: the toolbar owns the right edge and the
   HUD the left middle, so the badges sit side by side in the top-left. */
@media (max-height: 520px){
  .opt-tipjar.opt-tipjar{ top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); right: auto; }
  .opt-fs.opt-fs{ top: max(12px, env(safe-area-inset-top)); left: max(62px, calc(env(safe-area-inset-left) + 62px)); right: auto; }
}
