/* Reusable components: buttons, forms, cards, badges, menus, dialogs, toasts… */

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-weight: 600; line-height: 1.2;
  cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 1.1rem; height: 1.1rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 1px 2px rgb(80 70 229 / 30%); }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: #f0c4c4; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { filter: brightness(.94); }
.btn.lg { padding: .75rem 1.2rem; font-size: 1rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn.busy::before {
  content: ""; width: .9rem; height: .9rem; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}

.icon-btn {
  display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; flex: none;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--surface-2); }
.icon-btn.sm { width: 2rem; height: 2rem; }
.icon-btn.sm .icon { width: 1.1rem; height: 1.1rem; }
.icon-btn[aria-pressed="true"], .icon-btn.active { background: var(--brand-soft); border-color: #cfcbfa; color: var(--brand); }
.icon-btn[aria-expanded="true"] { background: var(--surface-2); }

.link {
  background: none; border: 0; padding: 0; font: inherit; font-weight: 600;
  color: var(--brand); cursor: pointer;
}
.link:hover { text-decoration: underline; }

.back {
  display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .9rem;
  color: var(--muted); font-weight: 600; font-size: .9rem;
}
.back:hover { color: var(--ink); text-decoration: none; }
.back .icon { width: 1rem; height: 1rem; }

/* ---- forms ---- */
.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .35rem; font-weight: 600; font-size: .9rem; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; }
.field-link { font-weight: 500; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select {
  font: inherit; font-weight: 400; font-size: 1rem; color: var(--ink);
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); transition: border-color .12s, box-shadow .12s;
}
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(80 70 229 / 18%); }
input[type=checkbox], input[type=range] { accent-color: var(--brand); }
.form-error {
  background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem;
  border-radius: var(--r-sm); font-size: .9rem;
}

