:root {
  --card: rgba(255, 248, 235, 0.95);
  --ink: #3b2a1a;
  --soft: #7a6450;
  --wood: #4a2f18;
  --pri: #c2571a;
  --pri-d: #9c4210;
  --ok: #3f9d4c;
  --warn: #d9a514;
  --bad: #cf3d2e;
  --hud: calc(48px + env(safe-area-inset-top));
  --nav: calc(64px + env(safe-area-inset-bottom));
  --sl: env(safe-area-inset-left);
  --sr: env(safe-area-inset-right);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1b0e; overscroll-behavior: none; }
body {
  font: 16px/1.35 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui.no-nav { --nav: env(safe-area-inset-bottom); }
#ui.no-nav #nav { display: none; }
#scene > *, #hud > *, #nav, .backdrop { pointer-events: auto; }
#scene > .label3d, #scene > .hint-bar, #scene > .float, #scene > .ghost, #scene > .target, #scene > .joy,
#scene > .big-msg, #scene > .feedback, #hud > .grow { pointer-events: none; }
button { font: inherit; color: inherit; touch-action: manipulation; }
h2 { margin: 0 0 8px; font-size: 1.25rem; }
h3 { margin: 12px 0 6px; font-size: 1rem; }
p { margin: 0 0 10px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.hint { color: var(--soft); font-size: 0.875rem; }
.emoji { font-size: 1.5rem; line-height: 1; }

/* ---- HUD & Navigation ---- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; height: var(--hud);
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + var(--sr)) 6px calc(8px + var(--sl));
  display: flex; gap: 6px; align-items: center;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 0; border-radius: 18px;
  background: var(--card); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); font-weight: 700; white-space: nowrap;
}
.pill.warn { background: #ffe9a8; color: #6b4a00; animation: pulse 1.2s infinite; overflow: hidden; text-overflow: ellipsis; }
.pill .val { font-variant-numeric: tabular-nums; }
#nav {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--nav);
  padding: 0 var(--sr) env(safe-area-inset-bottom) var(--sl);
  display: flex; background: var(--wood); box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.35);
}
.navbtn {
  flex: 1; border: 0; background: none; color: #f3e4cf; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 0.75rem; font-weight: 700; opacity: 0.75;
}
.navbtn.on { opacity: 1; background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 3px 0 #f0b060; }

/* ---- Bausteine ---- */
.card { background: var(--card); border-radius: 16px; padding: 10px 12px; box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3); }
.btn {
  min-height: 44px; padding: 8px 14px; border: 0; border-radius: 14px; background: #fff; color: var(--ink);
  font-weight: 700; box-shadow: 0 2px 0 #cbb89e, 0 3px 8px rgba(0, 0, 0, 0.2); cursor: pointer;
}
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 #cbb89e; }
.btn.primary { background: var(--pri); color: #fff; box-shadow: 0 2px 0 var(--pri-d), 0 3px 8px rgba(0, 0, 0, 0.25); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 0.875rem; }
.btn.icon { min-width: 44px; padding: 8px; }
.btn.big { min-height: 64px; min-width: 150px; font-size: 1.2rem; }
.btn.wide { width: 100%; }
.btn.off { opacity: 0.55; }
.title { font-weight: 800; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.sub { color: var(--soft); font-size: 0.8rem; }
.bar { display: grid; grid-template-columns: 96px 1fr 62px; align-items: center; gap: 8px; margin-top: 6px; font-size: 0.8rem; font-weight: 700; }
.bar-track { height: 12px; border-radius: 6px; background: #e3d5c0; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 6px; background: var(--ok); transition: width 0.25s; }
.bar-fill.happy { background: #e0629a; }
.bar-fill.low { background: var(--bad); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }

.top-left { position: absolute; top: calc(var(--hud) + 4px); left: calc(8px + var(--sl)); }
.stable-head, .tame-head { position: absolute; left: 50%; transform: translateX(-50%); width: min(94vw, 400px); }
.stable-head { top: calc(var(--hud) + 4px); text-align: center; }
.stable-head .btn.small { margin-top: 8px; }
.tame-head { top: calc(var(--hud) + 54px); }
.center-msg { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); width: min(90vw, 380px); text-align: center; }
.actions {
  position: absolute; left: var(--sl); right: var(--sr); bottom: calc(var(--nav) + 100px); padding: 0 8px;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
#ui.no-nav .actions { bottom: calc(var(--nav) + 64px); }
.seg { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.hint-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav) + 10px); width: max-content; max-width: 94vw;
  padding: 6px 12px; border-radius: 12px; background: rgba(40, 26, 14, 0.72); color: #fff; font-size: 0.85rem; text-align: center;
}

/* ---- Fütterung ---- */
.tray { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav) + 8px); display: flex; gap: 10px; }
.tray-item {
  width: 86px; height: 84px; border-radius: 16px; background: var(--card); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; cursor: grab;
}
.tray-item .emoji { font-size: 2rem; }
.tray-item .count { font-weight: 800; font-variant-numeric: tabular-nums; }
.tray-item .cap { font-size: 0.7rem; color: var(--soft); }
.ghost { position: fixed; font-size: 3rem; transform: translate(-50%, -60%); filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4)); z-index: 5; }
.target {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 4px dashed #fff; background: rgba(255, 220, 90, 0.3); animation: pulse 0.9s infinite;
}

