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

:root {
  --bg3-bg: #1d1613;
  --bg3-surface: #291f19;
  --bg3-surface-alt: #352922;
  --bg3-surface-hover: #44342b;
  --bg3-border-subtle: #4d3a28;
  --bg3-border: #755530;
  --bg3-border-light: #9d7543;
  --bg3-gold: #c89b3c;
  --bg3-gold-bright: #f4cf6d;
  --bg3-gold-dark: #6e4f1a;
  --bg3-crimson: #962222;
  --bg3-crimson-hover: #b82b2b;
  --bg3-text: #edd8b7;
  --bg3-text-bright: #fbf1e0;
  --bg3-text-muted: #baa385;
  --bg3-shadow: rgba(0, 0, 0, 0.65);
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, serif;
  background: #1d1613 radial-gradient(circle at 50% 0%, #2f221b 0%, #1d1613 75%, #150f0c 100%);
  background-attachment: fixed;
  color: var(--bg3-text);
  min-height: 100vh;
  line-height: 1.5;
}

header {
  background: linear-gradient(180deg, #2f231c 0%, #221a15 100%);
  padding: 0.75rem 2rem;
  border-bottom: 2px solid var(--bg3-gold);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.65), inset 0 -1px 0 rgba(200, 155, 60, 0.3);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--bg3-gold);
  box-shadow: 0 0 8px rgba(200, 155, 60, 0.3);
}

