/* Design tokens — Catppuccin Latte (light) / Mocha (dark), mauve primary */
:root {
  --bg: #eff1f5;             /* latte base */
  --fg: #4c4f69;             /* latte text */
  --muted: #e6e9ef;          /* latte mantle */
  --muted-fg: #6c6f85;       /* latte subtext0 */
  --border: #bcc0cc;         /* latte surface1 */
  --input: #bcc0cc;
  --ring: #8839ef;           /* latte mauve */
  --ring-glow: rgba(136, 57, 239, 0.18);
  --card: #eff1f5;
  --primary: #8839ef;        /* latte mauve */
  --primary-fg: #eff1f5;
  --primary-hover: #7215e3;
  --secondary: #ccd0da;      /* latte surface0 */
  --secondary-fg: #4c4f69;
  --secondary-hover: #bcc0cc;
  --accent: #8839ef;
  --warning: #df8e1d;        /* latte yellow */
  --warning-fg: #eff1f5;
  --success: #40a02b;        /* latte green */
  --destructive: #d20f39;    /* latte red */
  --radius: 0.5rem;
  --shadow-sm: 0 1px 2px rgba(76, 79, 105, 0.08);
  --shadow: 0 4px 12px rgba(76, 79, 105, 0.12), 0 2px 4px rgba(76, 79, 105, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e2e;           /* mocha base */
    --fg: #cdd6f4;           /* mocha text */
    --muted: #313244;        /* mocha surface0 */
    --muted-fg: #a6adc8;     /* mocha subtext0 */
    --border: #45475a;       /* mocha surface1 */
    --input: #45475a;
    --ring: #cba6f7;         /* mocha mauve */
    --ring-glow: rgba(203, 166, 247, 0.22);
    --card: #1e1e2e;
    --primary: #cba6f7;      /* mocha mauve */
    --primary-fg: #1e1e2e;
    --primary-hover: #b48cef;
    --secondary: #313244;
    --secondary-fg: #cdd6f4;
    --secondary-hover: #45475a;
    --accent: #cba6f7;
    --warning: #f9e2af;      /* mocha yellow */
    --warning-fg: #1e1e2e;
    --success: #a6e3a1;      /* mocha green */
    --destructive: #f38ba8;  /* mocha red */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
  }
}

/* Reset & base */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  text-align: center;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
  max-width: 380px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
}

@media (min-width: 720px) {
  .app-container {
    max-width: 820px;
  }
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.875rem;
  text-align: left;
}

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

/* Card */
.card {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--card);
  padding: 1rem 1.125rem;
  transition: border-color 0.2s, background-color 0.2s, opacity 0.2s;
  min-width: 0;
}

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

.card-header h5 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.card-status {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-fg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-summary {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted-fg);
}

.card-summary .summary-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-summary .btn {
  width: auto;
  flex-shrink: 0;
}

.card-body {
  display: none;
  margin-top: 0.875rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border);
}

/* States */
.card.locked {
  opacity: 0.55;
  background: var(--muted);
}
.card.locked .card-header h5 {
  color: var(--muted-fg);
}
.card.locked::before {
  content: '';
}

.card.active {
  border-color: var(--fg);
  box-shadow: 0 0 0 1px var(--fg);
}
.card.active .card-status::before {
  content: 'In progress';
}
.card.active .card-body {
  display: block;
}

.card.completed .card-status::before {
  content: '✓';
  font-size: 1rem;
  color: var(--success);
}
.card.completed .card-summary {
  display: flex;
}

/* Tool link (offsite artwork generator) */
.tool-link {
  margin-top: 1rem;
  padding: 0.75rem 0.875rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--muted-fg);
  text-align: center;
}
.tool-link a {
  color: var(--fg);
  font-weight: 500;
  margin-left: 0.25rem;
}

/* Typography */
h3 {
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
  color: var(--fg);
}

h5 {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.005em;
  margin: 0 0 0.5rem;
  color: var(--fg);
}

h6 {
  font-weight: 500;
  font-size: 0.875rem;
  margin: 0 0 0.5rem;
  color: var(--muted-fg);
}

.text-muted {
  color: var(--muted-fg);
}

small {
  font-size: 0.85em;
  color: var(--muted-fg);
}

sub {
  font-size: 0.75em;
  color: var(--muted-fg);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--muted-fg);
  text-underline-offset: 3px;
}
a:hover {
  text-decoration-color: var(--fg);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.875rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.25;
  user-select: none;
}

.btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
}

.btn-lg {
  padding: 0.625rem 1rem;
  font-size: 0.95rem;
}

.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  background: var(--muted);
  color: var(--muted-fg);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-fg);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.btn-warning {
  background: var(--warning);
  color: var(--warning-fg);
}
.btn-warning:hover:not(:disabled) {
  background: hsl(38 92% 45%);
}

