:root {
  color-scheme: dark;
  --night: #181024;
  --frame: #312142;
  --outline: #634779;
  --cream: #fff1d7;
  --muted: #cbb8da;
  --gold: #ffd578;
  --ink: #33213f;
  --green: #c3ef9f;
  --red: #ffb6c0;
  --display: "Bricolage Grotesque", ui-rounded, system-ui, sans-serif;
  --body: "Rethink Sans", system-ui, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --world-height: clamp(420px, calc(100svh - 267px), 648px);
  --shelf-height: 145px;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-width: 320px; min-height: 100svh; color: var(--cream); font: 500 15px/1.4 var(--body);
  background: radial-gradient(ellipse at 50% 3%, #39244c, transparent 65rem), var(--night);
}
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; }
button:disabled, button[aria-disabled="true"] { cursor: not-allowed; }
:where(button, summary):focus-visible, .odd input:focus-visible + span { outline: 3px solid #ead0ff; outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1, h2, .balance output, .roll-number { font-family: var(--display); }
.pixel { display: block; width: 24px; height: 24px; image-rendering: pixelated; flex: none; }
.shell { width: min(100% - 52px, 1280px); margin: auto; padding-bottom: 18px; }
.hud { min-height: 77px; display: grid; grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr); align-items: center; gap: 20px; }
.wordmark { display: flex; align-items: center; gap: 9px; color: var(--gold); }
.wordmark .pixel { width: 35px; height: 35px; }
.wordmark h1 { font-size: 26px; letter-spacing: -.06em; font-weight: 800; line-height: 1; white-space: nowrap; }
.gold-hud { display: flex; align-items: stretch; min-height: 52px; border: 1px solid #66507a; border-radius: 15px; background: #39294c; box-shadow: inset 0 -3px #2c1d3e; }
.gold-hud > div { display: flex; justify-content: center; flex-direction: column; }
.balance { min-width: 130px; padding: 4px 15px 5px; }
.balance > span, .production span { color: #dac8e7; font-size: 11px; line-height: 1.12; font-weight: 750; white-space: nowrap; }
.balance output { color: var(--gold); font-size: 30px; line-height: .98; font-weight: 800; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.balance output[data-long] { font-size: 22px; }
.production { min-width: 89px; padding: 4px 13px; border-left: 1px solid #614b76; }
.production strong { color: #f0deff; font-size: 20px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hud-tools { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.save-state { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.save-state i { width: 7px; height: 7px; border-radius: 50%; background: #c4e6a3; }
.save-state.failed i { background: var(--red); }
.icon-button { display: grid; place-items: center; width: 43px; height: 43px; padding: 0; border: 1px solid #715585; border-radius: 12px; background: #422e56; box-shadow: inset 0 -3px #2b1c3b; }
.icon-button .pixel { width: 22px; height: 22px; }
.icon-button[aria-pressed="true"] { background: #5b4372; }

.game { position: relative; min-width: 0; }
.scene-nav { position: absolute; z-index: 3; top: 19px; right: 21px; display: flex; gap: 5px; padding: 5px; border-radius: 15px; border: 1px solid #b38ec6a0; background: #251631ee; box-shadow: 0 5px 0 #24142f70; }
.scene-nav button { min-height: 40px; display: flex; align-items: center; gap: 6px; padding: 4px 11px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: #efdbf7; font-weight: 800; font-size: 13px; white-space: nowrap; }
.scene-nav button[aria-pressed="true"] { background: #5a3e70; border-color: #b389c3; color: #fff0bf; box-shadow: inset 0 -3px #38254f; }
.scene-nav .pixel { width: 19px; height: 19px; }
.scene { border: 1px solid var(--outline); border-radius: 22px; box-shadow: 0 8px 0 #110a1b, 0 18px 35px #10091b7c; overflow: hidden; background: #3c2652; }
.forge-world, .tavern-world { position: relative; isolation: isolate; overflow: hidden; }
.forge-world { height: var(--world-height); container-type: size; }
.forge-art, .forge-glow { position: absolute; inset: 0; pointer-events: none; }
.forge-art { z-index: -2; background: #3c2652 url("assets/schmiede-hintergrund.avif") 52% 71% / cover no-repeat; }
.forge-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, #21142caa, transparent 27%), radial-gradient(ellipse 53% 53% at 0% 0%, #1b102bd4, transparent 88%); }
.forge-stage {
  position: absolute; inset: 71% auto auto 52%; width: max(100%, 150cqh); aspect-ratio: 3 / 2;
  transform: translate(-52%, -71%); pointer-events: none;
}
.forge-glow {
  opacity: 0; background: radial-gradient(ellipse 25% 24% at 52% 72%, #ffd77883, transparent 100%);
}
.scene-title {
  position: absolute; z-index: 1; top: 22px; left: 26px; pointer-events: none; color: #fff1d8;
  font-size: clamp(35px, 4.4vw, 66px); font-weight: 800; line-height: .89; letter-spacing: -.069em;
  text-shadow: 0 3px #392049, 0 5px 21px #1a0d29;
}
.anvil {
  position: absolute; z-index: 1; top: 8%; left: 21.5%; width: 54.5%; aspect-ratio: 875 / 1014;
  padding: 0; border: 0; background: transparent; pointer-events: auto; touch-action: manipulation;
}
.anvil img { display: block; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.grumm-pose { opacity: 0; }
.anvil:focus-visible { outline: 2px dashed #ffe8a8; outline-offset: -8px; }
.roll-label {
  display: flex; align-items: center; justify-content: center; gap: 9px; width: max-content;
  border: 2px solid #ffedb9; border-radius: 14px; background: var(--gold); color: var(--ink);
  box-shadow: 0 5px #a7653d, 0 9px 20px #24142d; font: 800 clamp(17px, 1.9vw, 24px)/1 var(--display);
  letter-spacing: -.035em; transition: transform 160ms var(--ease-out);
}
.roll-label:active:not(:disabled) { transform: translateY(3px) scale(.97); }

.upgrade-shelf {
  position: relative; z-index: 2; min-height: var(--shelf-height); padding: 2px 12px 8px;
  border-top: 4px solid #b27a62;
  background:
    linear-gradient(180deg, #54364d8c, #332139 82%, #2c1c34),
    repeating-linear-gradient(177deg, #533249 0 7px, #5e3a4c 7px 10px, #57354c 10px 25px);
  box-shadow: inset 0 4px 0 #784e60, inset 0 -4px #2e1b36;
}
.shop-items { max-width: 850px; min-height: 130px; margin: auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); justify-items: stretch; }
.shop-item {
  position: relative; isolation: isolate; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0;
  padding: 1px 2px 3px; color: var(--cream); text-align: center; background: transparent; border: 0; border-radius: 13px;
}
.shop-item::before { content: ""; position: absolute; z-index: -1; inset: 4px 3px 0; border-radius: 13px; opacity: 0; background: radial-gradient(ellipse at 50% 61%, #b07fc346, #9569a61a 62%, transparent); }
.shop-item:focus-visible { outline-offset: -3px; }
.shop-sprite {
  width: 106px; height: 94px; flex: none; display: block; background-image: url("assets/werkstatt-objekte.png");
  background-size: 200% 200%; background-repeat: no-repeat; transition: transform 160ms var(--ease-out);
  filter: drop-shadow(0 5px 3px #2413329c);
}
.shop-sprite[data-item="hammer"] { background-position: 0 0; }
.shop-sprite[data-item="goblin"] { background-position: 100% 0; }
.shop-sprite[data-item="chest"] { background-position: 0 100%; }
.shop-sprite[data-item="fire"] { background-position: 100% 100%; }
.shop-sprite:is([data-item="rune"], [data-item="golem"], [data-item="volcano"], [data-item="starforge"]) {
  background-size: contain;
  background-position: center;
}
.shop-sprite[data-item="rune"] { background-image: url("assets/workshop-rune.png"); }
.shop-sprite[data-item="golem"] { background-image: url("assets/workshop-golem.png"); }
.shop-sprite[data-item="volcano"] { background-image: url("assets/workshop-volcano.png"); }
.shop-sprite[data-item="starforge"] { background-image: url("assets/workshop-starforge.png"); }
.shop-item:active:not([aria-disabled="true"]) .shop-sprite { transform: translateY(2px) scale(.96); }
.shop-item[aria-disabled="true"] .shop-sprite { opacity: .79; }
.shop-name { display: block; color: #ffedd9; font-weight: 800; font-size: 13px; line-height: 1.05; }
.shop-bonus {
  position: absolute; z-index: 2; bottom: calc(100% - 3px); left: 50%; translate: -50% 2px;
  padding: 6px 8px; color: #fff0d1; border: 1px solid #c095ad; border-radius: 8px;
  background: #322140; font-size: 11px; font-weight: 750; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 125ms var(--ease-out), translate 125ms var(--ease-out);
}
.shop-item:focus-visible .shop-bonus { opacity: 1; translate: -50% 0; }
.shop-price strong { display: flex; align-items: center; justify-content: center; gap: 3px; min-height: 19px; margin-top: 3px; padding: 0 7px; border-radius: 6px; color: #ebd0b5; background: #302139; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.shop-item.can-buy .shop-price strong { background: #ffd584; color: #392542; box-shadow: 0 2px #a06549; }
.shop-price .pixel { width: 13px; height: 13px; }
.shop-price small {
  position: absolute; top: 8px; left: calc(50% + 34px); padding: 1px 4px; border-radius: 5px; color: #f3dafb;
  background: #482c5e; border: 1px solid #9b70ae; font-size: 10px; font-weight: 800; line-height: 1.4; white-space: nowrap;
}
.shop-price small:empty { display: none; }

.tavern-world {
  height: calc(var(--world-height) + var(--shelf-height)); min-height: 485px;
  background: #332146 url("assets/wuerfeltaverne.avif") center 58% / cover no-repeat;
}
@media (prefers-reduced-motion: no-preference) {
  .forge-art { background-image: url("assets/schmiedefeuer.gif"), url("assets/schmiede-hintergrund.avif"); }
  .tavern-world { background-image: url("assets/tavernenlicht.gif"), url("assets/wuerfeltaverne.avif"); }
}
.tavern-world::before {
  content: ""; position: absolute; z-index: -1; inset: 0; background:
    radial-gradient(ellipse 72% 55% at 5% 0%, #21132ccc, transparent 79%),
    linear-gradient(270deg, #291638a9, transparent 65%);
}
.tavern .scene-title { font-size: clamp(34px, 4.1vw, 58px); }
.die {
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 3px;
  width: clamp(43px, 5.3vw, 68px); aspect-ratio: 1; padding: 9px; border-radius: 13px;
  background: #ffd28b; border: 2px solid #ffebbd; box-shadow: 3px 6px #a27358, 7px 12px 14px #25132f;
}
.die b { width: 74%; max-width: 9px; aspect-ratio: 1; place-self: center; border-radius: 3px; background: #603659; opacity: 0; }
.die b.on { opacity: 1; }
.risk-field { margin: 0 0 11px; padding: 0; min-width: 0; border: 0; }
.risk-field legend, .stake-label { display: block; color: #f5e7fc; font-weight: 800; font-size: 13px; padding: 0; margin-bottom: 6px; }
.odds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.odd { position: relative; min-width: 0; --risk: #d2f1b8; --risk-bg: #4a4f47; }
.odd-gold { --risk: #ffd698; --risk-bg: #5c4359; }
.odd-red { --risk: #ffc3cd; --risk-bg: #60394d; }
.odd input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.odd input:disabled { cursor: not-allowed; }
.odd span { display: grid; justify-items: center; gap: 4px; padding: 8px 2px 7px; border: 1px solid #805e91; border-radius: 9px; background: #2f1d3d; color: #ead6f0; white-space: nowrap; }
.odd input:checked + span { color: var(--risk); border-color: var(--risk); background: var(--risk-bg); box-shadow: inset 0 -2px #2d1b3c; }
.odd strong { color: var(--risk); font-size: clamp(16px, 1.55vw, 22px); font-weight: 800; line-height: 1; letter-spacing: -.045em; }
.odd small { font-size: 12px; font-weight: 750; line-height: 1; }
.bet-preview.invalid { color: var(--red); }
.stake-controls { display: grid; grid-template-columns: minmax(0, 1fr) 37px 41px; gap: 5px; }
.stake-input { display: flex; gap: 6px; align-items: center; min-width: 0; min-height: 40px; padding: 0 6px; border-radius: 9px; background: #251a34; border: 1px solid #89669a; }
.stake-input:focus-within { outline: 2px solid #ead0ff; }
.stake-input .pixel { width: 19px; height: 19px; }
.stake-input input { min-width: 0; width: 100%; padding: 0; appearance: textfield; outline: none; background: transparent; border: 0; color: #ffe6ab; font-size: 16px; font-weight: 800; }
.stake-input input::-webkit-inner-spin-button, .stake-input input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stake-button { padding: 0; border-radius: 9px; background: #543b65; border: 1px solid #896b9d; color: #f6e2ff; font-weight: 800; font-size: 12px; }
.stake-button:disabled { opacity: .68; }

.logbook { width: max-content; max-width: 100%; margin: 16px 0 0 auto; color: var(--muted); }
.logbook[open] { width: min(100%, 700px); }
.logbook summary {
  width: max-content; margin-left: auto; display: flex; align-items: center; gap: 5px; min-height: 36px; padding: 5px 8px;
  border-radius: 9px; color: #ead7f2; font-size: 13px; font-weight: 750; cursor: pointer; list-style: none;
}
.logbook summary::-webkit-details-marker { display: none; }
.logbook summary::after { content: ""; width: 7px; height: 7px; margin: -4px 2px 0 4px; border: solid #e2c5f1; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.logbook[open] summary::after { margin-top: 3px; transform: rotate(225deg); }
.logbook summary .pixel, .achievement-icon .pixel { width: 18px; height: 18px; }
.logbook-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 12px; border-radius: 13px; border: 1px solid #5f4671; background: #2e1e3f; }
.rank { grid-column: 1 / -1; display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 8px; background: #4a3360; color: #f8e6ff; }
.rank-info { flex: 1; min-width: 0; }
.rank-heading, .section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.rank-heading strong { font-weight: 800; }
.rank-heading span, .rank-info p, .section-heading output { font-size: 11px; color: #ebd7f3; white-space: nowrap; }
.rank-info p { margin-top: 3px; }
.rank progress { display: block; width: 100%; height: 5px; margin-top: 3px; border: 0; border-radius: 3px; background: #2d1b40; }
.rank progress::-webkit-progress-bar { background: #2d1b40; border-radius: 3px; }
.rank progress::-webkit-progress-value { background: #e4b0f9; border-radius: 3px; }
.rank progress::-moz-progress-bar { background: #e4b0f9; border-radius: 3px; }
.logbook-body h2 { color: #f9e5fd; font-size: 15px; line-height: 1.2; font-weight: 800; }
.journal-list { list-style: none; margin: 4px 0 0; padding: 0; }
.journal-list li { display: grid; grid-template-columns: 11px minmax(0, 1fr) auto; gap: 5px; align-items: baseline; padding: 4px 0; font-size: 11px; color: #edd9ee; }
.log-mark, .achievement.unlocked strong { color: var(--gold); }
.journal-list .win .log-mark { color: var(--green); }
.journal-list .loss .log-mark { color: var(--red); }
.journal-list time { color: var(--muted); }
.achievement { display: flex; align-items: center; gap: 5px; padding: 3px 0; font-size: 11px; }
.achievement-icon { filter: grayscale(.8); opacity: .85; }
.achievement.unlocked .achievement-icon { filter: none; opacity: 1; }
.achievement strong { color: #edd9ee; }
.offline-note { grid-column: 1 / -1; font-size: 11px; }

.particles { position: absolute; z-index: 2; inset: 0; pointer-events: none; overflow: hidden; }
.particles .spark, .particles .float-gold { position: absolute; }
.particles .spark { width: 5px; height: 5px; border-radius: 1px; background: #ffd385; box-shadow: 0 0 6px #ffc46890; }
.particles .spark:nth-child(3n) { background: #e3adff; }
.particles .float-gold { color: #fff0ae; font: 800 32px/1 var(--display); white-space: nowrap; letter-spacing: -.04em; text-shadow: 0 2px #432453, 0 4px 12px #201127; }
.toast {
  position: fixed; bottom: 18px; left: 50%; z-index: 7; translate: -50% 0; transform: translateY(14px) scale(.97); opacity: 0; pointer-events: none;
  max-width: calc(100% - 28px); width: max-content; padding: 10px 14px; border: 1px solid #f9d48b; border-radius: 11px;
  background: #39264c; box-shadow: 0 4px #160c24; color: #fff0c6; font-weight: 800;
  transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out);
}
.toast.show { transform: translateY(0) scale(1); opacity: 1; }

@media (hover: hover) and (pointer: fine) {
  .scene-nav button:hover, .icon-button:hover, .stake-button:hover:not(:disabled) { background: #684d7e; }
  .shop-item:hover::before, .shop-item:hover .shop-bonus { opacity: 1; }
  .shop-item:hover .shop-bonus { translate: -50% 0; }
  .shop-item.can-buy:hover .shop-sprite { transform: translateY(-4px) rotate(-3deg); }
  .odd input:hover:not(:disabled) + span { border-color: var(--risk); }
  .logbook summary:hover { background: #402952; }
}
@media (max-width: 920px) {
  .shell { width: calc(100% - 28px); }
  .hud { grid-template-columns: minmax(125px, 1fr) auto minmax(100px, 1fr); gap: 8px; min-height: 68px; }
  .wordmark h1 { font-size: 20px; }
  .wordmark .pixel { width: 28px; height: 28px; }
  .save-state > span { display: none; }
  .scene-nav { top: 12px; right: 12px; }
}
@media (max-width: 620px) {
  .shell { width: calc(100% - 18px); }
  .hud { grid-template-columns: 1fr auto; padding: 7px 0; }
  .hud-tools { grid-column: 2; grid-row: 1; }
  .gold-hud { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .gold-hud > div { flex: 1; min-width: 0; }
  .scene-title { top: 70px; left: 12px; }
  .scene-title br { display: none; }
  .scene-nav { right: auto; left: 10px; }
  .shop-sprite { width: 63px; height: 61px; }
  .shop-name { font-size: 11px; }
  .shop-price small { left: calc(50% + 18px); }
  .tavern-world { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; padding: 120px 10px 15px; height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .roll-label, .shop-sprite, .shop-bonus, .toast { transition: none; }
  .roll-label:active:not(:disabled), .shop-item:active:not([aria-disabled="true"]) .shop-sprite, .shop-item.can-buy:hover .shop-sprite, .toast, .toast.show { transform: none; }
  .particles { display: none; }
}
