/* Reusable components */

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--btn-bg); color: var(--text);
  font-weight: 600; font-size: 0.93rem; text-decoration: none; white-space: nowrap;
  transition: transform 0.15s var(--ease), background 0.2s var(--ease), box-shadow 0.25s var(--ease), border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px) scale(0.985); }
.btn[disabled], .btn[aria-disabled='true'] { opacity: 0.5; pointer-events: none; }
.btn-primary {
  border-color: transparent; color: var(--on-gold);
  background: linear-gradient(135deg, var(--gold-hi) 0%, var(--gold) 45%, var(--ember) 130%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.45) inset, 0 8px 24px -10px rgba(242, 160, 50, 0.75);
}
.btn-primary:hover { background: linear-gradient(135deg, #ffe09a 0%, var(--gold-hi) 40%, var(--gold) 110%); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 12px 30px -10px rgba(242, 160, 50, 0.9); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: var(--bad-soft); }
.btn-danger:hover { background: color-mix(in srgb, var(--bad) 22%, transparent); }
.btn-steel { color: var(--steel); background: var(--steel-soft); border-color: color-mix(in srgb, var(--steel) 30%, transparent); }
.btn-lg { min-height: 52px; padding: 0 24px; font-size: 1rem; border-radius: 14px; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.84rem; border-radius: 10px; }
.btn-sm svg { width: 16px; height: 16px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 11px; border: 1px solid transparent; background: transparent; color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); background: var(--bad-soft); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- surfaces ---------- */
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
}
.panel-pad { padding: clamp(18px, 2.4vw, 28px); }
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.card-pad { padding: 18px 20px; }
.section { margin-top: 34px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-family: var(--font-display); font-size: var(--fs-xl); }
.section-head a { font-size: var(--fs-sm); text-decoration: none; white-space: nowrap; }
.divider { height: 1px; background: var(--line); margin: 18px 0; border: 0; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field + .field { margin-top: 16px; }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.hint { font-size: var(--fs-xs); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface-solid) 70%, transparent);
  color: var(--text); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.select {
  appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.5l5 5 5-5' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center;
}
.select option { background: var(--surface-solid); color: var(--text); }
.input-wrap { position: relative; }
.input-wrap > svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); pointer-events: none; }
.input-wrap > .input { padding-left: 40px; }
.input-wrap > .icon-btn { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); }

/* segmented control */
.seg {
  display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px;
  border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
}
.seg button {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-2); font-weight: 600; font-size: 0.88rem;
  transition: background 0.2s var(--ease), color 0.2s, box-shadow 0.2s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked='true'], .seg button[aria-selected='true'] {
  background: var(--surface-solid); color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 12px -4px rgba(0, 0, 0, 0.4);
}
.seg button[aria-checked='true'] .dotc { background: var(--gold); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

/* chips (multi-select) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text-2);
  font-size: 0.88rem; font-weight: 500;
  transition: all 0.18s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip[aria-pressed='true'] {
  color: var(--text); border-color: color-mix(in srgb, var(--chip-c, var(--gold)) 70%, transparent);
  background: color-mix(in srgb, var(--chip-c, var(--gold)) 16%, transparent);
}
.chip .tick { width: 15px; height: 15px; display: none; color: var(--chip-c, var(--gold)); }
.chip[aria-pressed='true'] .tick { display: block; }

/* switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; }
.switch-row .txt { display: flex; flex-direction: column; }
.switch {
  position: relative; width: 46px; height: 27px; flex: none; border-radius: 99px; border: 0;
  background: var(--surface-hover); transition: background 0.25s var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%;
  background: var(--text); transition: transform 0.3s var(--ease-spring);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.switch[aria-checked='true'] { background: var(--gold); }
.switch[aria-checked='true']::after { transform: translateX(19px); background: #fff; }
.switch:disabled { opacity: 0.4; cursor: not-allowed; }
.switch-row.is-disabled strong { opacity: 0.55; }

/* range */
.range-row { display: flex; align-items: center; gap: 16px; }
.range-val {
  min-width: 64px; text-align: center; padding: 6px 10px; border-radius: 10px;
  background: var(--gold-soft); color: var(--gold-text); font-weight: 700; font-variant-numeric: tabular-nums;
}
input[type='range'] { -webkit-appearance: none; appearance: none; flex: 1; height: 28px; background: transparent; cursor: pointer; }
input[type='range']::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--gold) 0 var(--fill, 20%), var(--surface-hover) var(--fill, 20%) 100%);
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 6px; background: var(--surface-hover); }
input[type='range']::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--gold); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: #fff; border: 4px solid var(--gold); box-shadow: 0 2px 10px rgba(242, 181, 68, 0.5);
}
input[type='range']::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 4px solid var(--gold); }

