:root {
  --bg: #0f1217;
  --panel: #161b23;
  --panel-2: #1d2430;
  --border: #2a3342;
  --text: #e6ebf2;
  --muted: #8f9bb0;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  min-height: 54px;
  height: auto;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: rgba(245, 158, 11, 0.14);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.topbar-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.stat-pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  min-width: 78px;
}

.stat-pill.ok { border-color: rgba(34, 197, 94, 0.5); }
.stat-pill.warn { border-color: rgba(245, 158, 11, 0.7); background: rgba(245, 158, 11, 0.12); }
.stat-pill.bad { border-color: rgba(239, 68, 68, 0.8); background: rgba(239, 68, 68, 0.12); }

.stat-btn {
  cursor: pointer;
  text-align: left;
  transition: filter 0.15s, border-color 0.15s;
}
.stat-btn:hover:not(:disabled) { filter: brightness(1.16); border-color: var(--accent); }
.stat-btn:disabled { opacity: 0.45; cursor: default; }

.pf-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.pf-metric-box {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.pf-metric-box span { display: block; font-size: 11px; color: var(--muted); }
.pf-metric-box strong { font-size: 14px; color: var(--text); }

.pf-checks {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.pf-check-row {
  border-radius: 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.pf-check-row.ok { border-left: 4px solid var(--ok); }
.pf-check-row.warn { border-left: 4px solid var(--warn); background: rgba(245, 158, 11, 0.08); }
.pf-check-row.danger { border-left: 4px solid var(--danger); background: rgba(239, 68, 68, 0.10); }
.pf-check-title { font-weight: 700; font-size: 12.5px; margin-bottom: 2px; }
.pf-check-detail { font-size: 12px; color: var(--muted); }
.pf-check-tip { font-size: 11.5px; color: #fde68a; margin-top: 4px; }

.pf-hotspots-wrap {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.pf-hotspots-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.pf-hotspots-head strong {
  font-size: 12.5px;
  color: var(--accent);
}

.pf-hotspots-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 185px;
  overflow-y: auto;
}

.pf-hotspot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
}

.pf-hotspot-row.danger { border-left: 3px solid var(--danger); }
.pf-hotspot-row.warn { border-left: 3px solid var(--warn); }

.pf-hs-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.stat-pill strong {
  font-size: 12.5px;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.export-fmt-select {
  width: 175px;
  padding: 6px 8px;
}

.lang-switch {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--panel-2);
  color: var(--accent);
}

.modal-wide {
  width: 680px;
  max-width: 95vw;
}

.admin-users-list {
  max-height: 290px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-user-row {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1.3fr 130px 85px 85px auto;
  gap: 6px;
  align-items: center;
}

/* Main 3-column layout – strictly fills remaining viewport height above taskbar */
.workspace {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 325px;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  height: 100%;
  background: var(--panel);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px 64px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #46546c #161b23;
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: #161b23; }
.sidebar::-webkit-scrollbar-thumb { background: #3b475e; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--accent); }

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 255px minmax(0, 1fr) 285px;
  }
}

.sidebar-left { border-right: 1px solid var(--border); }
.sidebar-right { border-left: 1px solid var(--border); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-header h2, .card h2 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 700;
  color: #f3f6fb;
}

.sidebar-header h2 { margin: 0; }

.card h3 {
  margin: 0 0 6px 0;
  font-size: 12.5px;
  color: var(--accent);
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
}

.card-accent {
  border-color: rgba(245, 158, 11, 0.35);
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed #445168;
  border-radius: 9px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  background: rgba(15, 18, 23, 0.45);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.08);
}

.dropzone-icon { font-size: 22px; margin-bottom: 4px; }
.dropzone-text { font-size: 12.5px; }
.dropzone-text .link { color: var(--accent); text-decoration: underline; }
.dropzone-hint { font-size: 11px; color: var(--muted); margin-top: 3px; }

.file-info {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--ok);
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 6px;
  padding: 5px 8px;
  word-break: break-all;
}

/* Inputs & Buttons */
.field {
  margin-bottom: 8px;
}

.field label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.input-select, .input-num {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12.5px;
}

.input-num.readonly {
  color: var(--muted);
  background: rgba(15, 18, 23, 0.55);
}

.input-color {
  width: 100%;
  height: 31px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  padding: 2px;
  cursor: pointer;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 6px 0;
  font-size: 12px;
}

.checkbox-row input {
  accent-color: var(--accent);
  cursor: pointer;
}

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn-sm { padding: 5px 9px; font-size: 11.5px; }
.btn-full { width: 100%; }

.btn-primary { background: var(--accent); color: #111419; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #263040; }

.btn-outline { background: transparent; color: var(--text); border-color: #3a465c; }
.btn-outline:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.helper-note {
  margin: 4px 0 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
}

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.hidden { display: none !important; }

/* Center Stage */
.canvas-stage {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0b0e13;
  position: relative;
  overflow: hidden;
}

.stage-toolbar {
  flex: 0 0 auto;
  min-height: 42px;
  height: auto;
  padding: 5px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--panel-2);
  color: var(--accent);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mini-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.mini-check input { accent-color: var(--accent); }

.fabric-swatches {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch-label { font-size: 11.5px; color: var(--muted); }

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #485468;
  cursor: pointer;
  padding: 0;
}
.swatch.active { border-color: var(--accent); transform: scale(1.12); }

.warnings-bar {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
  padding: 7px 14px;
  font-size: 12px;
  line-height: 1.4;
}

.warnings-bar.error {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.canvas-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stitchCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#stitchCanvas:active { cursor: grabbing; }

.overlay-img {
  max-width: 82%;
  max-height: 82%;
  object-fit: contain;
  background: repeating-conic-gradient(#262d3a 0% 25%, #1c222d 0% 50%) 50% / 20px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.empty-state {
  position: absolute;
  text-align: center;
  max-width: 340px;
  color: var(--muted);
  pointer-events: none;
}

.empty-icon { font-size: 40px; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px 0; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0; line-height: 1.5; }

.loading-badge {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 27, 35, 0.92);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(245, 158, 11, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Simulator bar */
.sim-bar {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sim-speed { width: 135px; }
.sim-slider { flex: 1; }
.sim-counter { font-size: 12px; color: var(--muted); min-width: 115px; text-align: right; font-variant-numeric: tabular-nums; }

/* Right Sidebar Layers */
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-layers {
  text-align: center;
  color: var(--muted);
  padding: 20px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.layer-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.layer-card.disabled { opacity: 0.5; }

.layer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.layer-head:hover { background: rgba(255, 255, 255, 0.03); }

.layer-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  flex-shrink: 0;
}

.layer-title-wrap {
  flex: 1;
  min-width: 0;
}

.layer-title {
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-meta {
  font-size: 11px;
  color: var(--muted);
}

.layer-order-btns {
  display: flex;
  gap: 2px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.layer-body {
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border);
  background: rgba(15, 18, 23, 0.35);
}

.checklist {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}

.checklist li { margin-bottom: 4px; }
.checklist strong { color: var(--text); }

/* Thread Picker Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  width: 440px;
  max-width: 92vw;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-head h3 { margin: 0; font-size: 14px; }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  max-height: 280px;
  overflow-y: auto;
}

.pal-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 6px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-size: 11px;
}

.pal-item:hover { border-color: var(--accent); }

.pal-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

.modal-custom {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

/* Closed-Beta Login Gate */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: radial-gradient(circle at top, #1a2232 0%, #0b0e13 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-gate-card {
  width: 390px;
  max-width: 94vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 26px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.gate-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.gate-brand h2 {
  margin: 0;
  font-size: 19px;
}

.gate-links {
  margin-top: 16px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

.gate-links a {
  color: var(--muted);
  text-decoration: underline;
}

.gate-links a:hover { color: var(--accent); }

.guest-notice {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
  color: #fde68a;
  font-size: 11.5px;
  line-height: 1.4;
}

.saved-files-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
}

.saved-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.saved-file-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.saved-file-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Fail-closed Boot Splash (only shown while html.online-booting is active) */
.boot-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: radial-gradient(circle at top, #1a2232 0%, #0b0e13 70%);
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}

html.online-booting .boot-splash {
  display: flex;
}

.boot-card {
  width: 340px;
  max-width: 92vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.boot-spinner {
  width: 28px;
  height: 28px;
  margin: 16px auto 0 auto;
  border: 3px solid rgba(245, 158, 11, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Mobile-only section tabs (hidden on desktop) */
.mobile-tabs {
  display: none;
}

/* =========================================================================
   Responsive Mobile & Tablet Layout (<= 900px)
   ========================================================================= */
@media (max-width: 900px) {
  html, body {
    height: 100dvh;
    overflow: hidden;
    font-size: 14px;
  }

  .topbar {
    padding: 8px 10px;
    gap: 8px;
  }

  .brand h1 { font-size: 15px; }
  .brand .subtitle { display: none; }

  .topbar-stats {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 2px;
  }

  .stat-pill {
    min-width: 68px;
    padding: 3px 8px;
    flex: 0 0 auto;
  }

  .topbar-actions {
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex: 1 1 auto;
  }

  .export-fmt-select {
    width: 130px;
    padding: 5px 6px;
    font-size: 12px;
  }

  .topbar-actions .btn {
    padding: 6px 9px;
    font-size: 12px;
  }

  /* 3-tab mobile switcher bar */
  .mobile-tabs {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }

  .mob-tab {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 700;
    padding: 8px 6px;
    cursor: pointer;
    text-align: center;
  }

  .mob-tab.active {
    background: rgba(245, 158, 11, 0.16);
    border-color: var(--accent);
    color: var(--accent);
  }

  /* Single-column full-width active panel */
  .workspace {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  .workspace > .sidebar-left,
  .workspace > .canvas-stage,
  .workspace > .sidebar-right {
    display: none;
    width: 100%;
    height: 100%;
    flex: 1 1 0;
    min-height: 0;
    border: none;
  }

  .workspace[data-active-tab="left"] > .sidebar-left {
    display: flex;
    padding: 10px 12px 72px 12px;
  }

  .workspace[data-active-tab="stage"] > .canvas-stage {
    display: flex;
    flex-direction: column;
  }

  .workspace[data-active-tab="right"] > .sidebar-right {
    display: flex;
    padding: 10px 12px 72px 12px;
  }

  .stage-toolbar {
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .segmented {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .seg-btn {
    padding: 6px 4px;
    font-size: 11px;
    text-align: center;
  }

  .toolbar-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px 10px;
    justify-content: flex-start;
  }

  .canvas-wrap {
    flex: 1 1 0;
    min-height: 260px;
    touch-action: none;
  }

  .sim-bar {
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .sim-counter {
    font-size: 11px;
    min-width: auto;
  }

  /* Mobile-friendly modals */
  .modal-card {
    padding: 16px;
    max-width: 96vw;
    max-height: 90dvh;
    overflow-y: auto;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .pf-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .palette-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-user-row {
    grid-template-columns: 1fr 1fr;
  }

  .admin-user-row > div:first-child {
    grid-column: 1 / -1;
  }

  .saved-file-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .saved-file-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .login-gate-card {
    padding: 20px 18px;
  }
}
