:root {
  color-scheme: dark;
  --bg: #0a0e13;
  --bg-glow: #10202a;
  --surface: #121922;
  --surface-2: #18212d;
  --surface-3: #1f2a38;
  --border: #263445;
  --border-strong: #34465c;
  --text: #e9eff6;
  --text-muted: #9aabbf;
  --text-faint: #6f8197;
  --accent: #3ddc84;
  --accent-strong: #2fc472;
  --accent-soft: rgba(61, 220, 132, 0.14);
  --accent-contrast: #04210f;
  --gold: #f6c453;
  --gold-soft: rgba(246, 196, 83, 0.14);
  --danger: #ff6b78;
  --danger-soft: rgba(255, 107, 120, 0.14);
  --warning: #ffb547;
  --warning-soft: rgba(255, 181, 71, 0.13);
  --info: #5fb4ff;
  --info-soft: rgba(95, 180, 255, 0.13);
  --custom: #b98cff;
  --custom-soft: rgba(185, 140, 255, 0.15);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --focus: 0 0 0 3px rgba(61, 220, 132, 0.45);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(61, 220, 132, 0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
code, .mono { font-family: var(--font-mono); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

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

.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 1000;
  background: var(--accent); color: var(--accent-contrast); padding: 10px 16px; border-radius: var(--radius-sm);
  font-weight: 700; transition: top 0.2s;
}
.skip-link:focus { top: 12px; }

.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .container { padding: 0 24px; } }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 0.875rem; }
.card-gap { margin-top: 12px; }

.btn {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  font: inherit; font-weight: 650; font-size: 0.95rem;
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid var(--btn-border); border-radius: 10px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.15s var(--ease), background 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--text-faint); color: var(--btn-fg); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--accent-contrast); --btn-border: transparent; box-shadow: 0 6px 20px var(--accent-soft); }
.btn-primary:hover:not(:disabled) { --btn-bg: var(--accent-strong); border-color: transparent; }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-border: rgba(255, 107, 120, 0.4); }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-ghost:hover:not(:disabled) { --btn-bg: var(--surface-2); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.875rem; border-radius: 8px; }
.btn-lg { min-height: 50px; padding: 0 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; font-size: 1.2rem; line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field-hint { font-size: 0.82rem; color: var(--text-muted); margin-top: 6px; }
.checkbox .field-hint { display: block; }
input[type="text"], input[type="search"], input[type="password"], input[type="number"], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); box-shadow: var(--focus); border-radius: 10px; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex-shrink: 0; }
.checkbox { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; cursor: pointer; }
.checkbox input { margin-top: 3px; }

.form-error {
  background: var(--danger-soft); color: #ffd3d7; border: 1px solid rgba(255, 107, 120, 0.35);
  padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; margin-bottom: 12px;
}
.form-error ul { margin: 6px 0 0; padding-left: 20px; }
.form-success {
  background: var(--accent-soft); color: #c9f7dc; border: 1px solid rgba(61, 220, 132, 0.35);
  padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; margin-bottom: 12px;
}

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid; margin: 0 0 20px;
}
.banner-warning { background: var(--warning-soft); border-color: rgba(255, 181, 71, 0.35); color: #ffe2b5; }
.banner-info { background: var(--info-soft); border-color: rgba(95, 180, 255, 0.3); color: #d3e9ff; }
.banner-icon { font-size: 1.2rem; line-height: 1.3; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; border: 1px solid transparent;
}
.tag-custom { background: var(--custom-soft); color: var(--custom); border-color: rgba(185, 140, 255, 0.35); }
.tag-test { background: var(--warning-soft); color: var(--warning); border-color: rgba(255, 181, 71, 0.35); }
.tag-muted { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap;
}
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-open { background: var(--info-soft); color: var(--info); border-color: rgba(95, 180, 255, 0.35); }
.status-completed { background: var(--accent-soft); color: var(--accent); border-color: rgba(61, 220, 132, 0.35); }
.status-rejected { background: var(--danger-soft); color: var(--danger); border-color: rgba(255, 107, 120, 0.35); }

.badge {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; font-size: 0.75rem; font-weight: 800;
  background: var(--accent-contrast); color: var(--accent);
}

dialog {
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 0;
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(3, 6, 10, 0.72); backdrop-filter: blur(3px); }
dialog[open] { animation: dialog-in 0.22s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.dialog-header h2 { margin: 0; font-size: 1.2rem; }
.dialog-body { padding: 16px 20px; overflow-y: auto; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; flex-wrap: wrap; }

.toasts {
  position: fixed; z-index: 2000; right: 16px; bottom: 16px; left: 16px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 420px; width: 100%;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  animation: toast-in 0.25s var(--ease);
}
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--info); }
.toast strong { display: block; margin-bottom: 2px; }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18); border-top-color: currentColor;
  animation: spin 0.8s 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.4s infinite linear; border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty-state {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: rgba(18, 25, 34, 0.5);
}
.empty-state .empty-icon { font-size: 2.2rem; margin-bottom: 8px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

.item-icon { width: 100%; height: 100%; object-fit: contain; }
.item-icon.pixelated { image-rendering: pixelated; }

.model3d { position: relative; width: 100%; height: 100%; container-type: size; perspective: 320cqmin; touch-action: pan-y; }
.model3d.loading { visibility: hidden; }
.model-rot {
  --size: 58cqmin; --half: calc(var(--size) / 2);
  position: absolute; left: 50%; top: 50%; width: var(--size); height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  transform-style: preserve-3d; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.model3d.tracking .model-rot { transition: transform 0.12s ease-out; }
.model-rot.sprite { --size: 86cqmin; --depth: 7cqmin; }
.model-rot .face, .model-rot .layer {
  position: absolute; inset: 0; background-size: 100% 100%; background-repeat: no-repeat; image-rendering: pixelated;
}
.model-rot .face { backface-visibility: hidden; box-shadow: inset 0 0 0 100cqmax rgba(0, 0, 0, var(--shade, 0)); }
.model-rot .layer { transform: translateZ(calc(var(--z) * var(--depth))); filter: brightness(0.55); }
.model-rot .layer.outer { filter: none; }
.icon-placeholder {
  width: 100%; height: 100%; display: grid; place-items: center;
  color: var(--text-faint);
}
.icon-placeholder svg { width: 60%; height: 60%; }
.avatar { width: 32px; height: 32px; border-radius: 6px; image-rendering: pixelated; background: var(--surface-3); flex-shrink: 0; }
.avatar-placeholder { display: grid; place-items: center; color: var(--text-muted); font-weight: 800; font-size: 0.9rem; }

.inline-item { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mini-icon { width: 28px; height: 28px; flex-shrink: 0; display: grid; place-items: center; padding: 2px; border-radius: 6px; background: var(--surface-3); }
.mini-icon .icon-placeholder svg { width: 80%; height: 80%; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

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