:root {
  --bg: #fbf6f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #eadde0;
  --field: #f4eef0;
  --accent: #ff2d55;
  --accent-2: #ff7a90;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 45, 85, .1);
  --ok: #34c759;
  --danger: #ff3b30;
  --shadow: 0 1px 2px rgba(60, 20, 30, .05), 0 8px 24px -12px rgba(60, 20, 30, .12);
  --radius: 18px;
  --hold: min(64vw, 260px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0a0b;
    --card: #19151a;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #2c2429;
    --field: #241e23;
    --accent-soft: rgba(255, 45, 85, .16);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0a0b; --card: #19151a; --text: #f5f5f7; --muted: #a1a1a6; --line: #2c2429; --field: #241e23;
  --accent-soft: rgba(255, 45, 85, .16); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 14px 0 8px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
b { font-weight: 600; }

#app {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
}
.view { flex: 1; display: flex; flex-direction: column; gap: 18px; padding-top: 4vh; }
.view.center { justify-content: center; align-items: center; text-align: center; padding-top: 0; }
.view.main { padding-top: 0; gap: 14px; }

.intro { text-align: center; }
.logo { border-radius: 22%; box-shadow: 0 10px 30px -10px rgba(255, 45, 85, .5); }
.lead { color: var(--muted); margin: 0 auto; max-width: 30ch; }
.fine { color: var(--muted); font-size: 14px; margin: 0; }
.fine.center, .center { text-align: center; }
.big-ic { width: 88px; height: 88px; margin: 0 auto; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.big-ic .ic { width: 40px; height: 40px; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.inline { width: 18px; height: 18px; vertical-align: -3px; color: #0a84ff; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row .field { flex: 1; min-width: 0; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

.field {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--field);
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 14px 16px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.field:focus { border-color: var(--accent); background: var(--card); }
.code-input { text-transform: uppercase; letter-spacing: .18em; font-family: ui-monospace, "SF Mono", Menlo, monospace; text-align: center; }
.row .code-input { text-align: left; }

.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 14px;
  padding: 15px 18px;
  background: var(--field);
  color: var(--text);
  cursor: pointer;
  transition: transform .12s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 10px 14px; font-size: 15px; border-radius: 12px; flex: none; }
.btn.danger { width: 100%; background: transparent; color: var(--danger); border: 1px solid var(--line); }

.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card); color: var(--text); display: grid; place-items: center; box-shadow: var(--shadow); cursor: pointer; flex: none; }

/* Installatiestappen */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; gap: 14px; align-items: center; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 16px; }
.num { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; display: grid; place-items: center; flex: none; }

/* Code */
.code-card { padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 30px; font-weight: 700; letter-spacing: .14em; }
.group .code { font-size: 22px; }
.waiting { display: flex; align-items: center; justify-content: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Hoofdscherm */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.to { display: flex; align-items: center; gap: 10px; min-width: 0; }
.to-label { color: var(--muted); font-size: 15px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { font: inherit; font-size: 15px; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 8px 14px; white-space: nowrap; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .off { font-weight: 400; opacity: .75; }

.composer { padding: 12px 14px 10px; }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font: inherit; font-size: 18px; line-height: 1.35; padding: 2px 0; max-height: 7.5em; }
.composer textarea::placeholder { color: var(--muted); opacity: .8; }
.composer-foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; }

.hold-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 2vh 0 1vh; }
.hold-stage { position: relative; width: calc(var(--hold) + 34px); height: calc(var(--hold) + 34px); display: grid; place-items: center; }
.hold-stage::before {
  content: ""; position: absolute; inset: 14%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 45, 85, .35), transparent 70%);
  filter: blur(24px); animation: breathe 3.2s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.12); opacity: .6; } }

.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.ring circle { fill: none; stroke-width: 3.2; }
.ring-track { stroke: var(--line); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 351.86; stroke-dashoffset: 351.86; transition: stroke-dashoffset .45s cubic-bezier(.2, .8, .2, 1); }
.holding .ring-fill { transition: none; }

.hold {
  position: relative;
  width: var(--hold); height: var(--hold);
  border-radius: 50%;
  border: 0;
  color: #fff;
  background: radial-gradient(circle at 32% 26%, #ff8fa2 0%, #ff4b6e 42%, #ef1d4c 78%, #d4123f 100%);
  box-shadow: 0 22px 50px -14px rgba(255, 45, 85, .65), inset 0 -10px 24px rgba(120, 0, 30, .22), inset 0 8px 18px rgba(255, 255, 255, .28);
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  transition: transform .35s cubic-bezier(.2, .9, .3, 1.3), filter .2s;
}
.holding .hold { transform: scale(.94); transition: transform 3s cubic-bezier(.3, .6, .3, 1); }
.hold:disabled { filter: grayscale(.6) opacity(.6); }
.hold-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; opacity: 0; transform: scale(.8); transition: opacity .2s, transform .25s; pointer-events: none; }
.hold-label { font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.heart { width: 34%; height: 34%; fill: #fff; filter: drop-shadow(0 4px 8px rgba(120, 0, 30, .25)); }
.check { width: 30%; height: 30%; stroke-width: 2.4; }
#countdown { font-size: calc(var(--hold) * .36); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }

.hold-stage[data-state="idle"] .face-idle,
.hold-stage[data-state="holding"] .face-count,
.hold-stage[data-state="busy"] .face-busy,
.hold-stage[data-state="done"] .face-done { opacity: 1; transform: none; }
.hold-stage[data-state="idle"] .heart { animation: beat 3.2s ease-in-out infinite; }
@keyframes beat { 0%, 70%, 100% { transform: scale(1); } 78% { transform: scale(1.12); } 86% { transform: scale(.98); } 92% { transform: scale(1.07); } }
.hold-stage[data-state="done"] .hold { animation: pop .5s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { 40% { transform: scale(1.06); } }

.hint { color: var(--muted); font-size: 15px; margin: 0; min-height: 1.4em; text-align: center; transition: color .2s; }
.hint.warn { color: var(--accent); }
.hint.ok { color: var(--ok); }

/* Geschiedenis */
.history { margin-top: 6px; }
.history h2 { display: flex; justify-content: space-between; align-items: baseline; }
.history h2 .fine { font-weight: 400; font-size: 13px; }
#history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; }
.bubble { padding: 9px 14px; border-radius: 18px; font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.in .bubble { background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.meta { font-size: 12px; color: var(--muted); padding: 0 4px; }
.empty { text-align: center; padding: 8px 0; }

/* Instellingen */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 6px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { font-size: 20px; margin: 0; }
.sheet-head .icon-btn { box-shadow: none; background: var(--field); width: 34px; height: 34px; }
.sheet-head .icon-btn .ic { width: 18px; height: 18px; }
.group { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.group .field { padding: 11px 14px; font-size: 16px; }
.friends { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.friends li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.friends .sub { display: block; font-size: 13px; color: var(--muted); }
.link-btn { font: inherit; font-size: 15px; border: 0; background: none; color: var(--danger); cursor: pointer; padding: 6px 0; }

/* Toast en spinner */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1d1d1f; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px;
  max-width: calc(100vw - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  transition: opacity .2s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.light { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; width: 22%; height: 22%; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition-duration: .01ms !important; }
}
@media (max-height: 700px) {
  :root { --hold: min(54vw, 210px); }
  .view { padding-top: 2vh; }
}
