/* ==========================================================================
   Klavier – Gestaltung wie WMJ Spiele: Holztisch, Papierkarten, Fraunces + Manrope, gedruckte Knöpfe.
   Spieler: Vollbild-Leinwand (fallende Noten + Tastatur), Bedienleiste oben, sonst nichts.
   ========================================================================== */
:root {
  --wood: #2a1e17;
  --paper: #f3ead8; --paper-2: #e8dcc4; --paper-3: #d9caae; --card: #fbf6ea;
  --ink: #2b231e; --ink-2: #5d5046; --ink-3: #8a7b6d; --line: rgba(43, 35, 30, .16);
  --on-wood: #f1e7d4; --on-wood-2: #e2d4bd; --on-wood-3: #c9b79d; --wood-line: rgba(241, 231, 212, .14);
  --red: #c4472f; --red-d: #96331f; --mustard: #d9a23a; --mustard-d: #a8781f; --teal: #2e7b77; --teal-d: #1f5a57;
  --right: #f0b84a; --left: #4fb3a9;   /* Hände: rechts Senf, links Petrol (wie in den Noten auf der Leinwand) */
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --text: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --r: 14px; --r-sm: 6px; --r-md: 10px; --r-pill: 99px;
  --fs-cap: 11px; --fs-small: 13px; --fs-body: 15px; --fs-ui: 16px;
  --spring: cubic-bezier(.22, 1.4, .36, 1); --ease: cubic-bezier(.2, .7, .2, 1);
  --shadow-1: 0 1px 0 rgba(255, 255, 255, .5) inset, 0 2px 3px rgba(20, 12, 6, .25), 0 8px 18px -6px rgba(20, 12, 6, .45);
  --shadow-2: 0 2px 4px rgba(20, 12, 6, .3), 0 18px 40px -12px rgba(10, 6, 2, .6);
  --bg-hi: #4d3527; --bg-lo: #1b120d;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .24 0 0 0 0 .16 0 0 0 .11 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fibers: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .6' numOctaves='2' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .3 0 0 0 0 .2 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --feltnoise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='t'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23t)'/%3E%3C/svg%3E");
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--wood); }
body {
  margin: 0; min-height: 100dvh; color: var(--on-wood); font-family: var(--text); font-size: 16px; line-height: 1.45; font-weight: 500;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  background: var(--feltnoise), radial-gradient(120% 90% at 50% 15%, var(--bg-hi), var(--bg-lo) 75%) fixed, var(--bg-lo);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
svg { display: block; }
::selection { background: var(--mustard); color: var(--ink); }
.ic { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Bausteine ---------- */
.paper { position: relative; color: var(--ink); background: var(--grain), var(--fibers), var(--paper); border-radius: var(--r); box-shadow: var(--shadow-1); }
.title { font-family: var(--display); font-weight: 700; font-variation-settings: "opsz" 72, "SOFT" 50; letter-spacing: -.01em; line-height: 1.05; }
.eyebrow { font: 800 var(--fs-cap)/1.2 var(--text); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }

.btn {
  --bg: var(--paper); --fg: var(--ink); --edge: var(--paper-3);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 46px;
  font: 700 var(--fs-ui)/1.1 var(--text); color: var(--fg); background: var(--grain), var(--bg); border: 0; border-radius: 12px; padding: 12px 18px;
  box-shadow: 0 3px 0 var(--edge), 0 6px 14px -4px rgba(10, 6, 2, .5), inset 0 1px 0 rgba(255, 255, 255, .35);
  cursor: pointer; user-select: none; transition: transform .12s var(--ease), box-shadow .12s, filter .2s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge), 0 2px 6px -2px rgba(10, 6, 2, .5), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn.primary { --bg: var(--red); --fg: #fff6ea; --edge: var(--red-d); }
.btn.mustard { --bg: var(--mustard); --fg: #2b1d08; --edge: var(--mustard-d); }
.btn.dark { --bg: #3b2d24; --fg: #f1e7d4; --edge: #1e1510; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn .ic { width: 18px; height: 18px; }
.iconbtn {
  width: 46px; height: 46px; display: inline-grid; place-items: center; border: 0; border-radius: 12px; cursor: pointer; flex: none;
  color: var(--on-wood); background: rgba(255, 248, 234, .08); box-shadow: inset 0 0 0 1px var(--wood-line); transition: background .15s, transform .12s var(--ease);
}
.iconbtn:hover { background: rgba(255, 248, 234, .14); }
.iconbtn:active { transform: scale(.94); }
.iconbtn .ic { width: 22px; height: 22px; }

.field { display: block; width: 100%; font: 600 var(--fs-ui) var(--text); color: var(--ink); background: var(--card); border: 0; border-radius: var(--r-md);
  padding: 13px 14px; box-shadow: inset 0 0 0 1.5px var(--line), inset 0 2px 3px rgba(43, 35, 30, .08); outline: none; }
.field:focus { box-shadow: inset 0 0 0 2px var(--mustard), inset 0 2px 3px rgba(43, 35, 30, .08); }
.field::placeholder { color: var(--ink-3); font-weight: 500; }

.shake { animation: shake .4s var(--ease); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- Anmelden / Beitreten ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-4); }
.gate-card { width: min(380px, 100%); padding: var(--sp-6) var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); text-align: center; }
.gate-card .logo { width: 64px; height: 64px; margin: 0 auto var(--sp-1); border-radius: 16px; box-shadow: var(--shadow-1); }
.gate-card h1 { margin: 0 0 var(--sp-2); font-size: 34px; }
.gate-card .err { min-height: 20px; margin: 0; font-size: var(--fs-small); font-weight: 700; color: var(--red-d); }

/* ---------- Bibliothek ---------- */
.lib { max-width: 860px; margin: 0 auto; padding: max(var(--sp-4), env(safe-area-inset-top)) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom)); }
.lib-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.lib-head .logo { width: 40px; height: 40px; border-radius: 11px; box-shadow: 0 4px 10px rgba(0, 0, 0, .35); }
.lib-head h1 { margin: 0; flex: 1; font-size: 28px; color: var(--on-wood); text-shadow: 0 1px 2px rgba(10, 5, 2, .85); }
.lib-head .count { font: 700 var(--fs-small) var(--text); color: var(--on-wood-3); font-variant-numeric: tabular-nums; }
.search { position: relative; }
.search .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .field { padding: 15px 44px 15px 44px; font-size: 17px; border-radius: 14px; box-shadow: var(--shadow-1); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.search .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; border-radius: 10px; background: none; color: var(--ink-3); cursor: pointer; display: grid; place-items: center; }

.chips { display: flex; gap: var(--sp-2); margin: var(--sp-3) 0 var(--sp-4); overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border: 0; border-radius: var(--r-pill); cursor: pointer;
  font: 700 14px var(--text); color: var(--on-wood-2); background: rgba(255, 248, 234, .07); box-shadow: inset 0 0 0 1px var(--wood-line); white-space: nowrap;
}
.chip .ic { width: 17px; height: 17px; }
.chip.on { color: var(--ink); background: var(--grain), var(--mustard); box-shadow: 0 2px 0 var(--mustard-d); }
.chip select { appearance: none; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; outline: none; padding-right: 2px; max-width: 150px; }
.chip select option { color: var(--ink); background: var(--card); }
.chip.lv { gap: 0; padding: 0 6px; }
.chip.lv .lb { width: 13px; height: 38px; padding: 0; border: 0; cursor: pointer; color: inherit; opacity: .45;
  background: linear-gradient(currentColor, currentColor) center calc(100% - 11px) / 6px var(--h) no-repeat; }
.chip.lv .lb.on { opacity: 1; }
.chip.lv.on .lb:not(.on) { opacity: .3; }

.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--sp-3); padding: 12px 14px; border-radius: var(--r-md); cursor: pointer;
  text-decoration: none; color: var(--ink); background: var(--grain), var(--card); box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset, 0 2px 6px -2px rgba(10, 6, 2, .45);
  transition: transform .15s var(--ease);
}
.row:active { transform: scale(.985); }
.row b { display: block; font: 700 17px/1.2 var(--display); font-variation-settings: "opsz" 30; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { display: block; margin-top: 2px; font-size: var(--fs-small); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t { min-width: 0; }
.row .m { display: flex; align-items: center; gap: var(--sp-3); color: var(--ink-3); font: 700 var(--fs-small) var(--text); font-variant-numeric: tabular-nums; }
.row .m .ic { width: 16px; height: 16px; }
.row .best { color: var(--teal-d); }
.lvl { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; }
.lvl u { width: 4px; border-radius: 1px; background: currentColor; opacity: .25; }
.lvl u:nth-child(1) { height: 5px; } .lvl u:nth-child(2) { height: 7px; } .lvl u:nth-child(3) { height: 9px; } .lvl u:nth-child(4) { height: 11px; } .lvl u:nth-child(5) { height: 13px; }
.lvl u.on { opacity: 1; }
.lvl[data-l="1"], .lvl[data-l="2"] { color: var(--teal); } .lvl[data-l="3"] { color: var(--mustard-d); } .lvl[data-l="4"], .lvl[data-l="5"] { color: var(--red); }
.empty { padding: var(--sp-6) 0; display: grid; place-items: center; color: var(--on-wood-3); }
.empty .ic { width: 48px; height: 48px; stroke-width: 1.4; }
.more { height: 1px; }

/* Menü (Konto) */
.menu { position: fixed; z-index: 30; right: var(--sp-4); top: calc(max(var(--sp-4), env(safe-area-inset-top)) + 52px); width: 250px; padding: var(--sp-2); display: flex; flex-direction: column; gap: 2px; animation: pop .2s var(--spring); }
.menu .who { padding: 10px 12px 8px; font: 800 var(--fs-small) var(--text); color: var(--ink-2); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); font-weight: 700; text-align: left; cursor: pointer; }
.menu button:hover { background: rgba(43, 35, 30, .07); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
.scrim { position: fixed; inset: 0; z-index: 25; }
.sheet-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(10, 6, 2, .55); display: grid; place-items: center; padding: var(--sp-4); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); animation: pop .25s var(--spring); }
.sheet h2 { margin: 0; font-size: 24px; }
.sheet .link { font: 600 var(--fs-small) ui-monospace, monospace; word-break: break-all; padding: 10px 12px; border-radius: 8px; background: var(--card); box-shadow: inset 0 0 0 1px var(--line); user-select: all; }
.sheet .row2 { display: flex; gap: var(--sp-2); }
.sheet .row2 > * { flex: 1; }

