/* Drunk-O-Matic — basisstijl, mobile-first */
:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #38bdf8;
  --modal-overlay: rgba(0, 0, 0, 0.6);
  --radius: 14px;
  --pad: 14px;
}

/* Licht thema — expliciete keuze */
[data-theme="light"] {
  --bg: #f8fafc;
  --bg-2: #ffffff;
  --bg-3: #e2e8f0;
  --fg: #0f172a;
  --muted: #64748b;
  --accent: #d97706;
  --accent-2: #b45309;
  --green: #16a34a;
  --red: #dc2626;
  --blue: #0284c7;
  --modal-overlay: rgba(15, 23, 42, 0.45);
}

/* Auto: volg systeemvoorkeur */
@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg: #f8fafc;
    --bg-2: #ffffff;
    --bg-3: #e2e8f0;
    --fg: #0f172a;
    --muted: #64748b;
    --accent: #d97706;
    --accent-2: #b45309;
    --green: #16a34a;
    --red: #dc2626;
    --blue: #0284c7;
    --modal-overlay: rgba(15, 23, 42, 0.45);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.2rem; letter-spacing: 0.5px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: var(--bg-2);
  overflow-x: auto;
  position: sticky; top: 52px; z-index: 4;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--bg-3);
  color: var(--fg);
}

main { padding: 16px; padding-bottom: 80px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Dashboard */
.bac-display {
  text-align: center;
  padding: 24px 0 8px;
}
.bac-value {
  font-size: 3.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  line-height: 1;
}
.bac-phase {
  margin-top: 6px;
  font-size: 1.05rem;
  color: var(--fg);
}
.bac-meta { color: var(--muted); margin-top: 4px; font-size: 0.85rem; }

#bacChart {
  width: 100%;
  max-width: 100%;
  height: 220px;
  background: var(--bg-2);
  border-radius: var(--radius);
  margin-top: 16px;
}
.legend {
  display: flex; gap: 14px; justify-content: center;
  font-size: 0.8rem; color: var(--muted); margin-top: 6px;
}
.legend i.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; margin-right: 4px;
}
.legend i.dot.past { background: var(--accent); }
.legend i.dot.future { background: var(--blue); }

.quick-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 16px;
}
.quick-stats .stat {
  background: var(--bg-2); border-radius: var(--radius); padding: 12px;
}
.quick-stats .stat .label { color: var(--muted); font-size: 0.75rem; }
.quick-stats .stat .value { font-size: 1.1rem; font-weight: 600; }

/* Log */
h2 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 10px; }
.drink-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.drink-grid button {
  background: var(--bg-2); border: 1px solid var(--bg-3);
  color: var(--fg); border-radius: var(--radius);
  padding: 12px; text-align: left; cursor: pointer;
}
.drink-grid button:active { transform: scale(0.97); }
.drink-grid .name { font-weight: 600; }
.drink-grid .meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }

.custom-drink { margin-top: 14px; background: var(--bg-2); border-radius: var(--radius); padding: 10px 14px; }
.custom-drink .row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 8px; }
.custom-drink input { width: 100%; }

.drink-log { list-style: none; padding: 0; margin: 0; }
.drink-log li {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-2); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px;
}
.drink-log .time { color: var(--muted); font-size: 0.8rem; }
.drink-log button.del { background: transparent; color: var(--red); border: 0; cursor: pointer; }
.drink-log li.editable { cursor: pointer; transition: background .15s; }
.drink-log li.editable:hover { background: var(--bg-3); }
.drink-log li .row-text { flex: 1; }
.drink-log li .session-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.quick-time-shifts {
  display: flex; gap: 4px; flex-wrap: wrap; align-items: center;
  margin-top: 8px;
}
.quick-time-shifts span { color: var(--muted); font-size: 0.85rem; margin-right: 4px; }
.quick-time-shifts button { padding: 6px 10px; font-size: 0.85rem; }

/* Inputs */
label {
  display: block; font-size: 0.85rem; color: var(--muted);
  margin: 8px 0 2px;
}
input, select {
  width: 100%;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--bg-3); border-radius: 10px;
  padding: 10px; font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); }