/* ---- 3D-Beschriftungen & Effekte ---- */
.label3d { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; font-weight: 800; }
.label3d.mark { padding: 4px 10px; border-radius: 12px; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); animation: pulse 0.9s infinite; }
.label3d.letter { width: 30px; height: 30px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35); }
.label3d.letter.on { background: #ffd23f; outline: 3px solid #fff; }
.joy { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); border: 2px solid rgba(255, 255, 255, 0.7); }
.joy-knob { position: absolute; left: 32px; top: 32px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, 0.9); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
.float { position: absolute; font-size: 1.8rem; transform: translate(-50%, -50%); animation: rise 0.9s ease-out forwards; }
.big-msg { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: 5rem; font-weight: 900; color: #fff; text-shadow: 0 4px 0 var(--pri-d), 0 6px 16px rgba(0, 0, 0, 0.5); }
.feedback { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 2.2rem; font-weight: 900; color: #fff; opacity: 0; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45); }
.feedback.show { opacity: 1; animation: pop 0.8s ease-out; }
.feedback.good { color: #b8ff9a; }
.feedback.ok { color: #ffe27a; }
.feedback.bad { color: #ffb0a6; }
.balance { position: relative; height: 26px; margin: 8px 0 2px; border-radius: 13px; background: linear-gradient(90deg, var(--bad), #f2d7a0 30%, #f2d7a0 70%, var(--bad)); }
.bal-zone { position: absolute; left: 30%; width: 40%; top: 0; bottom: 0; background: rgba(63, 157, 76, 0.55); border-radius: 6px; }
.bal-marker { position: absolute; top: -5px; width: 14px; height: 36px; margin-left: -7px; border-radius: 7px; background: var(--wood); border: 2px solid #fff; }

/* ---- Toasts & Dialoge ---- */
#toasts { position: absolute; left: 0; right: 0; top: calc(var(--hud) + 110px); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 30; }
.toast { max-width: 90vw; padding: 8px 14px; border-radius: 14px; background: rgba(40, 26, 14, 0.92); color: #fff; font-weight: 700; text-align: center; animation: pop 0.25s ease-out; transition: opacity 0.3s; }
.toast.out { opacity: 0; }
#modals { position: absolute; inset: 0; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: rgba(30, 18, 8, 0.55); display: grid; place-items: center; padding: 12px; }
.modal {
  position: relative; width: min(100%, 420px); max-height: calc(100% - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex; flex-direction: column; background: #fff8eb; border-radius: 20px; padding: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  -webkit-user-select: text; user-select: text;
}
.modal.wide { width: min(100%, 640px); }
.modal h2 { padding-right: 40px; }
.modal-body { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.modal-btns .btn { flex: 1 1 auto; }
.modal .x { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eadbc5; font-weight: 800; }
.input { flex: 1; min-width: 0; height: 48px; padding: 0 14px; border: 2px solid #cbb89e; border-radius: 14px; background: #fff; font: inherit; font-weight: 700; color: var(--ink); -webkit-user-select: text; user-select: text; }
.input:focus { outline: 3px solid #f0b060; border-color: var(--pri); }
.legal-link { color: var(--pri-d); font-weight: 700; font-size: 0.875rem; }
.status { margin-top: 4px; font-size: 0.8rem; font-weight: 700; color: var(--pri-d); white-space: pre-line; }
.pill.day { flex-direction: column; gap: 2px; justify-content: center; font-size: 0.8rem; padding: 0 10px; }
.daybar { width: 100%; height: 4px; border-radius: 2px; background: #e3d5c0; overflow: hidden; }
.dayfill { display: block; height: 100%; background: var(--pri); }
.menu-row { margin-bottom: 8px; }
.menu-row .hint { margin: 2px 4px 0; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.day { flex: 1; min-width: 40px; min-height: 44px; border: 2px solid #dccab0; border-radius: 12px; background: #fff; font-weight: 800; }
button.day.on { border-color: var(--pri); background: var(--pri); color: #fff; }
button.day.today { outline: 3px solid #f0b060; outline-offset: 1px; }
.gaits { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 6px; border-radius: 16px; background: rgba(255, 248, 235, 0.85); }
.headshot { width: 60px; height: 60px; border-radius: 10px; background: #f6e3c3; display: block; }
.headshot.empty { background: none; }
.sheet { width: 100%; border-collapse: collapse; }
.sheet th { text-align: left; color: var(--soft); font-weight: 700; padding: 5px 10px 5px 0; white-space: nowrap; vertical-align: top; }
.sheet td { padding: 5px 0; font-weight: 700; }
.sheet tr + tr { border-top: 1px solid #eadbc5; }
.sheet.rank td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet.rank .me td, .sheet.rank .me th { color: var(--pri-d); font-size: 1.05rem; }
.prize { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px; border-radius: 14px; background: #ffeec2; }
.cupline { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 12px; border: 2px solid #dccab0; border-radius: 20px; background: #fff; font-weight: 700; }
.chip.on { border-color: var(--pri); background: #ffe9d6; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.25); flex: none; }
.swatch.big { width: 34px; height: 34px; }
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.boxcell { position: relative; min-height: 96px; padding: 4px; border: 2px solid #c9a779; border-radius: 10px; background: #f6e3c3; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; }
.boxcell .no { font-size: 0.7rem; color: var(--soft); }
.boxcell .nm { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.boxcell.free { background: #efe6d8; border-style: dashed; opacity: 0.6; }
.boxcell.hungry { border-color: var(--bad); background: #ffe1d6; }
.boxcell .flag { position: absolute; top: -6px; right: -4px; font-size: 0.8rem; }
.pager { justify-content: center; margin-top: 10px; font-weight: 700; }

/* ---- Shop ---- */
.shop-panel { position: absolute; left: calc(8px + var(--sl)); right: calc(8px + var(--sr)); bottom: calc(var(--nav) + 8px); max-height: 44%; display: flex; flex-direction: column; gap: 8px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: none; padding-bottom: 2px; scrollbar-width: none; }
.btn.tab { min-height: 38px; padding: 4px 12px; white-space: nowrap; font-size: 0.875rem; box-shadow: none; background: #eadbc5; }
.btn.tab.on { background: var(--wood); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; padding: 2px; }
.item { min-height: 92px; padding: 8px 6px; border: 2px solid #dccab0; border-radius: 14px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; }
.item.on { border-color: var(--pri); background: #ffe9d6; }
.item:disabled { opacity: 0.5; }
.item .nm { font-weight: 700; font-size: 0.85rem; }
.item .price { font-size: 0.75rem; color: var(--soft); }

/* ---- Schleifentafel ---- */
.wall {
  position: absolute; top: var(--hud); bottom: var(--nav); left: 0; right: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px calc(14px + var(--sr)) 20px calc(14px + var(--sl)); color: #fff3df;
  background: repeating-linear-gradient(90deg, #6b4526 0 78px, #5f3c20 78px 80px, #744b29 80px 158px, #5f3c20 158px 160px);
}
.wall h2 { font-size: 1.4rem; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.wall-sub { font-weight: 700; opacity: 0.9; }
.shelf { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; min-height: 84px; padding: 10px 12px 8px; margin: 8px 0 16px; border-bottom: 10px solid #3a2311; background: rgba(0, 0, 0, 0.18); border-radius: 8px 8px 0 0; }
.cupbox { display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; font-weight: 700; }
.empty { opacity: 0.85; font-weight: 700; }
.ribbons { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 14px 8px; }
.rib { display: flex; flex-direction: column; align-items: center; text-align: center; }
.rib .nm { max-width: 100%; font-weight: 800; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rib .sub { color: #f1dcc0; font-size: 0.7rem; }
.ribbon, .cup { filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4)); }
.wall .pager { margin-top: 16px; }

#fatal, .noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: #2a1b0e; color: #fff3df; text-align: center; font-size: 1.1rem; z-index: 99; }

#fatal a, .noscript a { color: #f0b060; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.label3d.mark { animation: none; }
@keyframes rise { to { transform: translate(-50%, -160%); opacity: 0; } }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Querformat auf dem Handy: Bedienelemente an die Ränder, damit das Pferd sichtbar bleibt. */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --nav: calc(50px + env(safe-area-inset-bottom)); }
  .navbtn { flex-direction: row; gap: 6px; }
  .stable-head { left: calc(8px + var(--sl)); transform: none; width: 270px; }
  .tame-head { top: calc(var(--hud) + 4px); width: min(52vw, 400px); }
  .actions { left: auto; right: calc(8px + var(--sr)); top: calc(var(--hud) + 4px); bottom: auto; width: 290px; padding: 0; justify-content: flex-end; }
  #ui.no-nav .actions { top: auto; bottom: calc(var(--nav) + 10px); width: auto; max-width: 60vw; }
  .tray-item { width: 76px; height: 64px; }
  .tray-item .emoji { font-size: 1.4rem; }
  .shop-panel { left: auto; top: calc(var(--hud) + 4px); width: 48vw; max-height: none; }
  .hint-bar { left: calc(8px + var(--sl)); transform: none; max-width: 46vw; text-align: left; }
  #toasts { top: calc(var(--hud) + 60px); }
  .big-msg { top: 26%; }
}
@media (prefers-reduced-motion: reduce) {
  .pill.warn, .target { animation: none; }
}
