:root {
  --bg: #0e1014;
  --bg2: #161922;
  --panel: #1a1e28;
  --panel2: #232836;
  --line: rgba(255,255,255,.08);
  --text: #eef0f5;
  --muted: #9aa1b2;
  --accent: #f2c14e;
  --danger: #ff6b6b;
  --coin: min(68vw, 300px, 40vh);
  --thick: calc(var(--coin) * .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* Münz-Stile: Fläche hell/dunkel, Rand, Gravur */
.style-gold    { --c1:#fff3c4; --c2:#f2c14e; --c3:#b8811c; --c4:#7a520c; --ink:#6b4508; --glow: rgba(242,193,78,.35); --accent:#f2c14e; }
.style-silver  { --c1:#ffffff; --c2:#d5dae3; --c3:#9aa2b1; --c4:#5f6675; --ink:#4a515f; --glow: rgba(213,218,227,.3); --accent:#d5dae3; }
.style-copper  { --c1:#ffd9c2; --c2:#e08a5a; --c3:#a8532b; --c4:#6b2f14; --ink:#5e260e; --glow: rgba(224,138,90,.35); --accent:#ef9a6a; }
.style-night   { --c1:#4a5a8c; --c2:#26315a; --c3:#151c38; --c4:#0a0e20; --ink:#f2c14e; --glow: rgba(110,130,220,.35); --accent:#8ea2ff; }
.style-rose    { --c1:#ffe3ea; --c2:#f2a7b8; --c3:#c06a82; --c4:#7d3a4d; --ink:#6e2a3e; --glow: rgba(242,167,184,.35); --accent:#f2a7b8; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 70% at 50% 38%, var(--glow) 0%, transparent 55%),
    radial-gradient(100% 60% at 50% 110%, #1b2030 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overflow-x: hidden;
  transition: background .6s;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

/* Kopfzeile */
.top { display: flex; align-items: center; justify-content: space-between; height: 48px; }
.brand { font-weight: 700; letter-spacing: .02em; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2) 45%, var(--c3) 80%, var(--c4));
  box-shadow: 0 0 12px var(--glow);
}
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); display: grid; place-items: center;
  transition: background .2s, transform .1s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg, .img-btn svg, .swap-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Frage */
.question { display: block; margin-top: 10px; }
.question input {
  width: 100%; height: 46px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); padding: 0 16px; outline: none; text-align: center;
  transition: border-color .2s, background .2s;
}
.question input::placeholder { color: var(--muted); }
.question input:focus { border-color: var(--accent); background: rgba(255,255,255,.07); }

/* Bühne + Münze */
.stage {
  flex: 1; min-height: calc(var(--coin) + 80px);
  display: grid; place-items: center; position: relative;
  perspective: 1100px;
}
.toss { position: relative; z-index: 2; will-change: transform; }
.coin {
  position: relative; display: block;
  width: var(--coin); height: var(--coin);
  border: 0; padding: 0; background: none; border-radius: 50%;
  transform-style: preserve-3d;
  will-change: transform;
  touch-action: manipulation;
  outline: none;
}
.coin:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.edge { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }
.edge i {
  position: absolute; inset: 0; border-radius: 50%;
  background: linear-gradient(90deg, var(--c4), var(--c3) 30%, var(--c2) 50%, var(--c3) 70%, var(--c4));
}
.face {
  position: absolute; inset: 0; border-radius: 50%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background:
    repeating-conic-gradient(from 0deg, rgba(0,0,0,.18) 0 1.2deg, transparent 1.2deg 3deg),
    radial-gradient(circle at 32% 26%, var(--c1) 0%, var(--c2) 38%, var(--c3) 78%, var(--c4) 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25), inset 0 -6px 14px rgba(0,0,0,.25);
  overflow: hidden;
}
.front { transform: translateZ(calc(var(--thick) / 2)); }
.back  { transform: rotateX(180deg) translateZ(calc(var(--thick) / 2)); }
.face-inner {
  position: absolute; inset: 7%; border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, var(--c1) 0%, var(--c2) 45%, var(--c3) 100%);
  box-shadow:
    inset 0 3px 6px rgba(255,255,255,.35),
    inset 0 -4px 10px rgba(0,0,0,.35),
    0 0 0 3px rgba(0,0,0,.12),
    0 2px 2px rgba(255,255,255,.25);
  display: grid; place-items: center; overflow: hidden;
}
.face-inner::before {
  content: ""; position: absolute; inset: 6%; border-radius: 50%;
  border: 2px dotted color-mix(in srgb, var(--ink) 45%, transparent);
  pointer-events: none;
}
.face-inner::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: linear-gradient(125deg, rgba(255,255,255,.45) 0%, rgba(255,255,255,0) 32%, rgba(255,255,255,0) 68%, rgba(255,255,255,.12) 100%);
  pointer-events: none;
}
.face-text {
  position: relative; z-index: 1; display: block;
  max-width: 76%;
  text-align: center; overflow-wrap: normal; hyphens: manual;
  font-family: ui-serif, Georgia, "Times New Roman", serif; font-weight: 700;
  line-height: 1.05; letter-spacing: .01em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,.45), 0 -1px 0 rgba(0,0,0,.25);
}
.face.has-img .face-text { display: none; }
.face-inner img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.shadow {
  position: absolute; left: 50%; top: calc(50% + var(--coin) / 2 + 6px); z-index: 1;
  width: calc(var(--coin) * .8); height: calc(var(--coin) * .12);
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), transparent 70%);
  will-change: transform, opacity;
}

