/* =========================================================
   YThumb — design system
   Tokens, base elements and shared components.
   ========================================================= */

:root,
[data-theme="dark"] {
  --bg: #0b0b10;
  --bg-elev: #111118;
  --surface: #16161e;
  --surface-2: #1d1d27;
  --surface-3: #262632;
  --border: #262631;
  --border-strong: #363645;
  --text: #f4f4f7;
  --text-2: #a3a3b5;
  --text-3: #6f6f82;

  --brand: #ff3358;
  --brand-hover: #ff4d6d;
  --brand-press: #e62a4c;
  --brand-soft: rgba(255, 51, 88, 0.14);
  --brand-contrast: #ffffff;
  --accent: #ffd23f;

  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --info: #3b82f6;

  --overlay: rgba(5, 5, 10, 0.66);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);

  --checker-a: #1a1a22;
  --checker-b: #15151c;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f6f9;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f3f7;
  --surface-3: #e9e9f0;
  --border: #e4e4ec;
  --border-strong: #d2d2de;
  --text: #13131a;
  --text-2: #5b5b6e;
  --text-3: #8c8ca0;

  --brand-soft: rgba(255, 51, 88, 0.1);
  --danger-soft: rgba(239, 68, 68, 0.1);

  --overlay: rgba(20, 20, 30, 0.45);
  --shadow-sm: 0 1px 2px rgba(20, 20, 40, 0.06);
  --shadow: 0 8px 24px rgba(20, 20, 40, 0.08);
  --shadow-lg: 0 24px 64px rgba(20, 20, 40, 0.16);

  --checker-a: #ececf2;
  --checker-b: #e3e3ea;

  color-scheme: light;
}

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Plus Jakarta Sans", var(--font);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --focus-ring: 0 0 0 3px rgba(255, 51, 88, 0.35);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.15;
  margin: 0;
  letter-spacing: -0.02em;
}

p { margin: 0; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; }

::selection { background: var(--brand); color: #fff; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }

/* Thin scrollbars everywhere */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.03em;
}
.brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
.brand b { color: var(--brand); font-weight: 800; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { --btn-bg: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .45; pointer-events: none; }
.btn i { font-size: 13px; }

.btn-primary {
  --btn-bg: var(--brand);
  --btn-fg: var(--brand-contrast);
  --btn-border: transparent;
  box-shadow: 0 6px 18px -6px rgba(255, 51, 88, .6);
}
.btn-primary:hover { --btn-bg: var(--brand-hover); }
.btn-primary:active { --btn-bg: var(--brand-press); }

.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-ghost:hover { --btn-bg: var(--surface-2); }

.btn-outline { --btn-bg: transparent; --btn-border: var(--border-strong); }
.btn-outline:hover { --btn-bg: var(--surface-2); }

.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-border: transparent; }
.btn-danger:hover { --btn-bg: #dc2626; }
.btn-danger-ghost { --btn-bg: transparent; --btn-fg: var(--danger); --btn-border: transparent; }
.btn-danger-ghost:hover { --btn-bg: var(--danger-soft); }

.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 16px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .01em;
}
.hint { font-size: 12px; color: var(--text-3); }

.input,
.select,
.textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}
.input:disabled { opacity: .6; cursor: not-allowed; }
.input-sm, .select.input-sm { height: 32px; font-size: 13px; padding: 0 10px; }

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238c8ca0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--surface-3);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand); cursor: pointer;
}
input[type="range"]:focus-visible { box-shadow: var(--focus-ring); }

/* Toggle switch */
.switch { position: relative; display: inline-flex; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 20px;
  background: var(--surface-3); transition: background-color .2s; cursor: pointer;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .2s var(--ease);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: var(--focus-ring); }

/* Segmented control */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg button {
  flex: 1;
  height: 28px;
  min-width: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Cards, badges, misc ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #ff8a3d);
  color: #fff; font-weight: 700; font-size: 13px; flex: none;
}

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 5px; border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface-2);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px; color: var(--text-2);
}

.divider { height: 1px; background: var(--border); border: 0; margin: 16px 0; }

.progress { height: 8px; border-radius: 8px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #ff8a3d); transition: width .4s var(--ease); }
.progress.is-full > span { background: var(--danger); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  padding: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transform: translateY(-4px) scale(.98);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity .14s, transform .14s var(--ease);
}
.dropdown.is-open .dropdown-menu { opacity: 1; transform: none; pointer-events: auto; }
.dropdown-menu.align-left { right: auto; left: 0; transform-origin: top left; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0; border-radius: var(--radius-xs);
  background: transparent;
  font-size: 14px; text-align: left;
  color: var(--text); cursor: pointer;
}
.dropdown-item i { width: 16px; text-align: center; color: var(--text-2); font-size: 13px; }
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.is-danger, .dropdown-item.is-danger i { color: var(--danger); }
.dropdown-item .kbd { margin-left: auto; }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-header { padding: 8px 10px 10px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  padding: 16px;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.modal.is-open { opacity: 1; pointer-events: auto; }
.modal-dialog {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(.98);
  transition: transform .2s var(--ease);
}
.modal.is-open .modal-dialog { transform: none; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 980px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 20px 0;
}
.modal-header h3 { font-size: 18px; }
.modal-body { padding: 16px 20px 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.modal-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; margin-bottom: 14px;
  background: var(--danger-soft); color: var(--danger); font-size: 18px;
}

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; z-index: 2000;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px); max-width: 420px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #1c1c25;
  color: #f4f4f7;
  border: 1px solid #2c2c38;
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500;
  pointer-events: auto;
  animation: toast-in .25s var(--ease);
}
[data-theme="light"] .toast { background: #15151c; border-color: #15151c; }
.toast i { font-size: 15px; }
.toast-success i { color: var(--success); }
.toast-error i { color: #ff6b6b; }
.toast-info i { color: #60a5fa; }
.toast-warning i { color: var(--warning); }
.toast.is-leaving { animation: toast-out .2s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ---------- Tooltip ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%; top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-2px);
  padding: 5px 8px;
  border-radius: 6px;
  background: #0d0d12; color: #fff;
  font-size: 12px; font-weight: 500; line-height: 1.2;
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .12s, transform .12s;
  z-index: 300;
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%); transition-delay: .35s; }
[data-tip-pos="right"]::after { left: calc(100% + 10px); top: 50%; transform: translateY(-50%) translateX(-2px); }
[data-tip-pos="right"]:hover::after { transform: translateY(-50%); }
[data-tip-pos="top"]::after { top: auto; bottom: calc(100% + 8px); }

/* ---------- Ad slots ---------- */
.ad-slot {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.ad-slot img { width: 100%; height: 100%; object-fit: cover; }
.ad-slot::before {
  content: "Sponsored";
  position: absolute; top: 8px; right: 8px; z-index: 1;
  padding: 2px 7px; border-radius: 5px;
  background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 48px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 16px; background: var(--brand-soft); color: var(--brand); font-size: 22px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
