:root {
  --bg: #f8f9f3;
  --ink: #000000;
  --green: #00bf63;
  --tan: #c29f85;
  --tag-lime: #a8d932;
  --tag-gold: #ebc633;
  --navy: #083051;
  --teal: #52b0b7;

  --panel: #fbf9f5;
  --shadow-color: #000;
  --line: 3px solid var(--ink);
  --shadow: 4px 4px 0 var(--shadow-color);
  --shadow-sm: 3px 3px 0 var(--shadow-color);
  --muted: rgba(0, 0, 0, .55);
  --field: #fff;
  --field-inset: #e9e9e1;
  --pip-empty: #dcdcd4;
  --disabled-bg: #dcdcd4;
  --disabled-fg: rgba(0, 0, 0, .45);
  --brand-font: "Pixelify Sans", var(--vt);

  --page: var(--bg);
  color-scheme: light;
}

.scene {
  --ink: #2b1d1a;
  --teal: #2a9d8f;
  --teal-d: #1c6e65;
  --gold: #f2c14b;
  --red: #e0453c;
  --red-d: #9c2018;
  --paper: #fbf3e4;
}

body {
  background-color: var(--bg);
  background-image: none;
  color: var(--ink);
}

.brand-row { display: flex; align-items: center; gap: 8px; }
.brand-icon {
  width: 35px; height: 35px; flex: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.logo {
  font-family: var(--brand-font);
  font-weight: 400;
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0;
  color: var(--ink);
  text-shadow: none;
}
.logo span { color: var(--green); }
.tagline {
  margin: 4px 0 0;
  font-family: var(--brand-font);
  font-size: 14px;
  color: var(--ink);
  opacity: .8;
}
@media (min-width: 520px) {
  .brand-icon { width: 70px; height: 70px; }
  .brand-row { gap: 12px; }
  .logo { font-size: 48px; }
  .tagline { font-size: 18px; margin-left: 82px; margin-top: -10px; }
}

.icon-btn {
  background: var(--field);
  color: var(--ink);
  border: var(--line);
  box-shadow: var(--shadow-sm);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 1px 1px 0 var(--shadow-color); }
.theme-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.icon-btn.theme-btn[aria-pressed] { opacity: 1; text-decoration: none; }
.theme-btn svg { display: block; }
:root[data-theme="dark"] .theme-btn .icon-moon,
:root:not([data-theme="dark"]) .theme-btn .icon-sun { display: none; }
.icon-btn:focus-visible, .btn:focus-visible { outline-color: var(--green); }

.statusbar { color: var(--ink); }
.status-score { color: var(--ink); }
.status-score small { color: var(--muted); }
.pips li { background: var(--pip-empty); border: 2px solid var(--ink); }
.pips li.t-green, .pips li.t-yellow, .pips li.t-orange, .pips li.t-red { background: var(--green); }
.pips li.current { background: var(--pip-empty); animation: rbPip 1s steps(2) infinite; }
@keyframes rbPip { 50% { background: var(--tag-lime); } }

.scene-wrap { border: var(--line); box-shadow: var(--shadow); }

.bubble, .panel {
  background: var(--panel);
  color: var(--ink);
  border: var(--line);
  box-shadow: var(--shadow);
}
.bubble::before { border-bottom-color: var(--ink); }
.bubble::after { border-bottom-color: var(--panel); }
@media (min-width: 900px) {
  .bubble::before { top: 22px; left: -15px; border: 10px solid transparent; border-left: 0; border-right: 12px solid var(--ink); }
  .bubble::after { top: 25px; left: -9px; border: 7px solid transparent; border-left: 0; border-right: 9px solid var(--panel); }
}
.bubble-name { background: var(--green); color: #000; }

.item-count {
  display: inline-block;
  background: var(--green);
  color: #000;
  padding: 4px 6px 3px;
}
.item-cat { color: var(--muted); }
.item-name { color: var(--ink); }
.guess-field { background: var(--field); border-color: var(--ink); box-shadow: inset 3px 3px 0 var(--field-inset); }
.guess-field:focus-within { border-color: var(--ink); box-shadow: inset 3px 3px 0 var(--field-inset), 0 0 0 3px var(--green); }
.guess-field input { color: var(--ink); }
.guess-field input::placeholder { color: #b8b8ae; }
.peso-prefix { color: var(--muted); }
.error { color: #b3261e; }

.btn, .btn-pay, .btn-share {
  background: var(--green);
  color: #000;
  border: 3px solid #000;
  box-shadow: var(--shadow-sm);
  opacity: 1;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 1px 1px 0 var(--shadow-color); }
.btn:disabled { opacity: 1; background: var(--disabled-bg); color: var(--disabled-fg); box-shadow: none; }

.result { border-top-color: var(--tan); }
.result-pts.t-green { color: #00994f; }

.panel.done {
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--tan);
  box-shadow: 4px 4px 0 var(--tan);
}
.receipt-slot { background: #000; border-color: #000; }
.receipt {
  --ink: #000;
  background: #fbf9f5;
  color: #000;
  box-shadow: 0 0 0 2px var(--tan);
}
.receipt::after {
  background:
    linear-gradient(135deg, #fbf9f5 5px, transparent 0) 0 0 / 10px 10px repeat-x,
    linear-gradient(-135deg, #fbf9f5 5px, transparent 0) 0 0 / 10px 10px repeat-x;
}
.receipt > .rl:first-child span {
  background: linear-gradient(90deg, var(--ink) 0 5ch, var(--green) 5ch 9ch, var(--ink) 9ch);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0;
}
.receipt .barcode { position: relative; margin-bottom: 54px; }
.receipt .barcode::before, .receipt .barcode::after {
  position: absolute; left: 50%;
  transform: translateX(-50%);
  font-family: var(--brand-font);
  font-size: 22px;
  line-height: 1;
}
.receipt .barcode::before { content: 'MG'; top: calc(100% + 8px); color: var(--ink); }
.receipt .barcode::after { content: 'KN'; top: calc(100% + 28px); color: var(--green); }

.share-note { color: var(--ink); }
.share-fallback { border-color: var(--ink); background: var(--field); color: var(--ink); }
.countdown { border: var(--line); box-shadow: var(--shadow-sm); }

.footer {
  border-top: 3px solid var(--tan);
  padding-top: 12px;
  color: var(--ink);
}
.footer p { opacity: .72; }
.footer #priceNotice { color: var(--ink); opacity: 1; }
.footer .fine { color: var(--ink); opacity: .62; }

.help {
  background: var(--panel);
  color: var(--ink);
  border: var(--line);
  box-shadow: 6px 6px 0 var(--shadow-color);
}
.help::backdrop { background: rgba(248, 249, 243, .75); }
:root[data-theme="dark"] .help::backdrop { background: rgba(14, 16, 15, .8); }
.help h2 { color: var(--ink); }
.help h2::after { content: ''; display: block; width: 40px; height: 4px; margin-top: 6px; background: var(--green); }
.score-table th, .score-table td { border-bottom-color: var(--tan); }

@media (max-width: 600px) {
  body.typing .layout { background-color: var(--bg); }
}

:root[data-theme="dark"] {
  --bg: #0e100f;
  --panel: #1a1d1b;
  --ink: #f8f9f3;
  --green: #00bf63;
  --tan: #c29f85;
  --shadow-color: #00733b;
  --muted: rgba(248, 249, 243, .6);
  --field: #0e100f;
  --field-inset: #000;
  --pip-empty: #3a3f3c;
  --disabled-bg: #2e332f;
  --disabled-fg: rgba(248, 249, 243, .45);
  color-scheme: dark;
}
:root[data-theme="dark"] .error { color: #ff7a70; }
:root[data-theme="dark"] .result-pts.t-green { color: #2fe08a; }
:root[data-theme="dark"] .result-pts.t-yellow { color: var(--tag-gold); }
:root[data-theme="dark"] .result-pts.t-orange { color: #f39a4a; }
:root[data-theme="dark"] .result-pts.t-red { color: #ff7a70; }

:root[data-theme="dark"] .brand-icon {
  filter: drop-shadow(1px 0 0 #f8f9f3) drop-shadow(-1px 0 0 #f8f9f3) drop-shadow(0 1px 0 #f8f9f3) drop-shadow(0 -1px 0 #f8f9f3);
}
@media (min-width: 520px) {
  :root[data-theme="dark"] .brand-icon {
    filter: drop-shadow(2px 0 0 #f8f9f3) drop-shadow(-2px 0 0 #f8f9f3) drop-shadow(0 2px 0 #f8f9f3) drop-shadow(0 -2px 0 #f8f9f3);
  }
}

@media (max-width: 519px) {
  .topbar { gap: 8px; }
  .top-actions { gap: 6px; }
  .icon-btn { width: 34px; height: 34px; font-size: 12px; }
  .logo { font-size: 28px; }
  .tagline { font-size: 12px; white-space: nowrap; }
}

:root { --paper-tile: url("assets/paper/paper-light.webp"); }
:root[data-theme="dark"] { --paper-tile: url("assets/paper/paper-dark.webp"); }
:root[data-bg="paper-pixel"] { --paper-tile: url("assets/paper/paper-pixel-light.png"); }
:root[data-bg="paper-pixel"][data-theme="dark"] { --paper-tile: url("assets/paper/paper-pixel-dark.png"); }

body {
  background-color: var(--bg);
  background-image: var(--paper-tile);
  background-repeat: repeat;
  background-size: 512px 512px;
  background-position: 0 0;
  background-attachment: scroll;
}
@media (min-width: 900px) and (hover: hover) {
  body { background-attachment: fixed; }
}
:root[data-bg="paper-pixel"] body { image-rendering: pixelated; }
:root[data-bg="paper-pixel"] body > * { image-rendering: auto; }

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 120% 100% at 50% 40%, transparent 60%, rgba(60, 45, 30, .07) 100%);
}
:root[data-theme="dark"] body::before {
  background: radial-gradient(ellipse 120% 100% at 50% 40%, transparent 55%, rgba(0, 0, 0, .45) 100%);
}

.howto { display: none; }
@media (min-width: 900px) {
  .layout {
    display: grid;
    grid-template-columns: auto 380px;
    grid-template-areas: "scene side" "howto side";
    grid-template-rows: auto 1fr;
    justify-content: center;
    align-items: start;
    column-gap: 24px;
    row-gap: 18px;
  }
  .scene-wrap { grid-area: scene; }
  .side { grid-area: side; width: 380px; max-width: 380px; }
  .howto {
    grid-area: howto;
    align-self: start;
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 18px;
    width: 0; min-width: 100%;
    padding: 14px 16px 16px;
    background: var(--panel);
    color: var(--ink);
    border: var(--line);
    box-shadow: var(--shadow);
  }
  .howto-title {
    margin: 0 0 10px;
    font-family: var(--pixel);
    font-size: 11px;
    line-height: 1.4;
  }
  .howto-title::after { content: ''; display: block; width: 32px; height: 4px; margin-top: 6px; background: var(--green); }
  .howto-steps { margin: 0; padding-left: 22px; font-size: 19px; line-height: 1.15; }
  .howto-steps li { margin-bottom: 6px; }
  .howto-steps li::marker { font-family: var(--pixel); font-size: 10px; color: var(--green); }
  .howto-score { width: 100%; border-collapse: collapse; font-size: 19px; }
  .howto-score th { text-align: left; font-weight: normal; padding: 2px 0; border-bottom: 2px dashed var(--tan); }
  .howto-score td {
    text-align: right; padding: 2px 0; border-bottom: 2px dashed var(--tan);
    font-family: var(--pixel); font-size: 11px; color: var(--ink);
  }
  .howto-score tr:first-child td { color: var(--green); }
}

.mode-tab {
  background: var(--panel);
  color: var(--ink);
  border: var(--line);
  box-shadow: var(--shadow-sm);
}
.mode-tab:active { transform: translateY(2px); box-shadow: 1px 1px 0 var(--shadow-color); }
.mode-tab[aria-selected="true"] { background: var(--green); color: #000; }
.mode-tab:focus-visible { outline-color: var(--green); }
.mode-tab.dev-reset { background: #e0453c; color: #fff; }

.budget { color: var(--ink); }
.budget.low { color: #e0453c; }
:root[data-theme="dark"] .budget.low { color: #ff7a70; }

body[data-mode="classic"] .pips li.t-yellow { background: var(--tag-gold); }
body[data-mode="classic"] .pips li.t-red { background: #e0453c; }

.g-row { border: 2px solid var(--ink); }
.g-row.empty { border-color: var(--muted); }
.g-row.g-win { background: var(--green); color: #000; border-color: #000; }
.g-row.g-close { background: var(--tag-gold); color: #000; border-color: #000; }
.g-row.g-far { background: #e0453c; color: #fff; border-color: #000; }

.btn-again { background: var(--green); }
.dist-bar { background: var(--ink); color: var(--panel); }
.dist-bar.today { background: var(--green); color: #000; }
.stats-body h3::after, .mode-help h3::after { content: ''; display: block; width: 28px; height: 3px; margin-top: 4px; background: var(--green); }
.mh-g { color: #00994f; } .mh-y { color: #a07d00; } .mh-r { color: #b3261e; }
:root[data-theme="dark"] .mh-g { color: #2fe08a; }
:root[data-theme="dark"] .mh-y { color: var(--tag-gold); }
:root[data-theme="dark"] .mh-r { color: #ff7a70; }

@media (max-width: 519px) {
  .top-actions { gap: 5px; }
  .icon-btn { width: 30px; height: 30px; font-size: 11px; }
  .icon-btn svg { width: 14px; height: 14px; }
  .logo { font-size: 26px; }
}

.modal-title { color: var(--ink); }
.modal-close { color: var(--ink); }
.panel.done .done-actions { background: var(--panel); }
.icon-btn.modal-close { width: 44px; height: 44px; }