button {
  background: var(--accent); color: #1a1300; border: 0;
  padding: 10px 14px; border-radius: 10px; font-weight: 600; cursor: pointer;
}
button.ghost { background: transparent; color: var(--fg); }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
button.primary { background: var(--green); color: #06210f; }

/* Titratie modes */
.mode-switch { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.mode {
  flex: 1; min-width: 110px;
  background: var(--bg-2); color: var(--muted);
  font-weight: 500; padding: 8px 10px;
}
.mode.active { background: var(--accent); color: #1a1300; }
.mode-panel { display: none; background: var(--bg-2); padding: 14px; border-radius: var(--radius); }
.mode-panel.active { display: block; }
.result {
  margin-top: 14px; padding: 12px; background: var(--bg-3);
  border-radius: 10px; font-size: 0.95rem; line-height: 1.4;
}

/* Universele utility — werkt op elk element, niet alleen modals */
.hidden { display: none !important; }

/* Modal */
.modal { position: fixed; inset: 0; background: var(--modal-overlay, rgba(0,0,0,0.6)); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg-2); border-radius: var(--radius); padding: 18px; width: min(440px, 92vw); max-height: 92vh; overflow-y: auto; }
.modal-card .row { display: flex; gap: 8px; margin-top: 14px; }
.modal-divider { border: 0; border-top: 1px solid var(--bg-3); margin: 22px 0 10px; }
.modal-section-title { margin: 0 0 8px; font-size: 1rem; font-weight: 600; color: var(--fg); text-transform: none; letter-spacing: 0; }

/* Klein bolletje op de profiel-knop wanneer in een groep verbonden */
#openProfile { position: relative; }
#openProfile.in-group::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 0 2px var(--bg-2);
}

/* Kalibratie */
.hint { color: var(--muted); font-size: 0.85rem; line-height: 1.4; background: var(--bg-2); padding: 10px 14px; border-radius: var(--radius); border-left: 3px solid var(--accent); }
.cal-input { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.cal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.cal-toggle { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--fg); font-size: 0.9rem; }
.cal-toggle input { width: auto; }
.result.hidden { display: none; }
.fit-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 8px 0; }
.fit-row .stat { background: var(--bg-2); padding: 8px 10px; border-radius: 8px; }
.fit-row .stat .label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
.fit-row .stat .value { font-size: 1.1rem; font-weight: 600; }
.fit-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.85rem; }
.fit-table th, .fit-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--bg-3); }
.fit-table th { color: var(--muted); font-weight: 500; }
.fit-warn { color: #fbbf24; font-size: 0.85rem; margin-top: 8px; }

/* === FUN TAB === */
.fun-avatar { text-align: center; padding: 6px 0 14px; }
.fun-avatar span {
  display: inline-block;
  font-size: 4rem;
  animation: wobble var(--wobble-speed, 4s) ease-in-out infinite;
  transform-origin: 50% 90%;
}
@keyframes wobble {
  0%,100% { transform: rotate(calc(-1 * var(--wobble-deg, 0deg))); }
  50%     { transform: rotate(var(--wobble-deg, 0deg)); }
}

.fun-section {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
}
.fun-section > summary {
  cursor: pointer; font-weight: 600; font-size: 1rem; padding: 4px 0;
  display: flex; align-items: center; gap: 8px;
}
.fun-section > summary small {
  color: var(--muted); font-weight: 400; font-size: 0.8rem; margin-left: auto;
}
.fun-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; }
@media (min-width: 600px) { .fun-grid { grid-template-columns: 1fr 1fr; } }

