:root {
  --bg: #1b2433;
  --panel: rgba(20, 26, 38, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f4f8;
  --muted: #aab4c4;
  --accent: #ffd34d;
  --danger: #ff4d4d;
  --ok: #4dff9a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: none; overscroll-behavior: none;
}
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 18px; min-height: 44px; cursor: pointer; touch-action: manipulation;
}
button:hover { background: rgba(255, 255, 255, 0.18); }
button.primary { background: var(--accent); color: #1b1b1b; border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button:focus-visible { outline: 3px solid #7fd8ff; outline-offset: 2px; }
kbd { background: #333b4a; border-radius: 5px; padding: 1px 6px; border: 1px solid #555f72; font-size: 0.9em; }

/* ---------- Bildschirme */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10, 14, 22, 0.55); backdrop-filter: blur(3px); z-index: 20; overflow-y: auto;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  width: min(560px, 100%); max-height: calc(100% - 8px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
.panel h1 { font-size: 56px; margin: 0; letter-spacing: 0.04em; color: var(--accent); }
.panel h2 { margin: 0 0 12px; }
.panel h3 { margin: 14px 0 6px; font-size: 16px; color: var(--accent); }
.tagline { color: var(--muted); margin-top: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.small { font-size: 13px; color: var(--muted); }
.panel.help { width: min(900px, 100%); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; font-size: 14px; line-height: 1.45; }
@media (max-width: 720px) { .help-grid { grid-template-columns: 1fr; } }
.help ul, .help ol { padding-left: 18px; margin: 4px 0; }
.rails-legend, .joker-legend { list-style: none; padding: 0 !important; }
.rails-legend li, .joker-legend li { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0; }
.swatch { flex: 0 0 38px; height: 18px; border-radius: 4px; margin-top: 2px; }
.swatch.groove { background: linear-gradient(#29c6ff 0 18%, #07090c 18% 82%, #29c6ff 82%); }
.swatch.pattern { background: repeating-linear-gradient(45deg, #5b2a8c 0 5px, #8e4fd6 5px 10px); }
.swatch.curb { background: repeating-linear-gradient(60deg, #ff8a1f 0 6px, #f4f1ea 6px 12px); }
.jicon { flex: 0 0 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 20px; color: #111; font-weight: 800; }

.map-list { display: grid; gap: 10px; margin-top: 16px; }
.map-card { text-align: left; display: block; width: 100%; border-radius: 14px; padding: 14px; }
.map-card.selected { border-color: var(--accent); background: rgba(255, 211, 77, 0.12); }
.map-card b { font-size: 18px; }
.map-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

.settings label { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 14px; }
.settings label.check { flex-direction: row; align-items: center; }
.settings select, .settings input[type='range'] { font: inherit; padding: 8px; border-radius: 10px; background: #2a3344; color: var(--text); border: 1px solid var(--line); min-height: 40px; }
.settings input[type='checkbox'] { width: 22px; height: 22px; }

.result .tip { background: rgba(255, 211, 77, 0.12); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; }
.result.lost h2 { color: var(--danger); }
.result.won h2 { color: var(--ok); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.stats div { background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 8px; font-size: 13px; color: var(--muted); }
.stats b { display: block; color: var(--text); font-size: 18px; }

/* ---------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .pad, #hud .slot { pointer-events: auto; }
.hud-top {
  position: absolute; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; display: flex; gap: 10px; align-items: center;
}
.icon-btn { width: 48px; height: 48px; padding: 0; border-radius: 14px; background: var(--panel); font-size: 16px; }
.progress { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 14px; padding: 0 12px; height: 48px; }
.progress-bar { flex: 1; height: 10px; background: rgba(255, 255, 255, 0.12); border-radius: 6px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #4dff9a, #ffd34d); transition: width 0.2s; }
#progress-text { font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; font-weight: 700; }
.timer { background: var(--panel); border-radius: 14px; height: 48px; padding: 0 14px; display: grid; place-items: center; font-variant-numeric: tabular-nums; font-weight: 700; }

.hint {
  position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(620px, calc(100% - 16px));
  background: rgba(20, 26, 38, 0.88); border: 1px solid rgba(255, 211, 77, 0.5); border-radius: 14px; padding: 10px 14px;
  font-size: 15px; line-height: 1.35; text-align: center; animation: pop 0.25s ease-out;
}
.toast {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); background: rgba(20, 26, 38, 0.9);
  border-radius: 12px; padding: 10px 16px; font-weight: 600; text-align: center; max-width: calc(100% - 32px);
  animation: pop 0.2s ease-out;
}
.toast.good { border: 1px solid var(--ok); }
.toast.bad { border: 1px solid var(--danger); }
.toast.info { border: 1px solid #7fd8ff; }
@keyframes pop { from { transform: translate(-50%, -40%) scale(0.95); opacity: 0; } }
.hint { animation-name: hintpop; }
@keyframes hintpop { from { transform: translate(-50%, -6px); opacity: 0; } }

.capture {
  position: absolute; top: 24%; left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 24px));
  background: rgba(120, 10, 10, 0.88); border: 2px solid var(--danger); border-radius: 16px; padding: 12px 16px; text-align: center;
  animation: shake 0.35s;
}
.capture-title { font-size: 22px; font-weight: 800; }
.capture-sub { margin: 4px 0 8px; }
.capture-bar { height: 12px; background: rgba(0, 0, 0, 0.4); border-radius: 6px; overflow: hidden; }
#capture-fill { height: 100%; background: #ffd34d; width: 100%; }
@keyframes shake { 20% { transform: translateX(calc(-50% - 8px)); } 40% { transform: translateX(calc(-50% + 8px)); } 60% { transform: translateX(calc(-50% - 4px)); } }

.manhole-prompt {
  position: absolute; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%); background: rgba(255, 211, 77, 0.95);
  color: #1b1b1b; font-weight: 700; padding: 8px 14px; border-radius: 999px; white-space: nowrap; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis;
}
.manhole-prompt.dim { background: rgba(160, 170, 185, 0.92); }

.hud-bottom {
  position: absolute; left: 8px; right: 8px; bottom: calc(10px + var(--safe-b)); display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
}
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin-left: auto; }
.inventory { display: flex; gap: 8px; }
.slot {
  position: relative; width: 78px; height: 86px; border-radius: 16px; background: var(--panel); border: 2px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; cursor: pointer; color: var(--text);
}
.slot .key { position: absolute; top: 4px; left: 7px; font-size: 12px; color: var(--muted); font-weight: 700; }
.slot .ic { font-size: 28px; line-height: 1; }
.slot .nm { font-size: 11px; margin-top: 4px; font-weight: 700; text-align: center; }
.slot .lv { font-size: 11px; color: var(--accent); letter-spacing: 1px; }
.slot .ch { position: absolute; top: 4px; right: 7px; font-size: 12px; font-weight: 800; }
.slot.empty { opacity: 0.55; }
.slot.empty .ic { font-size: 18px; color: var(--muted); }
.slot.waiting { border-style: dashed; border-color: var(--accent); }
.slot.waiting .ic { color: var(--accent); animation: pulse 1s infinite; }
.slot.match { animation: matchpulse 0.5s infinite alternate; border-color: #fff; }
.slot.nomatch { opacity: 0.35; }
.slot.new { animation: newpop 0.6s ease-out; }
@keyframes pulse { 50% { opacity: 0.4; } }
@keyframes matchpulse { to { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.55), 0 0 24px rgba(255, 211, 77, 0.9); transform: translateY(-4px); } }
@keyframes newpop { 0% { transform: scale(1.35); box-shadow: 0 0 30px rgba(255, 211, 77, 1); } }

.pending {
  display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px dashed var(--accent); border-radius: 14px; padding: 8px 12px;
  width: min(270px, calc(100vw - 16px));
}
.pending-ring {
  --p: 1; flex: 0 0 52px; height: 52px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), rgba(255, 255, 255, 0.12) 0);
  display: grid; place-items: center; position: relative;
}
.pending-ring::after { content: ''; position: absolute; inset: 6px; border-radius: 50%; background: #1b2433; }
.pending-ring span { position: relative; z-index: 1; font-weight: 800; font-variant-numeric: tabular-nums; }
.pending-title { font-size: 14px; }
.pending-title b { color: var(--accent); }
.pending-sub { font-size: 12px; color: var(--muted); }
.pending-odds { font-size: 11px; color: var(--muted); margin-top: 2px; }

.action-btn { background: var(--accent); color: #1b1b1b; font-weight: 800; border: none; }

.pad {
  width: 150px; height: 150px; border-radius: 50%; background: rgba(20, 26, 38, 0.55); border: 2px solid rgba(255, 255, 255, 0.25);
  position: relative; touch-action: none; flex: 0 0 auto;
}
.pad::before { content: '▲\A◀　　▶\A▼'; white-space: pre; position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: rgba(255, 255, 255, 0.35); font-size: 16px; line-height: 2.6; }
.pad .knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); border: 2px solid rgba(255, 255, 255, 0.7); }
.pad.active { border-color: var(--accent); }

@media (max-width: 560px) {
  .slot { width: 64px; height: 74px; }
  .slot .ic { font-size: 24px; }
  .pad { width: 128px; height: 128px; }
  .hud-bottom { flex-direction: row; }
  .pending { width: 212px; }
  .pending-odds { display: none; }
  .manhole-prompt { bottom: calc(184px + var(--safe-b)); }
  .panel h1 { font-size: 44px; }
}
@media (max-width: 420px) {
  .pad { width: 112px; height: 112px; }
  .slot { width: 58px; height: 70px; }
  .slot .nm { font-size: 10px; }
}
