:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1b2420;
  --muted: #6a716c;
  --faint: #9aa09b;
  --line: #e6e1d5;
  /* --brand* are set per event from its theme colour (KL.applyTheme). */
  --accent: var(--brand, #1e6b58);
  --accent-ink: var(--brand-ink, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 13%, #ffffff);
  --gold: #b48a35;
  --gold-soft: #f4ead4;
  --danger: #a8402f;
  --danger-soft: #f7e4df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 36, 32, 0.04), 0 6px 24px rgba(27, 36, 32, 0.06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --arabic: 'Amiri', 'Traditional Arabic', serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --accent: var(--brand-dark, #3fa486);
    --accent-ink: var(--brand-ink-dark, #06120e);
    --accent-soft: color-mix(in srgb, var(--accent) 20%, #121514);
    --bg: color-mix(in srgb, var(--accent) 6%, #0b0d0c);
    --surface: color-mix(in srgb, var(--accent) 8%, #121514);
    --surface-2: color-mix(in srgb, var(--accent) 10%, #161918);
    --ink: #e9ece8;
    --muted: #9ba49f;
    --faint: #6b7570;
    --line: color-mix(in srgb, var(--accent) 14%, #222726);
    --gold: #d6b062;
    --gold-soft: #3a3020;
    --danger: #e0806e;
    --danger-soft: #3a1f1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --accent: var(--brand-dark, #3fa486);
  --accent-ink: var(--brand-ink-dark, #06120e);
  --accent-soft: color-mix(in srgb, var(--accent) 20%, #121514);
  --bg: color-mix(in srgb, var(--accent) 6%, #0b0d0c);
  --surface: color-mix(in srgb, var(--accent) 8%, #121514);
  --surface-2: color-mix(in srgb, var(--accent) 10%, #161918);
  --ink: #e9ece8;
  --muted: #9ba49f;
  --faint: #6b7570;
  --line: color-mix(in srgb, var(--accent) 14%, #222726);
  --gold: #d6b062;
  --gold-soft: #3a3020;
  --danger: #e0806e;
  --danger-soft: #3a1f1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  appearance: none; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); transition: transform 0.1s, box-shadow 0.15s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--ink); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(#e11d48, #f59e0b, #16a34a, #0ea5e9, #6d28d9, #e11d48); }
.swatch.custom input { position: absolute; inset: -8px; width: 52px; height: 52px; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { appearance: none; border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.tabs button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; }
.toggle + .toggle { border-top: 1px solid var(--line); }
.toggle .t { font-weight: 600; font-size: 15px; }
.switch { position: relative; width: 46px; height: 26px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: 0.2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.theme-preview { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.theme-preview i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.15; }
h1 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
[hidden] { display: none !important; }

.wrap { max-width: 560px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1040px; }

.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand .logo { height: 32px; width: auto; display: block; flex: none; }

.invite { margin-top: 16px; }
.invite-code { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-weight: 700; font-size: 16px !important; letter-spacing: 0.06em; color: var(--ink); }

.credit { text-align: center; font-size: 13px; color: var(--faint); padding: 28px 16px 8px; }
.credit a { color: var(--muted); font-weight: 600; text-decoration: none; }
.credit a:hover { color: var(--ink); text-decoration: underline; }

.theme-toggle {
  appearance: none; cursor: pointer; flex: none;
  width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle svg { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type='text'], input[type='number'], input[type='password'], input[type='email'], input[type='date'], input[type='search'], input:not([type]), select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type='date'] {
  color-scheme: inherit;
}
:root[data-theme='dark'] input[type='date'] {
  color-scheme: dark;
}
:root[data-theme='light'] input[type='date'] {
  color-scheme: light;
}
input[type='date']::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}
input[type='date']::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.preset {
  appearance: none; font: inherit; text-align: left; cursor: pointer; color: var(--ink);
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}
.preset:hover { border-color: var(--faint); }
.preset[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); }
.preset .tag { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); }
.preset b { display: block; font-size: 15px; margin-top: 2px; }
.preset span { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-msg { text-align: center; padding: 48px 0; color: var(--muted); }
.field + .field { margin-top: 14px; }
.hint { font-size: 12px; color: var(--faint); margin-top: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 11px 18px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.06s, filter 0.15s, background 0.15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; padding: 14px 18px; font-size: 16px; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.pill.live::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.8s infinite;
}
.pill.paused { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.pill.done { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; position: relative; }
.progress > i { position: absolute; inset: 0 auto 0 0; display: block; transition: width 0.6s ease; }
.progress > i.assigned { background: var(--accent-soft); }
.progress > i.done { background: var(--accent); }

.copy {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px;
}
.copy code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.copy .btn { flex: none; }

@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
}
