/* ── Catppuccin Mocha ───────────────────────── */
:root {
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;
  --surface0: #313244;
  --surface1: #45475a;
  --surface2: #585b70;
  --overlay0: #6c7086;
  --overlay1: #7f849c;
  --subtext0: #a6adc8;
  --subtext1: #bac2de;
  --text: #cdd6f4;
  --lavender: #b4befe;
  --blue: #89b4fa;
  --sapphire: #74c7ec;
  --teal: #94e2d5;
  --green: #a6e3a1;
  --yellow: #f9e2af;
  --peach: #fab387;
  --maroon: #eba0ac;
  --red: #f38ba8;
  --mauve: #cba6f7;
  --accent: #6c6ce0;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--base);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top Bar ───────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 44px;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-back {
  background: transparent;
  border: none;
  color: var(--overlay0);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  display: none;
  white-space: nowrap;
}
.topbar-back:hover { color: var(--text); }
.topbar-back.visible { display: inline-flex; }
.topbar-breadcrumb {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-user {
  color: var(--subtext0);
  font-size: 13px;
}
.topbar select {
  background: var(--base);
  color: var(--text);
  border: 1px solid var(--surface0);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  min-width: 200px;
}
.topbar select:focus {
  outline: none;
  border-color: var(--accent);
}
.topbar-project-label {
  color: var(--subtext0);
  font-size: 13px;
}

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-green { background: #2d7d46; color: #fff; }
.btn-blue { background: #1e5f8e; color: #fff; }
.btn-danger { background: #8e1e1e; color: #fff; }
.btn-warn { background: #8e5a1e; color: #fff; }
.btn-ghost { background: transparent; color: var(--subtext0); border: 1px solid var(--surface0); }
.btn-ghost:hover { background: var(--surface0); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-icon { padding: 6px 10px; font-size: 13px; min-width: 36px; }

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.card-subtitle {
  color: var(--subtext0);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Forms ─────────────────────────────────────── */
input, select, textarea {
  background: var(--crust);
  color: var(--text);
  border: 1px solid var(--surface0);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input:read-only {
  color: var(--overlay0);
}
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 13px; color: var(--subtext0); margin-bottom: 4px; }
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.form-hint {
  font-size: 11px;
  color: var(--overlay0);
  margin-top: 4px;
}
.form-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Layout ────────────────────────────────────── */
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}
.page-wide {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}
.page-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}
.page-subtitle {
  color: var(--subtext0);
  font-size: 14px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--overlay0);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  padding-left: 4px;
}

/* ── Tabs ──────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--surface0);
  margin-bottom: 0;
}
.tab {
  padding: 8px 20px;
  cursor: pointer;
  color: var(--overlay0);
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ── Home Page ─────────────────────────────────── */
.project-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 520px;
}
.project-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--mantle);
  border: 2px solid var(--surface0);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.project-entry:hover {
  border-color: var(--accent);
  background: var(--surface0);
}
.project-entry-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.project-entry-disabled:hover {
  border-color: var(--surface0);
  background: var(--mantle);
}
.project-entry-icon {
  font-size: 24px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}
.project-entry-info { flex: 1; }
.project-entry-name {
  font-weight: 700;
  font-size: 14px;
}
.project-entry-meta {
  font-size: 12px;
  color: var(--overlay0);
}

/* ── Game Manager ──────────────────────────────── */
.gm-split {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 140px);
}
.gm-left {
  width: 260px;
  min-width: 260px;
  background: var(--mantle);
  border-right: 1px solid var(--surface0);
  display: flex;
  flex-direction: column;
}
.gm-left-header {
  padding: 12px 16px;
  font-weight: 700;
  font-size: 13px;
  color: var(--subtext0);
  border-bottom: 1px solid var(--surface0);
}
.gm-project-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.gm-project-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.gm-project-item:hover { background: var(--surface0); }
.gm-project-item.active {
  background: var(--surface0);
  border-left-color: var(--accent);
}
.gm-project-item-name {
  font-weight: 600;
  color: var(--text);
}
.gm-project-item-meta {
  font-size: 11px;
  color: var(--overlay0);
}
.gm-left-actions {
  padding: 8px 12px;
  border-top: 1px solid var(--surface0);
  display: flex;
  gap: 6px;
}
.gm-right {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
}
.gm-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--overlay0);
  font-size: 15px;
}
.gm-detail-group {
  margin-bottom: 24px;
}
.gm-detail-group h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--overlay0);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.gm-detail-table {
  width: 100%;
  max-width: 400px;
}
.gm-detail-table td {
  padding: 6px 0;
  font-size: 13px;
}
.gm-detail-table td:first-child {
  color: var(--subtext0);
  width: 100px;
}
.gm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Symbol Editor ─────────────────────────────── */
.symbol-row {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.symbol-row-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.symbol-row-bottom {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.symbol-preview-box {
  width: 128px;
  height: 128px;
  background: #222;
  border: 1px solid var(--surface1);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.symbol-preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.symbol-preview-box .placeholder {
  font-size: 12px;
  color: var(--overlay0);
  text-align: center;
  padding: 8px;
}
.symbol-preview-box.dragover {
  border-color: var(--accent);
  background: var(--surface0);
}
.symbol-fields {
  flex: 1;
  min-width: 0;
}
.symbol-field-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.symbol-field-row input {
  width: auto;
}
.symbol-name-input {
  font-size: 16px;
  font-weight: 600;
  padding: 6px 10px;
}
.symbol-file-info {
  font-size: 11px;
  color: var(--overlay0);
  margin-top: 4px;
  word-break: break-all;
}

/* ── Image Gen ─────────────────────────────────── */
.gen-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  align-items: center;
  border-bottom: 1px solid var(--surface0);
}
.gen-row input { width: 100%; }
.gen-row .gen-code { max-width: 120px; }
.gen-row .gen-rarity { max-width: 80px; }
.gen-row .gen-design { flex: 1; }

.gen-header {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--overlay0);
  border-bottom: 1px solid var(--surface0);
}
.gen-header span:nth-child(1) { width: 120px; flex-shrink: 0; }
.gen-header span:nth-child(2) { width: 80px; flex-shrink: 0; }
.gen-header span:nth-child(3) { width: 60px; flex-shrink: 0; }
.gen-header span:nth-child(4) { flex: 1; }
.gen-header span:nth-child(5) { width: 80px; flex-shrink: 0; text-align: center; }
.gen-header span:nth-child(6) { width: 40px; flex-shrink: 0; }

.gen-result-preview {
  max-width: 64px;
  max-height: 64px; 
  border-radius: 4px;
  display: block;
  margin: 0 auto;
}
.gen-progress {
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--surface0);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--subtext0);
}
.gen-progress-bar {
  height: 6px;
  background: var(--surface1);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}