/* badge / pill */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge svg { width: 13px; height: 13px; }
.badge.gold { background: var(--gold-soft); color: var(--gold-text); }
.badge.steel { background: var(--steel-soft); color: var(--steel); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.diff-easy { color: var(--ok); background: var(--ok-soft); }
.diff-medium { color: var(--steel); background: var(--steel-soft); }
.diff-hard { color: var(--bad); background: var(--bad-soft); }

/* progress bar */
.bar { height: 8px; border-radius: 8px; background: var(--surface-hover); overflow: hidden; }
.bar > i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--gold-hi));
  transition: width 0.7s var(--ease);
}
.bar.thin { height: 5px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  position: relative; padding: 10px 14px; border: 0; background: none; color: var(--text-2); font-weight: 600; white-space: nowrap;
}
.tabs button[aria-selected='true'] { color: var(--text); }
.tabs button[aria-selected='true']::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--gold);
}
.tabs .count { color: var(--text-3); font-weight: 500; margin-left: 4px; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; z-index: 100; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 11px;
  max-width: min(420px, calc(100vw - 32px)); padding: 12px 14px 12px 14px;
  border-radius: 14px; border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
  backdrop-filter: blur(14px); box-shadow: var(--shadow-2);
  font-size: 0.92rem; font-weight: 500;
  animation: toast-in 0.4s var(--ease-spring) both;
}
.toast.out { animation: toast-out 0.25s var(--ease) both; }
.toast .ti { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 8px; }
.toast .ti svg { width: 16px; height: 16px; }
.toast.success .ti { background: var(--ok-soft); color: var(--ok); }
.toast.error .ti { background: var(--bad-soft); color: var(--bad); }
.toast.info .ti { background: var(--gold-soft); color: var(--gold-text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@media (max-width: 900px) {
  .toasts { left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); align-items: stretch; }
  body.focus-mode .toasts { bottom: 20px; }
  /* Phones show dialogs as bottom sheets: put toasts at the top while one is open so they don't cover its text. */
  body:has(.modal-backdrop) .toasts { top: calc(16px + env(safe-area-inset-top)); bottom: auto; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px;
  background: var(--scrim); backdrop-filter: blur(6px);
  animation: fade-in 0.2s var(--ease) both;
}
.modal {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  border-radius: var(--r-xl); border: 1px solid var(--line-strong);
  background: var(--surface-solid); box-shadow: var(--shadow-2);
  animation: modal-in 0.35s var(--ease-spring) both;
}
.modal.wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-head h2 { font-family: var(--font-display); font-size: 1.45rem; }
.modal-body { padding: 16px 22px 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; flex-wrap: wrap; }
.modal-backdrop.closing { animation: fade-out 0.18s var(--ease) both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }
@media (max-width: 560px) {
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { border-radius: 24px 24px 0 0; max-height: 92dvh; animation-name: sheet-in; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
}

/* ---------- dropdown menu ---------- */
.menu-wrap { position: relative; display: inline-block; }
.menu {
  position: absolute; z-index: 50; right: 0; top: calc(100% + 8px); min-width: 250px;
  padding: 6px; border-radius: 16px; border: 1px solid var(--line-strong);
  background: var(--surface-solid); box-shadow: var(--shadow-2);
  animation: modal-in 0.22s var(--ease) both;
}
.menu.menu-floating {
  position: fixed; z-index: 150; right: auto; top: 0; left: 0;
  max-height: calc(100dvh - 16px); overflow-y: auto; overscroll-behavior: contain;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); text-align: left; text-decoration: none; font-size: 0.92rem;
}
.menu button:hover, .menu a:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu svg { width: 17px; height: 17px; color: var(--text-3); flex: none; }
.menu .menu-sep { height: 1px; background: var(--line); margin: 5px 6px; }
.menu .mi-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- banner ---------- */
.banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px 14px 18px; border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  background: linear-gradient(100deg, var(--gold-soft), transparent 80%), var(--surface);
  backdrop-filter: blur(12px);
}
.banner .bi { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: var(--gold-soft); color: var(--gold-text); flex: none; }
.banner .bi svg { width: 19px; height: 19px; }
.banner .bt { flex: 1; min-width: 200px; }
.banner .bt strong { display: block; }
.banner .bt span { color: var(--text-2); font-size: var(--fs-sm); }

/* ---------- skeleton ---------- */
.skel {
  border-radius: 12px;
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-hover) 50%, var(--surface-2) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }
.skel-line { height: 14px; margin: 8px 0; }

/* ---------- empty state ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px;
  padding: clamp(32px, 6vw, 56px) 20px;
  border: 1px dashed var(--line-strong); border-radius: var(--r-xl);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}
.empty .ei {
  width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 6px;
  border-radius: 20px; background: var(--gold-soft); color: var(--gold-text);
}
.empty .ei svg { width: 30px; height: 30px; }
.empty h3 { font-family: var(--font-display); font-size: 1.45rem; }
.empty p { color: var(--text-2); max-width: 46ch; }
.empty .btn-row { margin-top: 10px; justify-content: center; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th { text-align: left; font-weight: 600; color: var(--text-3); font-size: var(--fs-xs); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { cursor: pointer; transition: background 0.15s; }
.table tbody tr:hover, .table tbody tr:focus-visible { background: var(--surface-2); outline: none; }
.table tbody tr:last-child td { border-bottom: 0; }

/* score pill colour by value */
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score.hi { color: var(--ok); }
.score.mid { color: var(--gold-text); }
.score.lo { color: var(--bad); }

/* ring (svg progress) */
.ring { position: relative; display: grid; place-items: center; }
.ring svg { transform: rotate(-90deg); overflow: visible; }
.ring .track { stroke: var(--ring-track); }
.ring .fill { stroke: url(#forge-grad); stroke-linecap: round; transition: stroke-dashoffset 0.9s var(--ease); filter: drop-shadow(0 0 8px rgba(242, 160, 50, 0.45)); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }

.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  font-size: 0.72rem; font-weight: 700; color: var(--text-3); background: var(--surface-2);
}

/* spinner */
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--gold); animation: rot 0.8s linear infinite; flex: none; }
@keyframes rot { to { transform: rotate(360deg); } }

.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; background: var(--c);
  box-shadow: 0 0 0 2px var(--surface-solid) inset; transition: transform 0.15s var(--ease-spring);
}
.swatch:hover { transform: scale(1.1); }
.swatch[aria-checked='true'] { border-color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.emoji-grid button {
  height: 42px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.25rem;
  transition: transform 0.15s var(--ease-spring), border-color 0.15s;
}
.emoji-grid button:hover { transform: scale(1.08); }
.emoji-grid button[aria-checked='true'] { border-color: var(--gold); background: var(--gold-soft); }
