:root {
  --bg: #fef7ec;
  --card: #ffffff;
  --ink: #3b2f1e;
  --muted: #9a8a70;
  --amber: #f59e0b;
  --amber-dark: #d97706;
  --green: #16a34a;
  --red: #dc2626;
  --line: #f0e4d0;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(120, 85, 20, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1712;
    --card: #2a231a;
    --ink: #f3e9d8;
    --muted: #a08f75;
    --line: #3b3122;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* PIN screen */
.pin-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
  width: min(340px, 100%);
}
.pin-emoji { font-size: 48px; }
.pin-card h1 { margin: 8px 0 4px; }
.pin-card p { color: var(--muted); margin: 4px 0 16px; }
.pin-card input {
  width: 100%;
  font-size: 24px;
  text-align: center;
  letter-spacing: 6px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  margin-bottom: 12px;
}
.pin-error { color: var(--red); font-size: 14px; }

/* Layout */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}
.header h1 { font-size: 22px; margin: 0; }

.who-picker { display: flex; gap: 6px; }
.who-chip {
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.who-chip.active {
  border-color: var(--amber);
  background: var(--amber);
  color: #fff;
}

main { flex: 1; padding: 8px 16px; }
h2 { font-size: 16px; color: var(--muted); margin: 18px 0 10px; }

/* Balance card */
.balance-card {
  background: linear-gradient(135deg, var(--amber), var(--amber-dark));
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  text-align: center;
}
.balance-points { font-size: 40px; font-weight: 800; }
.balance-points span { font-variant-numeric: tabular-nums; }
.balance-euros { font-size: 20px; opacity: 0.95; margin: 4px 0 8px; }
.balance-bonus {
  font-size: 13px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--amber); color: #fff; }
.btn-payout { background: var(--green); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--amber-dark);
  border: 2px dashed var(--line);
}

/* Chore grid */
.chore-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.chore-btn {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.1s;
}
.chore-btn:active { transform: scale(0.95); }
.chore-btn .emoji { font-size: 30px; display: block; }
.chore-btn .name { font-size: 14px; font-weight: 600; display: block; margin: 6px 0 2px; }
.chore-btn .pts { font-size: 13px; color: var(--amber-dark); font-weight: 700; }

/* Custom entry */
.custom-entry { margin-top: 16px; color: var(--muted); }
.custom-entry summary { cursor: pointer; font-weight: 600; }
.custom-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.custom-form input {
  flex: 1;
  min-width: 90px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
}
#custom-points { flex: 0 0 90px; }

/* History */
.history-summary { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.history-item .h-emoji { font-size: 22px; }
.history-item .h-body { flex: 1; min-width: 0; }
.history-item .h-name { font-weight: 600; font-size: 15px; }
.history-item .h-meta { color: var(--muted); font-size: 12px; }
.history-item .h-pts { font-weight: 800; font-size: 15px; white-space: nowrap; }
.history-item .h-pts.plus { color: var(--green); }
.history-item .h-pts.minus { color: var(--red); }
.h-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
}

/* Settings */
.settings-block { margin-bottom: 18px; }
.settings-block label { display: block; font-weight: 600; margin-bottom: 6px; }
.settings-block input, .settings-block textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
}
.chore-row { display: flex; gap: 6px; margin-bottom: 6px; }
.chore-row input { padding: 8px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.chore-row .ce-emoji { flex: 0 0 52px; text-align: center; }
.chore-row .ce-name { flex: 1; min-width: 0; }
.chore-row .ce-points { flex: 0 0 60px; text-align: center; }
.chore-row .ce-remove { background: none; border: none; color: var(--red); font-size: 18px; cursor: pointer; }
.settings-status { color: var(--green); font-weight: 600; min-height: 1.2em; }
#chore-add-row { margin-top: 4px; }
#settings-save { width: 100%; margin-top: 8px; }

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 6px;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tabbtn span { font-size: 11px; font-weight: 600; }
.tabbtn.active { color: var(--amber-dark); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 10;
  animation: toast-pop 0.2s ease-out;
  white-space: nowrap;
}
@keyframes toast-pop {
  from { transform: translateX(-50%) scale(0.8); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Payout dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--card);
  color: var(--ink);
  width: min(340px, 90vw);
  padding: 22px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.payout-form h2 { margin: 0 0 8px; color: var(--ink); font-size: 20px; }
.payout-form label { display: block; font-weight: 600; margin: 10px 0 6px; }
.payout-form input {
  width: 100%;
  padding: 10px;
  font-size: 18px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
}
.payout-euros { font-size: 18px; font-weight: 700; color: var(--green); }
.payout-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