.gen-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── Modals ────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 540px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box-wide {
  max-width: 620px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Git Modal ─────────────────────────────────── */
.git-login-prompt {
  text-align: center;
  padding: 20px 0;
}
.git-login-prompt h2 {
  font-size: 20px;
  margin-bottom: 8px;
}
.git-login-prompt p {
  color: var(--subtext0);
  margin-bottom: 20px;
}
.git-code-display {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 8px;
  padding: 16px 24px;
  background: var(--crust);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  margin: 12px 0;
  user-select: all;
  text-align: center;
}
.git-status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.git-status-badge.dirty { background: #3a3a1e; color: var(--yellow); }
.git-status-badge.behind { background: #1a2d3a; color: var(--sapphire); }
.git-status-badge.ahead { background: #3a3a1e; color: var(--yellow); }
.git-status-badge.clean { background: #1a2d1a; color: var(--green); }
.git-detail-section {
  margin-top: 12px;
}
.git-detail-section summary {
  cursor: pointer;
  color: var(--overlay0);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 0;
}
.git-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--subtext0);
}
.git-file-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
}
.git-commit-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--surface0);
  font-size: 13px;
}
.git-commit-sha {
  color: var(--overlay0);
  font-family: monospace;
  white-space: nowrap;
  font-size: 12px;
}
.git-commit-msg {
  flex: 1;
  color: var(--text);
}
.git-commit-date {
  color: var(--overlay0);
  white-space: nowrap;
  font-size: 11px;
}

/* ── Toast ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  display: none;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.show { display: block; }
.toast.info { background: #1e5f8e; color: #fff; }
.toast.success { background: #2d7d46; color: #fff; }
.toast.error { background: #8e1e1e; color: #fff; }

/* ── Auth error banner ─────────────────────────── */
.auth-error {
  display: none;
  background: #3a1e1e;
  color: var(--red);
  padding: 12px 16px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}

/* ── Badge ─────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.badge-dirty { background: var(--yellow); color: #000; }
.badge-behind { background: var(--sapphire); color: #000; }
.badge-ahead { background: var(--yellow); color: #000; }
.badge-synced { background: var(--green); color: #000; }
.badge-pending { background: var(--yellow); color: #000; }

/* ── Loading spinner ───────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface0);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Separator ─────────────────────────────────── */
.separator {
  height: 1px;
  background: var(--surface0);
  margin: 16px 0;
}

/* ── Text utilities ────────────────────────────── */
.text-muted { color: var(--overlay0); font-size: 13px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.mono { font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.text-center { text-align: center; }

/* ── Login page ────────────────────────────────── */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 16px; }
.login-title { font-size: 32px; font-weight: 700; margin-bottom: 8px; }
.login-desc { color: var(--subtext0); margin-bottom: 32px; max-width: 400px; }
.login-code {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 8px;
  padding: 16px 24px;
  background: var(--crust);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  margin: 16px 0;
  user-select: all;
  font-family: var(--font);
}
.login-steps {
  text-align: left;
  color: var(--subtext0);
  font-size: 14px;
  line-height: 2;
  margin: 16px 0;
}
.login-steps li { list-style: none; }
.login-steps li::before { content: counter(step) ". "; counter-increment: step; }
.login-steps { counter-reset: step; }
.login-checking {
  display: none;
  margin-top: 16px;
  color: var(--subtext0);
}

/* ── Game Settings ──────────────────────────────── */
.gs-preview-icon {
  width: 64px;
  height: 64px;
  background: var(--crust);
  border: 2px solid var(--surface1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.gs-preview-icon img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.gs-preview-banner {
  width: 100%;
  max-width: 440px;
  height: 100px;
  background: var(--crust);
  border: 2px solid var(--surface1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.gs-preview-banner img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 6px; }
  .topbar select { min-width: 140px; }
  .form-row { flex-direction: column; }
  .symbol-row-top { flex-direction: column; align-items: center; }
  .gm-split { flex-direction: column; }
  .gm-left { width: 100%; min-width: 0; max-height: 200px; }
  .gen-row { flex-wrap: wrap; }
  .gen-row .gen-code { max-width: 100%; }
  .gen-row .gen-rarity { max-width: 100%; }
}