/* ---- cards, badges, meters ---- */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.card-body { padding: .85rem 1rem 1rem; display: grid; gap: .25rem; }
.card-title { font-size: 1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem;
  border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge .icon { width: .9rem; height: .9rem; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.plan { background: var(--brand-soft); color: var(--brand); text-transform: capitalize; }
.badge.style-outline { background: #26232f; color: #fff; }
/* difficulty colors */
.level-easy { --level: #1f8a55; --level-soft: #e6f5ed; }
.level-medium { --level: #3f6fd8; --level-soft: #e8effc; }
.level-hard { --level: #c2620b; --level-soft: #fdf0e3; }
.level-expert { --level: #b8337a; --level-soft: #fbe9f2; }
.badge[class*="level-"] { background: var(--level-soft); color: var(--level); }

.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--ok); transition: width .25s; }

.spinner {
  display: inline-block; width: .85rem; height: .85rem; vertical-align: -.1em;
  border: 2px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner.big { width: 2rem; height: 2rem; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- notice & empty state ---- */
.notice {
  display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; margin-bottom: 1.25rem;
  border-radius: var(--r); border: 1px solid var(--line); background: var(--surface);
}
.notice > .icon { margin-top: .1rem; }
.notice.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.notice.warn > .icon { color: var(--warn); }

.empty-state {
  display: grid; justify-items: center; gap: .6rem; text-align: center;
  padding: 3.5rem 1.5rem; margin-top: .5rem;
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg); background: rgb(255 255 255 / 55%);
}
.empty-state p { max-width: 26rem; }
.empty-state .btn { margin-top: .6rem; }
.empty-icon {
  display: grid; place-items: center; width: 3.5rem; height: 3.5rem; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); margin-bottom: .3rem;
}
.empty-icon .icon { width: 1.6rem; height: 1.6rem; }

/* ---- menu ---- */
.menu {
  position: fixed; z-index: 60; min-width: 230px; padding: .35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg); animation: pop .12s ease-out;
}
.menu-item {
  display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .65rem;
  border: 0; border-radius: var(--r-sm); background: none; text-align: left; cursor: pointer;
}
.menu-item .icon { width: 1.1rem; height: 1.1rem; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-hint { margin-left: auto; padding-left: 1rem; color: var(--muted); font-size: .85rem; }
.menu-header { padding: .5rem .65rem .35rem; font-size: .82rem; color: var(--muted); line-height: 1.4; }
.menu-header strong { color: var(--ink); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---- dialog ---- */
.dialog {
  width: min(560px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 0;
  border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
.dialog.small { width: min(420px, calc(100vw - 2rem)); }
.dialog[open] { animation: pop .16s ease-out; }
.dialog::backdrop { background: rgb(29 27 44 / 45%); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1rem 0 1.35rem; }
.dialog-body { display: grid; gap: 1rem; padding: .75rem 1.35rem 1.25rem; overflow-y: auto; }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap;
  padding: .85rem 1.35rem; border-top: 1px solid var(--line); background: var(--bg);
}
@media (max-width: 560px) {
  /* bottom sheet on phones */
  .dialog, .dialog.small {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .dialog-actions { padding-bottom: calc(.85rem + env(safe-area-inset-bottom)); }
  .dialog-actions .btn { flex: 1; }
}

/* ---- toasts ---- */
.toasts {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100;
  display: grid; gap: .5rem; justify-items: center; width: max-content; max-width: calc(100vw - 2rem);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: .55rem; padding: .7rem 1.1rem;
  border-radius: var(--r); background: var(--ink); color: #fff; box-shadow: var(--shadow-lg);
  font-weight: 500; animation: toast-in .2s ease-out;
}
.toast .icon { width: 1.1rem; height: 1.1rem; }
.toast.success .icon { color: #7ee2ad; }
.toast.error { background: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- difficulty picker ---- */
.difficulty-picker { border: 0; padding: 0; margin: 0; display: grid; gap: .6rem; min-width: 0; }
.label { font-weight: 650; font-size: .9rem; padding: 0; }
.difficulty-options { display: grid; gap: .5rem; grid-template-columns: repeat(2, 1fr); }
.difficulty {
  position: relative; display: grid; gap: .1rem; padding: .7rem .8rem; cursor: pointer;
  border: 1.5px solid var(--line-strong); border-radius: var(--r); transition: border-color .12s, background .12s;
}
.difficulty:hover { border-color: var(--level); }
.difficulty input { position: absolute; opacity: 0; pointer-events: none; }
.difficulty:has(input:checked) { border-color: var(--level); background: var(--level-soft); box-shadow: 0 0 0 1px var(--level); }
.difficulty:has(input:focus-visible) { outline: 3px solid rgb(80 70 229 / 40%); outline-offset: 2px; }
.style-picker .difficulty { --level: var(--brand); --level-soft: var(--brand-soft); }
.difficulty-name { font-weight: 700; }
.difficulty-k { font-size: .82rem; font-weight: 650; color: var(--level); }
.difficulty-desc { font-size: .8rem; color: var(--muted); line-height: 1.35; }
.custom-k { display: flex; align-items: center; gap: .6rem; font-size: .88rem; flex-wrap: wrap; }
.custom-k input[type=range] { flex: 1; min-width: 120px; }
.custom-k input[type=range]:disabled { opacity: .45; }
.k-value { font-weight: 700; min-width: 2ch; text-align: right; }

/* ---- dropzone ---- */
.dropzone {
  display: grid; justify-items: center; gap: .3rem; padding: 1.6rem 1rem; text-align: center; cursor: pointer;
  border: 2px dashed var(--line-strong); border-radius: var(--r); background: var(--bg);
  transition: border-color .12s, background .12s;
}
.dropzone > .icon { width: 1.8rem; height: 1.8rem; color: var(--brand); margin-bottom: .2rem; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.compact { padding: .8rem 1rem; }
.dropzone.compact > .icon, .dropzone.compact > .small { display: none; }
.file-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: .5rem; }
.file-thumb { position: relative; aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-remove {
  position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 1.5rem; height: 1.5rem;
  border: 0; border-radius: 50%; background: rgb(29 27 44 / 70%); color: #fff; cursor: pointer;
}
.file-remove .icon { width: .85rem; height: .85rem; }
