@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap');

:root {
  --bg-outer: #e7e3da;
  --bg-card: #faf8f2;
  --surface: #fff;
  --surface-btn: #f3efe6;
  --text: #1a1a1a;
  --text-muted: #6b6560;
  --text-faint: #a39d95;
  --border: #ece7dd;
  --border-soft: #e3ddd2;
  --border-dashed: #ddd6c9;
  --red: #E23B2E;
  --blue: #2E4EA4;
  --gold: #EAB000;
  --teal: #17876B;
  --pink: #E63B8A;
  --orange: #EE7326;
  --purple: #6E3FA3;
  --cyan: #22A7C0;
  --font-display: 'Fredoka', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #app { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg-outer);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 0; height: 0; }
.scrollx { scrollbar-width: none; }
.scrollx::-webkit-scrollbar { display: none; }

@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sheetup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.fadeup { animation: fadeup .35s ease; }
.shake { animation: shake .4s; }

/* ---------- app shell ---------- */
/* height (not min-height) so the nested flex:1 + overflow-y:auto content
   area actually scrolls internally instead of growing the whole page —
   100dvh accounts for mobile browser toolbars, with a 100vh fallback. */
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: var(--bg-outer);
}
.phone {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100%;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,.12);
}

/* ---------- login ---------- */
.login-screen {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 28px;
  overflow: hidden;
}
.petal { position: absolute; opacity: .9; }
.login-card {
  position: relative;
  background: var(--surface);
  border-radius: 26px;
  padding: 32px 26px 26px;
  box-shadow: 0 24px 60px rgba(26,26,26,.14);
}
.login-logo { display: flex; align-items: baseline; gap: 6px; justify-content: center; font-family: var(--font-display); font-weight: 700; line-height: .85; font-size: 72px; letter-spacing: -2px; }
.login-title { text-align: center; margin-top: 10px; font-family: var(--font-display); font-weight: 600; font-size: 22px; }
.login-sub { text-align: center; margin-top: 4px; color: var(--text-muted); font-size: 14px; }
.pin-boxes { display: flex; gap: 12px; justify-content: center; margin: 26px 0 6px; }
.pin-box {
  width: 52px; height: 60px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--blue); background: var(--surface-btn); border: 2px solid transparent;
}
.pin-box.filled { background: #eef1fb; border-color: var(--blue); }
.pin-msg { height: 18px; text-align: center; color: #c0392b; font-size: 13px; font-weight: 600; }
.login-hint { text-align: center; margin-top: 18px; color: var(--text-faint); font-size: 12px; }
.login-link { display: block; text-align: center; margin-top: 12px; background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; text-decoration: underline; }

.keypad { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 8px; }
.keypad button {
  height: 56px; border: none; border-radius: 16px; background: var(--surface-btn);
  font-family: var(--font-display); font-weight: 600; font-size: 24px; color: var(--text);
}
.keypad button.ghost { background: transparent; cursor: default; }
.keypad button.del { font-size: 22px; color: var(--text-muted); font-family: inherit; font-weight: 400; }

/* ---------- app content ---------- */
.app-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.app-content { flex: 1; overflow-y: auto; padding-bottom: 96px; }
.screen-header { padding: 22px 20px 12px; }
.screen-title { font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.screen-sub { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* ---------- dashboard ---------- */
.dash-hero { position: relative; padding: 26px 22px 30px; background: linear-gradient(135deg,#2E4EA4,#6E3FA3); overflow: hidden; border-radius: 0 0 28px 28px; }
.dash-blob { position: absolute; border-radius: 100% 0 100% 100%; }
.dash-head { position: relative; color: #fff; }
.dash-head .hello { font-size: 14px; opacity: .85; }
.dash-head .title { font-family: var(--font-display); font-weight: 600; font-size: 26px; margin-top: 2px; }
.dash-progress { position: relative; display: flex; align-items: center; gap: 20px; margin-top: 20px; }
.ring { width: 118px; height: 118px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring-inner { width: 88px; height: 88px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-pct { font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1; color: var(--text); }
.ring-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.dash-count { color: #fff; }
.dash-count .n { font-family: var(--font-display); font-weight: 600; font-size: 24px; line-height: 1; }
.dash-count .n span { opacity: .7; font-size: 16px; }
.dash-count .label { font-size: 13px; opacity: .85; margin-top: 4px; }

.stat-row { display: flex; gap: 12px; padding: 18px 18px 4px; }
.stat-card { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; }
.stat-num { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.section-title { padding: 18px 18px 6px; font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.almost-row { display: flex; gap: 12px; overflow-x: auto; padding: 0 18px 8px; }
.almost-card { flex: 0 0 auto; width: 132px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; }
.almost-card .top { display: flex; align-items: center; gap: 8px; }
.almost-card .flag { font-size: 22px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.almost-card .name { font-weight: 600; font-size: 14px; margin-top: 8px; }
.bar-track { height: 6px; background: #efeae0; border-radius: 99px; margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.almost-card .meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ---------- search + variant switch ---------- */
.search-wrap { margin: 0 20px 12px; position: relative; }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 16px; opacity: .5; }
.search-input { width: 100%; padding: 13px 40px 13px 42px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); font-size: 15px; font-family: inherit; color: var(--text); outline: none; }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border: none; border-radius: 50%; background: var(--surface-btn); color: var(--text-muted); font-size: 15px; }
.variant-switch { display: flex; gap: 6px; margin: 0 20px 14px; background: var(--surface-btn); border-radius: 99px; padding: 4px; }
.variant-switch button { flex: 1; padding: 9px; border: none; border-radius: 99px; font-weight: 600; font-size: 14px; background: transparent; color: #8a847b; }
.variant-switch button.active { background: #fff; color: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,.08); }

.empty-state { margin: 8px 20px; padding: 30px; text-align: center; color: var(--text-faint); border: 1.5px dashed var(--border-dashed); border-radius: 18px; font-size: 14px; }

/* ---------- fehlliste: list variant ---------- */
.card-list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.team-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.team-card-head { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: none; border: none; text-align: left; }
.group-badge { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 8px; font-family: var(--font-display); font-weight: 700; font-size: 13px; flex-shrink: 0; }
.page-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 8px; font-family: var(--font-display); font-weight: 700; font-size: 12px; flex-shrink: 0; background: var(--surface-btn); color: var(--text-muted); }
.team-card-head .flag { font-size: 24px; }
.team-card-head .name { flex: 1; font-weight: 600; font-size: 16px; }
.team-card-head .frac { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.chevron { font-size: 22px; color: #c3bcb0; transition: transform .2s; display: inline-block; }
.team-card-body { padding: 2px 16px 16px; }
.chip-grid { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; }
.chip { aspect-ratio: 1; border-radius: 12px; font-family: var(--font-display); font-weight: 600; font-size: 15px; border: none; }
.chip.missing { border: 1.5px dashed #d3ccbf; background: var(--bg-card); color: #b3ab9e; }

/* ---------- fehlliste: tile variant ---------- */
.tile-grid { padding: 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile-card { position: relative; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 14px; overflow: hidden; }
.tile-corner { position: absolute; top: -18px; right: -18px; width: 60px; height: 60px; border-radius: 0 0 0 100%; }
.tile-top { position: relative; display: flex; align-items: center; justify-content: space-between; }
.tile-top .flag { font-size: 26px; }
.tile-card .name { position: relative; font-weight: 600; font-size: 15px; margin-top: 10px; }
.tile-card .bar-track { margin-top: 8px; }
.tile-card .meta { position: relative; font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 600; }

/* ---------- doppelte ---------- */
.entry-card { margin: 12px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 18px; }
.entry-select { width: 100%; padding: 12px 14px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); font-size: 15px; font-family: inherit; margin-bottom: 14px; }
.entry-row { display: flex; align-items: center; justify-content: space-between; }
.entry-display { font-family: var(--font-display); font-weight: 700; font-size: 40px; line-height: 1; min-height: 44px; }
.entry-hint { text-align: right; font-size: 13px; color: var(--text-muted); max-width: 150px; }
.entry-add { margin-top: 14px; width: 100%; padding: 14px; border: none; border-radius: 16px; font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.entry-add.enabled { background: var(--orange); color: #fff; }
.entry-add.disabled { background: var(--border-soft); color: var(--text-faint); }

.double-list { padding: 0 18px; display: flex; flex-direction: column; gap: 8px; }
.double-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; }
.double-num { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 11px; font-family: var(--font-display); font-weight: 700; font-size: 16px; flex-shrink: 0; }
.double-info { flex: 1; }
.double-info .name { font-weight: 600; font-size: 14px; }
.double-info .meta { font-size: 12px; color: var(--text-muted); }
.stepper-btn { width: 34px; height: 34px; border-radius: 10px; font-size: 20px; font-weight: 600; }
.stepper-btn.dec { border: 1px solid var(--border-soft); background: var(--bg-card); color: var(--text); }
.stepper-btn.inc { border: none; background: var(--orange); color: #fff; }
.stepper-count { font-family: var(--font-display); font-weight: 700; font-size: 18px; min-width: 22px; text-align: center; }

/* ---------- tauschen ---------- */
.trade-hero { margin: 12px 18px; padding: 18px; border-radius: 20px; background: linear-gradient(135deg,#17876B,#22A7C0); color: #fff; }
.trade-hero .title { font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.trade-hero .sub { font-size: 13px; opacity: .9; margin-top: 2px; }
.trade-hero button { margin-top: 14px; width: 100%; padding: 13px; border: none; border-radius: 99px; background: #fff; color: var(--teal); font-weight: 700; font-size: 15px; font-family: var(--font-display); }
.trade-chips { padding: 0 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.trade-chip { display: inline-flex; align-items: baseline; gap: 3px; white-space: nowrap; padding: 8px 13px; border-radius: 12px; background: #fff; font-family: var(--font-display); font-weight: 700; font-size: 15px; border: 1px solid; }
.trade-chip .x { opacity: .6; font-size: 11px; }

/* ---------- import ---------- */
.import-card { margin: 12px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 18px; }
.import-card textarea { width: 100%; min-height: 140px; padding: 12px 14px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--bg-card); font-size: 14px; font-family: 'SFMono-Regular', Consolas, monospace; resize: vertical; }
.import-card input[type=file] { margin-bottom: 10px; font-size: 13px; }
.import-card .hint { font-size: 12px; color: var(--text-muted); margin: 8px 0 14px; }
.import-btn { width: 100%; padding: 14px; border: none; border-radius: 16px; background: var(--blue); color: #fff; font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.import-log { margin: 0 18px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; font-size: 13px; color: var(--text-muted); }
.import-log ul { margin: 6px 0 0; padding-left: 18px; }
.import-log li { margin-bottom: 4px; }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: absolute; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px); border-top: 1px solid var(--border); display: flex; padding: 8px 6px 12px;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none; padding: 4px 0; color: var(--text-faint); }
.nav-btn.active { color: var(--blue); }
.nav-btn .icon { font-size: 19px; line-height: 1; filter: grayscale(1) opacity(.7); }
.nav-btn.active .icon { filter: none; }
.nav-btn .label { font-size: 10px; font-weight: 600; }

/* ---------- bottom sheet + toast ---------- */
.sheet-backdrop { position: absolute; inset: 0; background: rgba(26,26,26,.45); z-index: 20; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg-card);
  border-radius: 24px 24px 0 0; padding: 8px 18px 24px; max-height: 82%; overflow-y: auto; animation: sheetup .28s ease;
}
.sheet-handle { width: 40px; height: 4px; background: var(--border-dashed); border-radius: 99px; margin: 8px auto 14px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sheet-head .flag { font-size: 30px; }
.sheet-head .name { font-family: var(--font-display); font-weight: 600; font-size: 20px; }
.sheet-head .meta { font-size: 13px; color: var(--text-muted); }
.sheet-close { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-soft); background: var(--surface); font-size: 18px; }

.toast {
  position: absolute; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: #fff; padding: 11px 20px; border-radius: 18px; font-size: 14px; font-weight: 600;
  animation: pop .3s ease; max-width: 84%; text-align: center;
}

.loading-screen { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; }
