/* Reusable components */

/* Page header ------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-4); justify-content: space-between; }
.page-head > div:first-child { flex: 1 1 380px; min-width: 0; }
.eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); margin-bottom: var(--sp-1); }
.lede { color: var(--text-2); margin-top: var(--sp-2); max-width: 62ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }

/* Buttons ----------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--control-h); padding: 0 var(--sp-4);
  border: 1px solid var(--btn-bd); border-radius: var(--r-pill);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 700; font-size: var(--fs-sm); text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast), border-color var(--dur-fast);
  box-shadow: var(--shadow-1);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; box-shadow: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bd: transparent; box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.16), var(--shadow-1); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; color: var(--primary); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); }
.btn-xp { --btn-bg: var(--xp); --btn-fg: #2b1d00; --btn-bd: transparent; box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.15); }
.btn-xp:hover:not(:disabled) { background: var(--xp-strong); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: transparent; }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 85%, black); }
:root[data-theme="dark"] .btn-danger { --btn-fg: #2a0b05; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { min-height: 2rem; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-lg { min-height: 3rem; padding: 0 var(--sp-5); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.file-btn { cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--control-h); height: var(--control-h); border-radius: var(--r-pill);
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-lg { width: 3rem; height: 3rem; border-color: var(--border-strong); background: var(--surface); }
.icon-btn-on-color { color: #fff; background: rgb(0 0 0 / 0.14); }
.icon-btn-on-color:hover { background: rgb(0 0 0 / 0.28); color: #fff; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* Cards ------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; }
.card-pad { padding: var(--sp-5); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-head h2 { font-size: var(--fs-lg); }
@media (max-width: 560px) { .card-pad { padding: var(--sp-4); } }

/* Chips, badges, tags ---------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px 2px 8px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  color: var(--text); font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-quiz { background: var(--info-soft); color: var(--info); }
.badge-test { background: var(--danger-soft); color: var(--danger); }
.badge-project { background: color-mix(in srgb, var(--c-iris) 16%, var(--surface)); color: var(--c-iris); }
.badge-keydate { background: var(--xp-soft); color: var(--xp-ink); }
.badge-study { background: var(--primary-soft); color: var(--primary-ink); }
.badge-now { background: var(--primary); color: var(--on-primary); }
.tag { font-size: var(--fs-xs); color: var(--text-2); font-weight: 700; }
.xp-tag { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--r-pill); background: var(--xp-soft); color: var(--xp-ink); font-size: var(--fs-xs); font-weight: 700; white-space: nowrap; }
.xp-tag.is-earned { background: var(--success-soft); color: var(--success); }
.xp-pill, .score-pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: var(--r-pill); background: var(--xp-soft); color: var(--xp-ink); font-weight: 700; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.score-pill.tone-ember { background: color-mix(in srgb, var(--c-ember) 16%, var(--surface)); color: var(--c-ember); }
.due { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--text-2); font-weight: 700; }
.due.is-soon { color: var(--warning); }
.due.is-overdue { color: var(--danger); }

.avatar { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 24px; flex: none; }

/* Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.label { font-size: var(--fs-sm); font-weight: 700; color: var(--text); }
.field-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.field-row > .field { flex: 1 1 200px; }
.input {
  width: 100%; min-height: var(--control-h); padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
textarea.input { padding: var(--sp-3); resize: vertical; line-height: var(--lh-body); }
.input:hover { border-color: var(--text-3); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.input::placeholder { color: var(--text-3); }
.input-sm { min-height: 2.125rem; width: auto; font-size: var(--fs-sm); padding: 0 var(--sp-2); }
.input-lg { min-height: 3rem; font-size: var(--fs-lg); }
select.input { padding-right: var(--sp-5); }
.textarea-code { font-family: var(--font-mono); font-size: var(--fs-sm); }
.textarea-note { min-height: 280px; }
.form-error { color: var(--danger); font-weight: 700; font-size: var(--fs-sm); }
.hint { display: block; }
.inline-field { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* Segmented controls (also used as radio groups) */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--r-pill); border: 1px solid var(--border); max-width: 100%; overflow-x: auto; }
.seg-wrap { flex-wrap: wrap; border-radius: var(--r-md); }
.seg-btn, .seg-link, .seg-opt span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 2rem; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-2);
  font-weight: 700; font-size: var(--fs-sm); text-decoration: none; white-space: nowrap; cursor: pointer;
}
.seg-btn:hover, .seg-link:hover, .seg-opt:hover span { color: var(--text); }
.seg-btn[aria-pressed="true"], .seg-link[aria-selected="true"], .seg-opt input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.seg-opt small { color: var(--xp-ink); font-weight: 700; }