/* ---------- Spieler ---------- */
.play { position: fixed; inset: 0; background: #120c09; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.play canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: center; gap: var(--sp-2);
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(18, 12, 9, .92), rgba(18, 12, 9, .7) 70%, rgba(18, 12, 9, 0));
}
.bar .name { flex: 1; min-width: 0; padding: 0 4px; }
.bar .name b { display: block; font: 700 17px/1.15 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .name small { display: block; font-size: 12px; color: var(--on-wood-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .iconbtn { width: 42px; height: 42px; background: rgba(255, 248, 234, .06); }
.bar .iconbtn.on { color: var(--ink); background: var(--grain), var(--mustard); box-shadow: 0 2px 0 var(--mustard-d); }
.bar .iconbtn.hand { position: relative; }
.bar .iconbtn.hand.on.l { background: var(--grain), var(--left); box-shadow: 0 2px 0 #2f7e76; }
.bar .iconbtn.hand.on.r { background: var(--grain), var(--right); box-shadow: 0 2px 0 #b9862a; }
.bar .tempo { width: auto; min-width: 58px; padding: 0 10px; font: 800 14px var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar .sep { width: 1px; height: 26px; background: var(--wood-line); margin: 0 2px; }
.bar .midi.on { color: #8fe0a0; }
.bar .mic.on { box-shadow: 0 2px 0 var(--mustard-d), 0 0 0 calc(var(--lv, 0) * 6px) rgba(217, 162, 58, .35); }
.seek { position: absolute; z-index: 6; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); height: 22px; cursor: pointer; touch-action: none; }
.seek i { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 99px; background: rgba(255, 248, 234, .16); }
.seek u { position: absolute; left: 0; top: 9px; height: 4px; border-radius: 99px; background: var(--mustard); width: calc(var(--p, 0) * 100%); }
.seek b { position: absolute; top: 4px; left: calc(var(--p, 0) * 100% - 7px); width: 14px; height: 14px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
.bigplay {
  position: absolute; z-index: 4; left: 50%; top: 42%; transform: translate(-50%, -50%); width: 84px; height: 84px; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #2b1d08; background: var(--grain), var(--mustard); box-shadow: 0 5px 0 var(--mustard-d), 0 14px 30px rgba(0, 0, 0, .5);
  transition: transform .15s var(--ease), opacity .2s;
}
.bigplay .ic { width: 38px; height: 38px; fill: currentColor; stroke-width: 0; margin-left: 5px; }
.bigplay:active { transform: translate(-50%, -46%); }
.pop {
  position: absolute; z-index: 6; top: calc(max(8px, env(safe-area-inset-top)) + 58px); right: max(10px, env(safe-area-inset-right)); width: min(300px, calc(100% - 20px));
  padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); animation: pop .2s var(--spring);
}
.pop label { display: flex; align-items: center; gap: var(--sp-3); font: 700 var(--fs-body) var(--text); cursor: pointer; }
.pop label > span { flex: 1; display: inline-flex; align-items: center; gap: 6px; }
.pop input[type=range] { width: 100%; accent-color: var(--mustard-d); }
.pop .val { font: 800 var(--fs-small) var(--text); color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.pop .tg { width: 44px; height: 26px; border-radius: 99px; background: var(--paper-3); position: relative; transition: background .15s; flex: none; }
.pop .tg::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s var(--spring); }
.pop input:checked + .tg { background: var(--teal); }
.pop input:checked + .tg::after { transform: translateX(18px); }
.pop input[type=checkbox] { display: none; }
.pop .credits { font-size: 11px; line-height: 1.4; color: var(--ink-3); }
.pop .credits a { color: inherit; }
.result {
  position: absolute; z-index: 7; left: 50%; top: 45%; transform: translate(-50%, -50%); width: min(320px, calc(100% - 32px)); padding: var(--sp-5);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); text-align: center; animation: pop .3s var(--spring);
}
.result .pct { font: 800 64px/1 var(--display); font-variation-settings: "opsz" 144; color: var(--ink); font-variant-numeric: tabular-nums; }
.result .sub { display: flex; gap: var(--sp-4); font: 700 var(--fs-small) var(--text); color: var(--ink-2); }
.result .sub span { display: inline-flex; align-items: center; gap: 4px; }
.result .sub .ic { width: 16px; height: 16px; }
.result .row2 { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); width: 100%; }
.result .row2 .btn { flex: 1; }
.rotate { position: absolute; z-index: 3; left: 50%; top: 58%; transform: translateX(-50%); color: var(--on-wood-3); opacity: .8; pointer-events: none; animation: rot 2.4s var(--ease) infinite; }
.rotate .ic { width: 40px; height: 40px; stroke-width: 1.4; }
@keyframes rot { 0%, 30% { transform: translateX(-50%) rotate(0); } 60%, 100% { transform: translateX(-50%) rotate(-90deg); } }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--on-wood-3); }
.spin { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(255, 248, 234, .15); border-top-color: var(--mustard); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .bar { gap: 5px; }
  .bar .iconbtn { width: 38px; height: 38px; border-radius: 10px; }
  .bar .iconbtn .ic { width: 20px; height: 20px; }
  .bar .tempo { min-width: 50px; padding: 0 6px; font-size: 13px; }
  .bar .sep { display: none; }
}
/* Titel über dem Startknopf, wenn die Leiste dafür zu schmal ist */
.ptitle { position: absolute; z-index: 4; left: 50%; top: calc(42% - 92px); transform: translate(-50%, -100%); width: min(90%, 520px); text-align: center; pointer-events: none; display: none; }
.ptitle b { display: block; font: 700 22px/1.2 var(--display); text-shadow: 0 2px 8px rgba(0, 0, 0, .8); }
.ptitle small { display: block; margin-top: 4px; font-size: var(--fs-small); color: var(--on-wood-3); text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
@media (max-width: 680px) {
  .bar .name { display: none; }
  .bar .back { margin-right: auto; }
  .ptitle { display: block; }
  .bigplay[hidden] ~ .ptitle { display: none; }
}