.fun-card {
  background: var(--bg-3); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.fun-card h3 { margin: 0; font-size: 0.95rem; }
.fun-card .hint { font-size: 0.78rem; padding: 6px 8px; border-left-width: 2px; background: rgba(0,0,0,0.15); }
.fun-display {
  text-align: center; font-size: 1.4rem; font-weight: 600;
  padding: 18px 8px; background: var(--bg-2); border-radius: 8px;
  min-height: 70px; display: flex; align-items: center; justify-content: center;
  user-select: none;
}
.fun-display.armed { background: var(--green); color: #06210f; }
.fun-display.go    { background: var(--accent); color: #1a1300; font-size: 2rem; }
.fun-display.early { background: var(--red); color: #fff; }
.fun-display.word  { font-size: 2.2rem; font-weight: 800; letter-spacing: 1px; }
.fun-history {
  font-size: 0.75rem; color: var(--muted); padding: 6px 8px;
  border-top: 1px solid var(--bg-2); min-height: 1.2em;
}

.stroop-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stroop-buttons button {
  font-weight: 700; padding: 12px; border-radius: 8px; color: #0f172a;
  border: 2px solid transparent;
}
.stroop-buttons button:disabled { opacity: 0.4; }

.tap-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tap-btn {
  padding: 18px; font-size: 1.2rem; font-weight: 700;
  background: var(--bg-2); color: var(--fg);
  border: 2px solid var(--bg-3); border-radius: 10px;
}
.tap-btn:disabled { opacity: 0.5; }
.tap-btn.next { border-color: var(--accent); background: var(--accent); color: #1a1300; }

#biasChart { width: 100%; height: 180px; background: var(--bg-3); border-radius: 8px; margin-top: 10px; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.badge {
  background: var(--bg-3); border-radius: 10px; padding: 10px 8px;
  text-align: center; transition: opacity .3s, transform .3s;
}
.badge.locked { opacity: 0.25; filter: grayscale(1); }
.badge.earned { box-shadow: 0 0 0 1px var(--accent); }
.badge .icon { font-size: 1.6rem; }
.badge .label { font-size: 0.75rem; margin-top: 4px; }
.badge .when  { font-size: 0.65rem; color: var(--muted); margin-top: 2px; }

/* Groep */
.group-status { background: var(--bg-3); padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; color: var(--muted); margin: 8px 0; }
.group-cta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.group-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.group-header .name { font-weight: 600; }
.group-header .code { font-family: ui-monospace, monospace; background: var(--bg-3); padding: 4px 8px; border-radius: 6px; letter-spacing: 1px; }
.group-header button { padding: 6px 10px; font-size: 0.85rem; }

.member-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.member {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--bg-3); padding: 10px 12px; border-radius: 10px;
}
.member .avatar { font-size: 1.6rem; display: flex; flex-direction: column; align-items: center; min-width: 38px; }
.member .avatar .rank { font-size: 0.65rem; color: var(--muted); font-weight: 600; }
.member .avatar .emoji { line-height: 1; }
.avatar-img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; display: block; }
.member .avatar .avatar-img { margin-top: 2px; }
.avatar-photo-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.avatar-photo-row button { padding: 8px 12px; font-size: 0.85rem; }
.photo-preview { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px; background: var(--bg-3); border-radius: 10px; }
.photo-preview img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.photo-preview button { font-size: 0.8rem; padding: 6px 10px; }

.profile-avatar-current {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-3); padding: 10px; border-radius: 10px; margin-top: 8px;
}
.profile-avatar-current .img-wrap img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.profile-avatar-current .img-wrap span { font-size: 2rem; }
.profile-avatar-current .controls { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; justify-content: flex-end; }
.profile-avatar-current button { padding: 6px 10px; font-size: 0.85rem; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 3rem; opacity: 0.5; }
.empty-state h3 { margin: 12px 0 6px; color: var(--fg); }
.empty-state p { font-size: 0.9rem; line-height: 1.5; max-width: 320px; margin: 0 auto; }
.member .name { font-weight: 600; }
.member .meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.member .bac { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.member .bac.l0 { color: #94a3b8; }
.member .bac.l1 { color: #22c55e; }
.member .bac.l2 { color: #f59e0b; }
.member .bac.l3 { color: #ef4444; }
.member .bac.l4 { color: #a855f7; }
.member.offline { opacity: 0.45; }
.member.me { box-shadow: inset 0 0 0 1px var(--accent); }
.dot-online { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #22c55e; vertical-align: middle; margin-right: 4px; }
.dot-online.off { background: #475569; }

/* Reaction picker grid */
.reaction-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin: 12px 0;
}
.reaction-grid button {
  font-size: 2rem; padding: 14px 6px; line-height: 1;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid transparent; transition: transform .12s, border-color .12s;
  position: relative;
}
.reaction-grid.custom button { padding: 4px; }
.reaction-grid img.custom-reaction {
  width: 64px; height: 64px; object-fit: contain; display: block; margin: 0 auto;
  border-radius: 8px;
}
.reaction-grid button .del-x {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; cursor: pointer;
  border: 0; padding: 0; line-height: 1;
}
.reaction-grid button .del-x:hover { transform: scale(1.15); }
.empty-cust-hint { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 16px 8px; }
.reaction-grid button:hover, .reaction-grid button:active {
  transform: scale(1.1); border-color: var(--accent);
}

/* Reaction toast — verschilt van badge-toast */
.reaction-toast {
  position: fixed; left: 50%; top: 80px;
  transform: translateX(-50%) translateY(-30px); opacity: 0;
  background: var(--bg-2); color: var(--fg);
  padding: 12px 18px; border-radius: 14px;
  font-size: 1rem; font-weight: 500;
  border: 2px solid var(--accent);
  z-index: 60; transition: transform .35s ease-out, opacity .35s;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.reaction-toast .emoji { font-size: 1.6rem; margin-right: 4px; vertical-align: middle; }
.reaction-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.reaction-toast.sent { border-color: var(--green); }

/* Toast bij nieuwe badge */
.badge-toast {
  position: fixed; left: 50%; bottom: 20px;
  transform: translateX(-50%) translateY(80px); opacity: 0;
  background: var(--accent); color: #1a1300;
  padding: 10px 16px; border-radius: 999px; font-weight: 600;
  z-index: 60; transition: transform .4s, opacity .4s; box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.badge-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* BAC-reactieve achtergrond — ingesteld via JS via --bac-tint */
body { background: linear-gradient(160deg, var(--bg) 0%, var(--bac-tint, var(--bg)) 100%); transition: background 1.2s ease; }

footer { padding: 18px; text-align: center; color: var(--muted); font-size: 0.75rem; }