/* Ergebnis */
.result { text-align: center; min-height: 86px; display: flex; flex-direction: column; justify-content: center; }
.result-label {
  font-size: clamp(24px, 7vw, 34px); font-weight: 750; letter-spacing: -.01em;
  overflow-wrap: anywhere; transition: opacity .3s, transform .3s;
}
.result-label.win { color: var(--accent); animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.result-sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.result.hidden-out .result-label, .result.hidden-out .result-sub { opacity: 0; transform: translateY(6px); }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.pair-stats { display: flex; justify-content: center; gap: 8px; min-height: 30px; margin: 4px 0 12px; flex-wrap: wrap; }
.pill { font-size: 13px; color: var(--muted); padding: 5px 12px; border-radius: 999px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.pill b { color: var(--text); font-weight: 650; }

.actions { display: flex; }
.flip-btn {
  flex: 1; height: 58px; border-radius: 18px; border: 0;
  font-size: 18px; font-weight: 700; letter-spacing: .02em; color: #1a1408;
  background: linear-gradient(180deg, var(--c1), var(--c2) 55%, var(--c3));
  box-shadow: 0 10px 30px var(--glow), inset 0 1px 0 rgba(255,255,255,.6);
  transition: transform .1s, filter .2s;
}
.style-night .flip-btn { color: #fff; }
.flip-btn:active { transform: scale(.98); }
.flip-btn:disabled { filter: saturate(.6) brightness(.85); }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; animation: fade .2s; backdrop-filter: blur(2px); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 88dvh;
  background: var(--panel); border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0;
  display: flex; flex-direction: column;
  animation: up .28s cubic-bezier(.2,.9,.3,1);
  box-shadow: 0 -20px 60px rgba(0,0,0,.5);
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.18); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 8px; }
.sheet-head h2 { font-size: 18px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + var(--safe-b)); overscroll-behavior: contain; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 10px; font-weight: 650; }
.text-btn { background: none; border: 0; color: var(--accent); font-weight: 650; padding: 8px 4px; }
.text-btn.small { font-size: 14px; padding: 4px 0; }

.sides { display: flex; flex-direction: column; gap: 6px; }
.side-tag { font-size: 12px; color: var(--muted); margin: 0 0 6px 4px; }
.side-row { display: flex; gap: 8px; }
.side-input {
  flex: 1; min-width: 0; height: 50px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel2); padding: 0 14px; font-size: 18px; outline: none;
}
.side-input:focus { border-color: var(--accent); }
.img-btn, .swap-btn {
  width: 50px; height: 50px; flex: none; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel2); display: grid; place-items: center; cursor: pointer;
}
.swap-btn { align-self: center; width: 44px; height: 36px; border-radius: 12px; }
.img-preview { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.img-preview img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:active { transform: scale(.97); }
.chip.on { border-color: var(--accent); }

.styles { display: flex; gap: 12px; flex-wrap: wrap; }
.style-dot {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid transparent; padding: 0;
  background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2) 45%, var(--c3) 80%, var(--c4));
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.12);
}
.style-dot.on { border-color: var(--text); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--text); }

.toggle { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

.install { margin-top: 18px; }
.ghost-btn {
  width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel2); font-weight: 650;
}
.ghost-btn.danger { color: var(--danger); margin-top: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 2px; }
.hint.center { text-align: center; padding: 24px 0; }
.fine { color: var(--muted); font-size: 13px; margin-top: 18px; opacity: .8; }

/* Verlauf */
.hist-summary { display: flex; flex-direction: column; gap: 10px; }
.sum-row { background: var(--panel2); border-radius: 14px; padding: 12px 14px; }
.sum-names { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 8px; }
.sum-names span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.sum-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.hist-list { list-style: none; padding: 0; margin: 16px 0 0; }
.hist-list li { display: flex; gap: 12px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.hist-coin {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2) 45%, var(--c3)); color: var(--ink);
  font: 700 13px ui-serif, Georgia, serif; overflow: hidden;
}
.hist-coin img { width: 100%; height: 100%; object-fit: cover; }
.hist-main { flex: 1; min-width: 0; }
.hist-win { font-weight: 650; overflow-wrap: anywhere; }
.hist-meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.hist-time { color: var(--muted); font-size: 12px; white-space: nowrap; }

@media (min-height: 800px) { :root { --coin: min(72vw, 320px, 42vh); } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop, .result-label.win { animation: none; } }
