:root {
  --bg: #0b101b;
  --surface: #131b2e;
  --surface-2: #1d2842;
  --surface-3: #243252;
  --border: #2a395c;
  --text: #f1f5f9;
  --muted: #9db0ce;
  --amber: #f59e0b;
  --amber-hover: #fbbf24;
  --amber-text: #0b101b;
  --cyan: #38bdf8;
  --cyan-soft: rgba(56, 189, 248, 0.14);
  --amber-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #fb923c;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #e2e8f0;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --amber: #d97706;
  --amber-hover: #b45309;
  --amber-text: #ffffff;
  --cyan: #0284c7;
  --cyan-soft: rgba(2, 132, 199, 0.12);
  --amber-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #ea580c;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Login */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.3rem;
}

.login-brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* App Shell */
.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.75rem 0.9rem 5.5rem;
}

@media (min-width: 980px) {
  .app-shell {
    padding: 1rem 1.4rem 2.5rem;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.topbar-logo {
  border-radius: 9px;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Navigation */
.main-nav {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 0.9rem;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: 0.15s ease;
}

.nav-tab.active {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-text);
}

.count-pill {
  background: rgba(0, 0, 0, 0.22);
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  font-size: 0.76rem;
}

[data-theme="light"] .nav-tab:not(.active) .count-pill {
  background: var(--surface-3);
}

/* Workspace grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}

@media (min-width: 980px) {
  .workspace-grid {
    grid-template-columns: 1.08fr 0.92fr;
    gap: 1.25rem;
  }

  .preview-col {
    position: sticky;
    top: 1rem;
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0;
  font-size: 1rem;
}

.card h3 {
  margin: 0.4rem 0 0;
  font-size: 0.92rem;
  color: var(--cyan);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Mode Bar */
.mode-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
  padding: 0.55rem;
  margin-bottom: 0.9rem;
}

@media (min-width: 560px) {
  .mode-bar {
    grid-template-columns: repeat(4, 1fr);
  }
}

.mode-pill {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.5rem;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.mode-pill.active {
  background: var(--cyan-soft);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field > span,
.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.58rem 0.72rem;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
}

input[type="color"] {
  width: 100%;
  height: 39px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

textarea {
  resize: vertical;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

@media (min-width: 560px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.toolbar-row > input[type="search"] {
  flex: 1 1 220px;
}

.toolbar-row > select {
  width: auto;
  min-width: 160px;
}

/* Style Chips Grid */
.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 0.45rem;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.style-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.52rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: 0.14s ease;
}

.style-chip:hover {
  border-color: var(--cyan);
}

.style-chip.active {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.style-chip-top {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  width: 100%;
  font-weight: 600;
  font-size: 0.85rem;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.style-chip-meta {
  font-size: 0.74rem;
  color: var(--muted);
}

/* Presets & Pills */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preset-chip,
.game-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.34rem 0.68rem;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
}

.preset-chip.active,
.game-chip.active {
  background: var(--cyan-soft);
  border-color: var(--cyan);
  color: var(--cyan);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tone-pill,
.subtype-pill,
.status-pill {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.72rem;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.tone-pill.active,
.subtype-pill.active,
.status-pill.active {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-text);
}

.inline-add {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.45rem;
}

.toggles-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
}

.toggles-grid select {
  width: auto;
  padding: 0.35rem 0.55rem;
  font-size: 0.83rem;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  cursor: pointer;
  user-select: none;
}

.check-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--amber);
}

/* Checklist Pack */
.checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 0.45rem;
  max-height: 280px;
  overflow-y: auto;
}

.pack-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  cursor: pointer;
}

/* Buttons & Badges */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.58rem 0.95rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: 0.14s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.36rem 0.68rem;
  font-size: 0.81rem;
}

.btn-full {
  width: 100%;
}

.btn-grow {
  flex: 1 1 auto;
}

.btn-primary {
  background: var(--amber);
  color: var(--amber-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--amber-hover);
}

.btn-accent {
  background: var(--cyan-soft);
  border-color: var(--cyan);
  color: var(--cyan);
}

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--cyan);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.btn-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.btn-row.wrap {
  flex-wrap: wrap;
}

.btn-row.end {
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ai {
  background: var(--cyan-soft);
  color: var(--cyan);
}

.badge-auto {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-edited {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-muted {
  background: var(--surface-2);
  color: var(--muted);
}

/* AI Card */
.ai-card {
  padding: 0.85rem 1rem;
}

.ai-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.94rem;
  list-style: none;
}

.ai-body {
  margin-top: 0.85rem;
}

.ai-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.ai-photo-preview {
  max-height: 150px;
  max-width: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  align-self: flex-start;
}

.ai-detected {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--cyan-soft);
  border: 1px solid var(--cyan);
  font-size: 0.85rem;
}

/* Preview Card */
.preview-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.platform-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface-2);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.plat-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.42rem 0.8rem;
  border-radius: 7px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

.plat-tab.active {
  background: var(--amber);
  color: var(--amber-text);
}

.label-counter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.counter.warn {
  color: var(--warn);
}

.title-copy-row {
  display: flex;
  gap: 0.45rem;
}

.title-copy-row .preview-title-input {
  flex: 1 1 auto;
  font-weight: 600;
}

.preview-desc-input {
  font-family: inherit;
  line-height: 1.5;
  min-height: 290px;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.meta-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
}

.meta-box summary {
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 0.75rem;
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
}

.meta-grid dt {
  color: var(--muted);
  font-weight: 600;
}

.meta-grid dd {
  margin: 0;
}

/* Styles & Listings Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.85rem;
}

.style-manage-card,
.listing-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border-left: 4px solid var(--amber);
}

.listing-card {
  border-left-color: var(--cyan);
}

.listing-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.listing-title {
  font-weight: 700;
  font-size: 0.98rem;
}

.listing-snippet {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid var(--danger);
  color: #fecaca;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

[data-theme="light"] .alert-error {
  color: #991b1b;
}

/* Mobile bottom sticky bar */
.mobile-copy-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom));
  background: rgba(11, 16, 27, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 40;
}

[data-theme="light"] .mobile-copy-bar {
  background: rgba(255, 255, 255, 0.94);
}

.mobile-copy-bar .btn:not(:last-child) {
  flex: 1 1 auto;
}

@media (min-width: 980px) {
  .mobile-copy-bar {
    display: none !important;
  }
}

/* Modal */
.modal-dialog {
  width: min(640px, calc(100vw - 1.5rem));
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}

.modal-dialog::backdrop {
  background: rgba(5, 8, 16, 0.75);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--cyan);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 60;
}

@media (min-width: 980px) {
  .toast {
    bottom: 1.4rem;
  }
}