.btn-icon {
  width: auto;
  padding: 0.5rem;
}

.btn-group {
  display: inline-flex;
  gap: 0.375rem;
}

/* Form controls */
input[type="number"],
input[type="text"],
select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.25;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--ring);
  outline: 0;
  box-shadow: 0 0 0 3px var(--ring-glow);
}

input[type="file"] {
  display: block;
  width: 100%;
  padding: 0.375rem 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--secondary);
  color: var(--secondary-fg);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

input[type="range"] {
  display: block;
  width: 100%;
  accent-color: var(--primary);
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  text-align: left;
  color: var(--fg);
}

/* Checkboxes */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  font-size: 0.875rem;
}

.checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* Toggle switches */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  font-size: 0.875rem;
}

.toggle-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 2.5rem;
  height: 1.375rem;
  background: var(--muted);
  border-radius: 1rem;
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.toggle-switch input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: calc(1.375rem - 4px);
  height: calc(1.375rem - 4px);
  background: var(--bg);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}

.toggle-switch input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-switch input[type="checkbox"]:checked::after {
  transform: translateX(1.125rem);
  background: var(--primary-fg);
}

/* Progress bars */
.progress {
  width: 100%;
  height: 0.5rem;
  background: var(--muted);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--primary-fg);
  transition: width 0.3s;
  white-space: nowrap;
}

.progress-bar.bg-success {
  background: var(--success);
}

.progress-bar.progress-bar-striped {
  background-image: linear-gradient(
    45deg,
    hsl(0 0% 100% / 0.15) 25%,
    transparent 25%,
    transparent 50%,
    hsl(0 0% 100% / 0.15) 50%,
    hsl(0 0% 100% / 0.15) 75%,
    transparent 75%,
    transparent
  );
  background-size: 1rem 1rem;
}

.progress-bar.progress-bar-animated {
  animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
  0% { background-position: 1rem 0; }
  100% { background-position: 0 0; }
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Alert */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  text-align: left;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--muted);
  color: var(--fg);
}

.alert-warning {
  background: #fef6dd;
  border-color: #f2d88a;
  color: #a06412;
}

@media (prefers-color-scheme: dark) {
  .alert-warning {
    background: #302a1f;
    border-color: #574a2a;
    color: #f9e2af;
  }
}

/* Row / grid helpers */
.row {
  display: flex;
  gap: 0.5rem;
}

.row > .col {
  flex: 1;
}

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: hsl(240 10% 4% / 0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1001;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal.open {
  display: flex;
}

.modal.open ~ .modal-backdrop {
  display: block;
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  #toolsModal .modal-content {
    max-width: 600px;
  }
}

/* Settings sections (inside tools modal) */
.settings-section {
  margin-bottom: 1.5rem;
}
.settings-section:last-child {
  margin-bottom: 0;
}
.settings-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--muted-fg);
  margin: 0 0 0.75rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--border);
}
.settings-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.settings-grid-2 .btn {
  width: 100%;
}
.setting-help {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted-fg);
}

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

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

.modal-header h5 {
  margin: 0;
}

.modal-body {
  padding: 1.25rem;
  text-align: left;
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  text-align: right;
}

.modal-footer .btn {
  width: auto;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--muted-fg);
  padding: 0;
  line-height: 1;
  transition: color 0.15s;
}
.btn-close:hover {
  color: var(--fg);
}

/* SVG controls layout */
/* App header */
.app-header {
  width: 100%;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.app-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}

/* Tools gear button */
.tools-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-fg);
  padding: 0.25rem;
  border-radius: var(--radius);
  transition: color 0.15s, background-color 0.15s;
  flex-shrink: 0;
}
.tools-btn:hover {
  color: var(--fg);
  background: var(--muted);
}
.tools-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

/* Icon buttons */
.icon-btn svg {
  width: 1.125rem;
  height: 1.125rem;
  vertical-align: middle;
}

/* Input with reset button */
.input-with-reset {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.input-with-reset .btn {
  width: auto;
  white-space: nowrap;
}

/* Speed control */
.speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.speed-control input[type="range"] {
  flex: 1;
}
.speed-control .btn {
  width: auto;
  white-space: nowrap;
}

/* Debug panel */
.debug-panel {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.6;
  text-align: left;
}

/* Spacing utilities */
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 2.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-5 { margin-top: 2.5rem; }

/* Footer */
.app-footer {
  margin-top: 2.5rem;
  color: var(--muted-fg);
  font-size: 0.8rem;
}

/* Tool-specific */
.img-thumbnail {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem;
  max-width: 100%;
  width: 100%;
  background: #ffffff;
}

.tool-body {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 3rem;
}

.form-section {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--card);
  padding: 1rem 1.125rem;
}

.form-section-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--fg);
}

.header-link {
  color: var(--muted-fg);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}
.header-link:hover {
  color: var(--fg);
}