.swatches, .emoji-picker { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.swatch { position: relative; width: 36px; height: 36px; border-radius: 50%; background: var(--c); cursor: pointer; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.1); }
.swatch input { position: absolute; opacity: 0; }
.swatch:has(input:checked) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.swatch:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 5px; }
.emoji-opt { position: relative; cursor: pointer; }
.emoji-opt input { position: absolute; opacity: 0; }
.emoji-opt span { display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--r-md); font-size: 22px; border: 1px solid var(--border); background: var(--surface); transition: transform var(--dur-fast) var(--ease-bounce); }
.emoji-picker-lg .emoji-opt span { width: 52px; height: 52px; font-size: 28px; }
.emoji-opt:hover span { transform: scale(1.06); }
.emoji-opt input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary); }
.emoji-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.search { position: relative; flex: 1 1 240px; min-width: 0; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 38px; border-radius: var(--r-pill); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.toolbar-end { margin-left: auto; }

/* Progress ---------------------------------------------------------- */
.progress { position: relative; height: 10px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; width: 100%; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width var(--dur-slow) var(--ease); }
.progress-xp > span { background: linear-gradient(90deg, var(--xp), var(--xp-strong)); }
.progress-success > span { background: var(--success); }
.progress-ember > span { background: var(--c-ember); transition: none; }
.progress-thin { height: 6px; }

/* Task rows --------------------------------------------------------- */
.task-list { display: flex; flex-direction: column; }
.task-list.card { padding: var(--sp-1) 0; }
.task { position: relative; display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.card:not(.task-list) .task { padding-left: 0; padding-right: 0; }
.task::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--c); }
.card:not(.task-list) .task::before { display: none; }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-title { font-weight: 700; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.task-actions { display: flex; align-items: center; gap: 2px; }
.task.is-done .task-title { text-decoration: line-through; color: var(--text-3); }
.task.is-done .chip, .task.is-done .badge { opacity: 0.6; }
@media (max-width: 560px) {
  .task { flex-wrap: wrap; }
  .task-main { flex-basis: calc(100% - 60px); }
  .task .xp-tag { order: 3; margin-left: 48px; }
  .task-actions { order: 4; margin-left: auto; }
}

.check {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--surface); color: transparent;
  transition: all var(--dur-fast) var(--ease);
}
.check:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.check[aria-pressed="true"] { background: var(--success); border-color: var(--success); color: #fff; animation: pop var(--dur) var(--ease-bounce); }
@keyframes pop { 50% { transform: scale(1.2); } }

/* Empty states ------------------------------------------------------ */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-6) var(--sp-4); color: var(--text-2); }
.empty-emoji { font-size: 40px; line-height: 1; }
.empty h3 { color: var(--text); font-size: var(--fs-md); }
.empty p { max-width: 42ch; font-size: var(--fs-sm); }
.empty .btn { margin-top: var(--sp-2); }

.notice { display: flex; gap: var(--sp-2); align-items: center; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--info-soft); color: var(--info); font-size: var(--fs-sm); font-weight: 700; }

/* Toasts ------------------------------------------------------------ */
.toasts { position: fixed; z-index: 200; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: var(--sp-2); align-items: flex-end; pointer-events: none; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-3);
  font-weight: 700; font-size: var(--fs-sm); max-width: 420px;
  opacity: 0; transform: translateY(12px) scale(0.98); transition: opacity var(--dur), transform var(--dur) var(--ease-bounce);
}
.toast.is-in { opacity: 1; transform: none; }
.toast-xp { background: var(--xp); color: #2b1d00; }
.toast-error { background: var(--danger); color: #fff; }
.toast-emoji { font-size: 20px; }
@media (max-width: 560px) { .toasts { left: 16px; right: 16px; bottom: 16px; align-items: stretch; } .toast { max-width: none; } }

/* Modals ------------------------------------------------------------ */
.modal { padding: 0; border: 0; background: transparent; color: var(--text); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: visible; }
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal-lg { width: min(720px, calc(100vw - 32px)); }
.modal-xl { width: min(960px, calc(100vw - 32px)); }
.modal::backdrop { background: rgb(15 18 17 / 0.5); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in var(--dur) var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 48px); background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-3); overflow: hidden; }
.modal-form { display: contents; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-4) var(--sp-2) var(--sp-5); }
.modal-head h2 { font-size: var(--fs-lg); overflow-wrap: anywhere; }
.modal-body { padding: var(--sp-2) var(--sp-5) var(--sp-5); overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); }

/* Confetti ---------------------------------------------------------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti i { position: absolute; top: -12px; left: var(--x); width: 9px; height: 14px; border-radius: 2px; animation: fall var(--d) var(--delay) cubic-bezier(0.25, 0.6, 0.4, 1) forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--r)); opacity: 0.2; } }
