:root {
  --bg: #101a30;
  --bg-alt: #16223e;
  --card: #1c2b4d;
  --border: #2c3d63;
  --text: #eef2fb;
  --text-dim: #9fb0d1;
  --accent: #f4b53f;
  --accent-dark: #d99a1f;
  --blue: #3f7bd6;
  --read: #d64545;
  --unread: #3fae5a;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-alt) 100%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
}

button, .tile, .hm-tile { touch-action: manipulation; }
input, select { font-size: 16px; }

button { font-family: inherit; }
button:disabled { cursor: wait; opacity: 0.65; }

.hidden { display: none !important; }

/* Auth */
#authScreen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.auth-card .sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.auth-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #1a1204;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  text-decoration: underline;
  padding: 8px;
  font-weight: 400;
}

#authStatus {
  min-height: 20px;
  font-size: 0.85rem;
  color: var(--read);
  margin-top: 8px;
}

/* App shell */
#appScreen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(16, 26, 48, 0.88);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
}

.version-badge {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.05rem;
}

.icon-btn:active { transform: scale(0.94); }

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.view { display: none; }
.view.active { display: block; }

/* Hero */
.hero {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(244, 181, 63, 0.3);
  border-radius: 22px;
  padding: 22px 20px;
  background:
    radial-gradient(circle at 100% 0%, rgba(244, 181, 63, 0.28), transparent 55%),
    linear-gradient(135deg, #24365f 0%, #1c2b4d 100%);
  box-shadow: 0 10px 30px rgba(5, 10, 24, 0.3);
}

.hero-label {
  color: var(--text-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-count {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 4px;
}

#heroTotal {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.hero-unit { color: var(--text); font-weight: 600; }

.hero-line {
  margin-top: 10px;
  max-width: 75%;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.35;
}

.hero-duck {
  position: absolute;
  right: 14px;
  bottom: 4px;
  font-size: 4.2rem;
  opacity: 0.9;
  transform: rotate(8deg);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

/* Progress bars */
.progress {
  height: 6px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(var(--tile-tint, 244, 181, 63), 0.7), rgb(var(--tile-tint, 244, 181, 63)));
  transition: width 500ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Home tiles */
.home-tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 16px;
}

.tile-body { flex: 1; min-width: 0; }

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 108px;
  padding: 16px;
  text-align: left;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 120ms ease, border-color 180ms ease;
}

.action-card:active { transform: scale(0.97); }
.action-icon { font-size: 1.6rem; margin-bottom: auto; }
.action-title { font-weight: 700; margin-top: 10px; }
.action-sub { color: var(--text-dim); font-size: 0.8rem; }
#backupCard.stale { border-color: rgba(244, 181, 63, 0.6); }
#backupCard.stale .action-sub { color: var(--accent); }

.tile {
  --tile-tint: 244, 181, 63;
  --tile-ink: #ffd987;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(5, 10, 24, 0.12);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 92% 16%, rgba(var(--tile-tint), 0.17), transparent 35%),
    linear-gradient(115deg, rgba(var(--tile-tint), 0.08), transparent 56%);
}

.tile::after {
  content: "";
  position: absolute;
  top: -30px;
  right: 42px;
  z-index: -1;
  width: 72px;
  height: 118px;
  border: 1px solid rgba(var(--tile-tint), 0.13);
  border-radius: 999px;
  transform: rotate(32deg);
}

.tile[data-open="dd_weekblad"] {
  --tile-tint: 244, 181, 63;
  --tile-ink: #ffd987;
}

.tile[data-open="kd_weekblad"] {
  --tile-tint: 222, 114, 165;
  --tile-ink: #f3aecf;
}

.tile[data-open="pockets"] {
  --tile-tint: 83, 193, 175;
  --tile-ink: #94dfd2;
}

.tile:hover {
  border-color: rgba(var(--tile-tint), 0.48);
  box-shadow: 0 12px 28px rgba(5, 10, 24, 0.22);
  transform: translateY(-2px);
}

.tile:focus-visible {
  outline: 3px solid rgba(var(--tile-tint), 0.4);
  outline-offset: 3px;
}

.tile:active { transform: scale(0.98); }

.tile .emoji {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(var(--tile-tint), 0.24);
  border-radius: 16px;
  background: rgba(var(--tile-tint), 0.11);
  font-size: 1.65rem;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}
.tile .tile-title { font-weight: 700; font-size: 1.05rem; }
.tile .tile-sub { color: var(--text-dim); font-size: 0.85rem; margin-top: 2px; }

.tile-arrow {
  margin-left: auto;
  color: var(--tile-ink);
  font-size: 1.15rem;
  opacity: 0.62;
  transition: opacity 180ms ease, transform 180ms ease;
}

.tile:hover .tile-arrow {
  opacity: 1;
  transform: translateX(3px);
}

@media (prefers-reduced-motion: reduce) {
  .tile, .tile-arrow, .progress span { transition: none; }
  .hm-tile.pop { animation: none; }
}

.quickcheck-banner {
  margin-top: 16px;
  background: var(--blue);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  font-weight: 700;
}

/* Back button / view header */
.view-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.back-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.1rem;
}

.back-btn:active { transform: scale(0.94); }

.view-header h2 { margin: 0; font-size: 1.2rem; }

/* Year chips */
.year-row {
  position: relative;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.year-row::-webkit-scrollbar { display: none; }

.year-progress { margin-bottom: 16px; }
.year-progress-text { color: var(--text-dim); font-size: 0.85rem; }
.year-progress .progress { margin-top: 6px; }

.year-chip {
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.year-chip.active {
  background: var(--accent);
  color: #1a1204;
  border-color: var(--accent);
}

.year-chip.add {
  color: var(--accent);
  border-style: dashed;
}

/* Heatmap grid */
.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}

.hm-tile {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--unread);
  opacity: 0.35;
  border: none;
  color: #08210f;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease;
}

.hm-tile:active { transform: scale(0.92); }

.hm-tile.read {
  background: var(--read);
  opacity: 1;
  color: #fff;
}

.hm-tile.unread { opacity: 0.35; }

.hm-tile.pop { animation: pop 340ms cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes pop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}

.hm-tile.special {
  border: 2px solid var(--accent);
  font-size: 0.7rem;
}

.section-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 8px;
}

