/* Puzzles für Mama — warm, calm, senior-friendly */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #2b1d3a;
  --bg-soft: #3a2a4d;
  --card: #46325e;
  --card-soft: #54406f;
  --text: #f3ecfa;
  --text-dim: #b9a9cf;
  --accent: #e8a13c;
  --accent-deep: #c9882a;
  --green: #6fbf8b;
  --radius: 18px;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app { height: 100dvh; overflow: hidden; }

/* [hidden] must always win over component display rules */
[hidden] { display: none !important; }

.view {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.view.active { display: flex; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  flex: 0 0 auto;
}
.topbar h1 { font-size: 26px; font-weight: 800; letter-spacing: .3px; }

.back-btn {
  width: 44px; height: 44px;
  border: none; border-radius: 12px;
  background: var(--bg-soft); color: var(--text);
  font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

/* ===== Library ===== */
#view-library { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.continue-strip { padding: 6px 18px 4px; }
.daily-strip { padding: 6px 18px 4px; }
.daily-strip h2, .continue-strip h2, .library-section h2 {
  font-size: 15px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-dim); margin-bottom: 10px; font-weight: 700;
}
.daily-strip h2 { color: var(--accent); }

.pcard-daily { outline: 2.5px solid var(--accent); outline-offset: -2.5px; }
.daily-cards { grid-template-columns: 1fr 1fr; }

.library-section { padding: 14px 18px 120px; }

.puzzle-cards {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.pcard {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
  aspect-ratio: 1/1.08;
  display: flex; flex-direction: column;
  cursor: pointer;
  transition: transform .12s ease;
}
.pcard:active { transform: scale(.97); }

.pcard .thumb {
  flex: 1; min-height: 0;
  background-size: cover; background-position: center;
}
.pcard .label {
  padding: 9px 12px 11px;
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pcard .progress-pill {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.62);
  border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  padding: 4px 10px;
  color: var(--green);
  backdrop-filter: blur(4px);
}

.pcard-add {
  border: 2.5px dashed var(--card-soft);
  background: transparent;
  align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 15px; font-weight: 600;
  gap: 8px;
}
.pcard-add .plus { font-size: 40px; font-weight: 300; color: var(--accent); }

.add-photo-btn {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #241505;
  border: none; border-radius: 999px;
  font-size: 17px; font-weight: 800;
  padding: 15px 26px;
  box-shadow: 0 6px 22px rgba(232,161,60,.4);
  z-index: 5;
}

/* ===== Setup ===== */
.setup-body {
  flex: 1; display: flex; flex-direction: column;
  padding: 10px 22px calc(env(safe-area-inset-bottom, 0px) + 22px);
  overflow-y: auto;
}
.setup-preview {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #000;
  max-height: 52dvh;
  display: flex; align-items: center; justify-content: center;
}
.setup-preview img { max-width: 100%; max-height: 52dvh; display: block; }

.setup-controls { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }

.piece-count-display {
  text-align: center; font-size: 30px; font-weight: 800; color: var(--accent);
}
.piece-count-display small { font-size: 17px; color: var(--text-dim); font-weight: 600; }

.piece-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 46px;
  background: transparent;
}
.piece-slider::-webkit-slider-runnable-track {
  height: 10px; border-radius: 999px;
  background: var(--bg-soft);
}
.piece-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent);
  margin-top: -14px;
  box-shadow: 0 3px 10px rgba(0,0,0,.45);
  border: 3px solid #fff3;
}
.piece-slider::-moz-range-track {
  height: 10px; border-radius: 999px; background: var(--bg-soft);
}
.piece-slider::-moz-range-thumb {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff3;
}

.slider-labels {
  display: flex; justify-content: space-between;
  color: var(--text-dim); font-size: 13px; margin-top: -6px;
}

.aspect-hint { text-align: center; color: var(--text-dim); font-size: 14px; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #241505;
  border: none; border-radius: 16px;
  font-size: 19px; font-weight: 800;
  padding: 17px;
  box-shadow: 0 5px 18px rgba(232,161,60,.35);
}
.btn-primary:active { filter: brightness(.92); }

.btn-ghost {
  background: var(--bg-soft); color: var(--text);
  border: none; border-radius: 16px;
  font-size: 17px; font-weight: 700;
  padding: 15px;
}

/* ===== Game ===== */
#view-game { background: #241831; }

#board {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
}

.game-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  z-index: 10;
  pointer-events: none;
}
.game-topbar > * { pointer-events: auto; }

.game-btn {
  width: 48px; height: 48px;
  border: none; border-radius: 14px;
  background: rgba(38, 24, 56, .82);
  color: var(--text);
  font-size: 21px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.game-progress {
  background: rgba(38, 24, 56, .82);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 17px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}
.game-progress .done-all { color: var(--green); }

/* Peek overlay */
.peek-overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(15, 9, 24, .94);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
  padding: 40px 20px;
}
.peek-overlay img {
  max-width: 100%; max-height: 78dvh;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.peek-close {
  width: 52px; height: 52px;
  border: none; border-radius: 50%;
  background: var(--bg-soft); color: var(--text);
  font-size: 22px;
}

/* Menu sheet */
.menu-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--bg-soft);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5);
}
.menu-item {
  background: var(--card);
  border: none; border-radius: 14px;
  color: var(--text);
  font-size: 17.5px; font-weight: 700;
  text-align: left;
  padding: 16px 16px;
}

/* Win overlay */
.win-overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(15, 9, 24, .96);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.win-card {
  background: var(--bg-soft);
  border-radius: 24px;
  padding: 28px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  max-width: 420px; width: 100%;
  box-shadow: var(--shadow);
}
.win-emoji { font-size: 52px; }
.win-card h2 { font-size: 30px; font-weight: 800; color: var(--green); }
.win-card img {
  width: 100%; border-radius: 14px;
  box-shadow: var(--shadow);
}
.win-card p { color: var(--text-dim); font-size: 15.5px; text-align: center; }
.win-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 6px; }

/* Toast */
.toast {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  background: rgba(20, 12, 32, .92);
  color: var(--text);
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 15.5px; font-weight: 600;
  z-index: 60;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }
