/* Great Trace — ink / blueprint UI. Layers on the great-apps framework, which
   sets a fixed full-screen .view with overflow:hidden; we make .app-body the
   single scroll region and pin the header, action bar and footer. */

:root {
  --accent: #4f8dff;
  --accent-dim: #3a6fd6;
  --accent-glow: rgba(79, 141, 255, 0.35);
  --bg: #0b1120;
  --bg-surface: #131c30;
  --bg-elev: #1b2740;
  --border: #253352;
  --text: #e8edf7;
  --text-muted: #8ea0c0;
  --danger: #ff6b6b;
}

html, body { background: var(--bg); }

/* ── Shell layout ─────────────────────────────────────────── */
#app-view { background: radial-gradient(120% 80% at 50% -10%, #16233d 0%, var(--bg) 60%); }

.list-header { background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(8px); border-bottom-color: var(--border); }
.header-row h1 { letter-spacing: 0.2px; }
.header-accent { color: var(--accent); }

.app-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

/* ── Empty / pick state ───────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 26px calc(24px + env(safe-area-inset-bottom, 0px));
  gap: 6px;
}
.empty-art { filter: drop-shadow(0 10px 24px rgba(0,0,0,0.45)); margin-bottom: 6px; }
.empty-state h2 { font-size: 1.5rem; font-weight: 600; }
.empty-lead { color: var(--text-muted); max-width: 30ch; line-height: 1.5; margin-bottom: 14px; }

.pick-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }

.privacy-note {
  margin-top: 18px;
  color: var(--text-muted);
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 32ch;
  line-height: 1.4;
}
.privacy-note svg { flex-shrink: 0; color: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────── */
.primary-btn, .secondary-btn, .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font: inherit;
  font-weight: 600;
  border-radius: 12px;
  padding: 13px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.primary-btn { background: linear-gradient(180deg, var(--accent), var(--accent-dim)); color: #fff; box-shadow: 0 6px 18px var(--accent-glow); }
.secondary-btn { background: var(--bg-elev); color: var(--text); border-color: var(--border); }
.primary-btn:active, .secondary-btn:active, .ghost-btn:active { transform: translateY(1px); }
.primary-btn.small { padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 12px var(--accent-glow); }

.ghost-btn {
  flex-direction: column;
  gap: 3px;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-color: transparent;
}
.ghost-btn:hover { color: var(--text); }
.ghost-btn svg { color: var(--text-muted); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 6px 2px;
  align-self: flex-start;
}
.link-btn:active { opacity: 0.7; }

/* ── Editor ───────────────────────────────────────────────── */
.editor { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px 20px; }

.preview-wrap { position: relative; }
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
}
.trace-stat { color: var(--text-muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

.seg-control {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.is-active { background: var(--accent); color: #fff; }

.preview, .original-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  border: 1px solid var(--border);
  background-color: var(--bg-surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.original-img { object-fit: contain; background: #0a0f1c; }

/* Light "paper" checkerboard: conveys transparency AND keeps dark ink visible. */
.preview.checker {
  background-image:
    linear-gradient(45deg, #d7dbe4 25%, transparent 25%),
    linear-gradient(-45deg, #d7dbe4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d7dbe4 75%),
    linear-gradient(-45deg, transparent 75%, #d7dbe4 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  background-color: #f2f3f6;
  padding: 10px;
}
.preview svg { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; }

.processing {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(9, 14, 26, 0.9);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  padding: 6px 12px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.spinner-sm {
  width: 13px; height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Controls ─────────────────────────────────────────────── */
.controls { display: flex; flex-direction: column; gap: 15px; }

.slider-row { display: flex; flex-direction: column; gap: 8px; }
.slider-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.88rem; color: var(--text); font-weight: 500; }
.slider-label b { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 700; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill, 40%), var(--bg-elev) var(--fill, 40%));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
}

.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row, .color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  gap: 10px;
}
.switch-row span, .color-row span { display: flex; flex-direction: column; font-size: 0.9rem; font-weight: 500; }
.switch-row small { color: var(--text-muted); font-size: 0.72rem; font-weight: 400; }

/* iOS-style toggle */
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 44px; height: 26px; border-radius: 13px;
  background: var(--bg-elev); border: 1px solid var(--border);
  position: relative; cursor: pointer; flex-shrink: 0;
  transition: background 0.2s;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform 0.2s;
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(18px); }

.color-row input[type="color"] {
  appearance: none; -webkit-appearance: none;
  width: 40px; height: 30px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: none; cursor: pointer; flex-shrink: 0;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }

/* ── Action bar + footer ──────────────────────────────────── */
.action-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.action-bar .primary-btn.small { margin-left: auto; }
.action-bar .btn-sep { flex: 1; }

.list-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 16px;
  padding-bottom: calc(7px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.footer-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.version-label { flex-shrink: 0; }
.copyright { flex-shrink: 0; margin-left: auto; }

/* ── Overlay (help) ───────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6, 10, 20, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 520px;
  max-height: 82vh;
  display: flex; flex-direction: column;
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(18px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.overlay-head h2 { font-size: 1.15rem; font-weight: 600; }
.overlay-scroll { overflow-y: auto; padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px)); }
.help-steps { display: flex; flex-direction: column; gap: 14px; padding-left: 20px; }
.help-steps li { line-height: 1.5; color: var(--text); }
.help-steps b { color: var(--accent); }
.help-steps em { color: var(--text); font-style: normal; font-weight: 600; }
.help-note { margin-top: 16px; color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%; bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.18s ease;
}
@keyframes toast-in { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (min-width: 620px) {
  .editor { max-width: 560px; margin: 0 auto; width: 100%; }
  .action-bar { justify-content: center; }
  .action-bar .primary-btn.small { margin-left: 12px; }
}