.add-special-row { margin-top: 16px; }

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.inline-form input, .inline-form select {
  flex: 1;
  min-width: 100px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

/* Pockets */
.subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.subtab {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  font-weight: 600;
}

.subtab.active {
  background: var(--accent);
  color: #1a1204;
  border-color: var(--accent);
}

.pocket-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pocket-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pocket-num {
  font-weight: 700;
  min-width: 32px;
}

.pocket-title { flex: 1; }
.pocket-title .theme { color: var(--text-dim); font-size: 0.85rem; }

.toggle-btn {
  border: none;
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-btn.read { background: var(--read); color: #fff; }
.toggle-btn.unread { background: var(--unread); color: #08210f; opacity: 0.5; }

.row-actions button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  min-width: 36px;
  min-height: 40px;
  padding: 4px 6px;
}

/* Quick check */
.qc-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.qc-form select, .qc-form input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

.qc-result {
  margin-top: 20px;
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
}

.qc-result.read { background: var(--read); color: #fff; }
.qc-result.unread { background: var(--unread); color: #08210f; }
.qc-result .qc-sub { display: block; font-size: 0.9rem; font-weight: 500; margin-top: 8px; opacity: 0.85; }

.empty-hint {
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
  font-size: 0.9rem;
}

.app-status {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 100;
  width: min(calc(100% - 32px), 560px);
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.app-status.error { border-color: var(--read); }
.app-status.success { border-color: var(--unread); }