h1 {
  font-size: 1.35rem;
  color: var(--bg3-gold-bright);
  text-shadow: 0 0 10px rgba(200, 155, 60, 0.35);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

nav#tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--bg3-border);
  color: var(--bg3-text-muted);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.tab-btn.active, .tab-btn:hover {
  background: var(--bg3-surface-alt);
  border-color: var(--bg3-gold);
  color: var(--bg3-gold-bright);
  box-shadow: 0 0 10px rgba(200, 155, 60, 0.25);
}

main { padding: 2rem; max-width: 1200px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

h2 {
  margin-bottom: 1rem;
  color: var(--bg3-gold-bright);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  letter-spacing: 0.02em;
}

h3 {
  margin: 1.5rem 0 0.5rem;
  color: var(--bg3-gold);
  font-size: 1.15rem;
}

h4 {
  color: var(--bg3-gold-bright);
}

.btn {
  display: inline-block;
  background: var(--bg3-surface-alt);
  color: var(--bg3-text-bright);
  border: 1px solid var(--bg3-border);
  padding: 0.5rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg3-surface-hover);
  border-color: var(--bg3-gold);
  box-shadow: 0 0 8px rgba(200, 155, 60, 0.25);
  color: #fff;
}

.btn:disabled { opacity: 0.4; cursor: default; }

.btn.primary {
  background: linear-gradient(180deg, #962222 0%, #6e1515 100%);
  border: 1px solid var(--bg3-gold);
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #ad2929 0%, #831b1b 100%);
  box-shadow: 0 0 14px rgba(200, 155, 60, 0.4);
}

.btn-nexus {
  background: linear-gradient(180deg, #8a5015 0%, #5c3209 100%);
  border: 1px solid var(--bg3-gold);
  color: #fce8cc;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-nexus:hover {
  background: linear-gradient(180deg, #a6621c 0%, #703f0f 100%);
  color: #fff;
  box-shadow: 0 0 10px rgba(200, 155, 60, 0.35);
}

#drop-zone {
  border: 2px dashed var(--bg3-border-light);
  background: rgba(26, 19, 16, 0.6);
  border-radius: 8px;
  padding: 3rem;
  text-align: center;
  margin-bottom: 1.5rem;
  transition: border-color 0.2s ease;
}

#drop-zone.drag-over {
  border-color: var(--bg3-gold-bright);
  background: rgba(45, 32, 25, 0.8);
}

#file-input, #diff-file-input { display: none; }

/* Stat Cards & Grid Layout */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.stat-card {
  background: linear-gradient(180deg, #2d221b 0%, #211914 100%);
  border: 1px solid var(--bg3-border);
  border-radius: 6px;
  padding: 1rem 0.75rem;
  text-align: center;
  box-shadow: 0 4px 14px var(--bg3-shadow), inset 0 1px 0 rgba(200, 155, 60, 0.25);
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.stat-card .num {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--bg3-gold-bright);
  line-height: 1.2;
  text-shadow: 0 0 10px rgba(200, 155, 60, 0.35);
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

.stat-card .num.text-label {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--bg3-text-bright);
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.25rem;
}

.stat-card .label {
  font-size: 0.76rem;
  color: var(--bg3-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.35rem;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  margin-left: 5px;
  vertical-align: middle;
  transition: all 0.2s ease;
}

.status-dot.connected {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.status-dot.error {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.input-with-toggle {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-with-toggle input {
  flex: 1;
}

.form-hint {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--bg3-text-muted);
  line-height: 1.4;
}

.form-hint a {
  color: var(--bg3-gold-bright);
  text-decoration: underline;
}

.form-hint a:hover {
  color: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

th {
  text-align: left;
  padding: 0.6rem;
  background: var(--bg3-surface);
  color: var(--bg3-gold);
  border-bottom: 1px solid var(--bg3-border);
}

td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--bg3-border-subtle);
  vertical-align: middle;
}

tr:hover td { background: var(--bg3-surface-alt); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: bold;
}

.badge-RESOLVED { background: #1a4a1a; color: #7cf07c; border: 1px solid #2e7d32; }
.badge-DELISTED { background: #521616; color: #ffa6a6; border: 1px solid #991b1b; }
.badge-UNRESOLVED { background: #523910; color: #ffd680; border: 1px solid #b45309; }
.badge-PROTECTED { background: #163654; color: #8ec3ff; border: 1px solid #1d4ed8; }

.toolbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

.warning {
  background: #38240b;
  border: 1px solid var(--bg3-gold);
  color: #f7e0b5;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.subsection { margin-bottom: 2rem; }

.hidden { display: none !important; }

.uuid { font-family: monospace; font-size: 0.75rem; color: var(--bg3-text-muted); }

input[type="text"], input[type="email"], input[type="password"] {
  background: var(--bg3-surface);
  border: 1px solid var(--bg3-border);
  color: var(--bg3-text-bright);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--bg3-gold);
  box-shadow: 0 0 6px rgba(200, 155, 60, 0.4);
}

#tbl-unmapped input[type="text"],
#tbl-mapped input[type="text"] {
  width: 100%;
  min-width: 24ch;
  box-sizing: border-box;
}

.header-install {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.header-install select, select.input-control {
  background: var(--bg3-surface-alt);
  color: var(--bg3-text-bright);
  border: 1px solid var(--bg3-border);
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.badge-pc { background: #1a3250; color: #9bc5f5; border: 1px solid #2563eb; }
.badge-steam_deck { background: #13402e; color: #85e8ba; border: 1px solid #059669; }
.badge-playstation { background: #262152; color: #c4ccf7; border: 1px solid #4f46e5; }
.badge-xbox { background: #164019; color: #9ae8a1; border: 1px solid #16a34a; }

.preview-card {
  background: var(--bg3-surface);
  border: 1px solid var(--bg3-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 4px 16px var(--bg3-shadow);
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--bg3-text-muted);
}

.preview-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}

.preview-actions input[type="text"] {
  width: 280px;
}

.info-box {
  background: #192a3d;
  border: 1px solid #2563eb;
  color: #aed1fc;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin: 1rem 0;
}

.error-box {
  background: #471717;
  border: 1px solid #dc2626;
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin: 1rem 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--bg3-text-muted);
}

.form-group input, .form-group select {
  background: var(--bg3-surface);
  border: 1px solid var(--bg3-border);
  color: var(--bg3-text-bright);
  padding: 0.45rem;
  border-radius: 4px;
  width: 100%;
  max-width: 380px;
}

.grid-2col {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
}

@media (max-width: 850px) {
  .grid-2col { grid-template-columns: 1fr; }
  header { gap: 1rem; }
  .header-right { margin-left: 0; width: 100%; justify-content: space-between; }
}

/* PWA App Install Button & Dialog */
.btn-install {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border: 1px solid #a78bfa;
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
  transition: all 0.2s ease;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.btn-install:hover {
  background: linear-gradient(135deg, #6d28d9, #4338ca);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.6);
}

.modal-dialog {
  border: 1px solid var(--bg3-border-light);
  border-radius: 10px;
  background: #18120f;
  color: var(--bg3-text-bright);
  padding: 0;
  max-width: 560px;
  width: 90%;
  margin: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.9), 0 0 15px rgba(200, 155, 60, 0.15);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--bg3-border);
  background: var(--bg3-surface);
}

.modal-header h3 {
  margin: 0;
  color: var(--bg3-gold-bright);
  font-size: 1.2rem;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--bg3-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  line-height: 1;
}

.btn-close:hover {
  color: var(--bg3-gold-bright);
}

.modal-body {
  padding: 1.5rem;
}

.install-instructions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.25rem;
}

.install-platform {
  background: var(--bg3-surface);
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border-left: 4px solid var(--bg3-gold);
}

.install-platform h4 {
  margin: 0 0 0.35rem;
  color: var(--bg3-gold-bright);
  font-size: 0.95rem;
}

.install-platform p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--bg3-text-muted);
  line-height: 1.4;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--bg3-border);
  background: var(--bg3-surface);
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

/* Header Auth Controls */
.header-auth {
  display: flex;
  align-items: center;
}

.btn-auth {
  background: linear-gradient(180deg, #2b3950 0%, #162235 100%);
  color: #c7dcfa;
  border: 1px solid #3b82f6;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.btn-auth:hover {
  background: linear-gradient(180deg, #374b6b 0%, #1d2d46 100%);
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg3-surface-alt);
  border: 1px solid var(--bg3-border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

.user-email {
  font-size: 0.82rem;
  color: var(--bg3-gold-bright);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--bg3-border);
  color: var(--bg3-text-muted);
}

.btn-outline:hover {
  background: var(--bg3-surface-hover);
  border-color: var(--bg3-gold);
  color: var(--bg3-text-bright);
}

/* Auth & Nexus Modal Styles */
.auth-modal-content, .nexus-modal-content {
  max-width: 440px;
}

.auth-subtitle {
  font-size: 0.88rem;
  color: var(--bg3-text-muted);
  line-height: 1.45;
  margin-bottom: 1.25rem;
}

.auth-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: #ffffff;
  color: #1f2937;
  font-weight: 500;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  font-size: 0.92rem;
  width: 100%;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn-google:hover {
  background: #f9fafb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.google-icon {
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 0.5rem 0;
  color: var(--bg3-border-light);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--bg3-border);
}

.auth-divider span {
  padding: 0 0.5rem;
}

.auth-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.auth-actions .btn {
  flex: 1;
  text-align: center;
}

@media (display-mode: standalone) {
  header {
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }
}
