:root {
  --bg-linen: #faf6f0;
  --bg-parchment: #f3ece2;
  --bg-canvas: #efe7dc;
  --surface: #fffdf9;
  --surface-hover: #fbf6ee;
  --border: #e6dccf;
  --border-strong: #d6c8b6;

  --accent: #c86d51;
  --accent-hover: #b35a3f;
  --accent-soft: #f8e9e3;
  --sage: #628169;
  --sage-soft: #e8f0e9;

  --ink: #2d241e;
  --ink-muted: #6c5f55;
  --ink-subtle: #9a8d82;

  --shadow-sm: 0 1px 2px rgba(45, 36, 30, 0.05);
  --shadow-md: 0 6px 20px rgba(45, 36, 30, 0.08);
  --shadow-lg: 0 16px 40px rgba(45, 36, 30, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --font-display: 'Fraunces', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg-linen);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* ===== APP SHELL ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ===== TOPBAR ===== */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 20;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-mark svg {
  width: 34px;
  height: 34px;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(200, 109, 81, 0.25));
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.brand-tag {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.divider-v {
  width: 1px;
  height: 26px;
  background: var(--border);
}

.project-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-title-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  width: 190px;
  transition: border-color 0.15s, background 0.15s;
}

.project-title-input:hover {
  background: var(--bg-linen);
}

.project-title-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

.save-indicator {
  font-size: 0.74rem;
  color: var(--sage);
  background: var(--sage-soft);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  white-space: nowrap;
}

/* Segmented view control */
.segmented-control {
  display: inline-flex;
  background: var(--bg-parchment);
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s ease;
}

.seg-btn svg {
  width: 15px;
  height: 15px;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent);
  color: #fffdf9;
  box-shadow: 0 2px 6px rgba(200, 109, 81, 0.28);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn-secondary:hover {
  background: var(--bg-linen);
  border-color: var(--ink-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn-ghost:hover {
  background: var(--bg-parchment);
  color: var(--ink);
}

.btn-sm {
  padding: 7px 11px;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 5px 9px;
  font-size: 0.76rem;
}

.full-width {
  width: 100%;
}

.flex-1 {
  flex: 1;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ===== MAIN WORKSPACE ===== */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ===== LEFT TOOL RAIL ===== */
.tool-rail {
  width: 72px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  gap: 8px;
  flex-shrink: 0;
  overflow-y: auto;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.tool-divider {
  width: 36px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.tool-btn {
  width: 100%;
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.tool-btn svg {
  width: 19px;
  height: 19px;
}

.tool-btn span {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tool-btn:hover:not(:disabled) {
  background: var(--bg-linen);
  color: var(--ink);
}

.tool-btn.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: rgba(200, 109, 81, 0.35);
}

.tool-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.rail-active-swatch {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.active-swatch-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--border-strong), var(--shadow-sm);
  background: #c86d51;
}

.active-swatch-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
}

/* ===== CENTER CANVAS STAGE ===== */
.canvas-stage {
  flex: 1;
  position: relative;
  background: var(--bg-canvas);
  background-image: radial-gradient(rgba(154, 141, 130, 0.22) 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
  min-width: 0;
}

#patternCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.selection-bar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-pill);
  padding: 6px 10px 6px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 15;
}

.selection-info {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--bg-linen);
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.14s;
}

.mini-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.drag-overlay {
  position: absolute;
  inset: 16px;
  background: rgba(250, 246, 240, 0.92);
  border: 2.5px dashed var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: none;
}

.drag-overlay-card {
  text-align: center;
  color: var(--accent-hover);
}

.drag-overlay-card svg {
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
}

.drag-overlay-card h3 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 4px;
}

.drag-overlay-card p {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* Bottom HUD */
.canvas-hud {
  position: absolute;
  bottom: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.hud-pill {
  pointer-events: auto;
  background: rgba(255, 253, 249, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.hud-coords {
  min-width: 190px;
}

.coords-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: transparent;
  flex-shrink: 0;
}

.hud-dimensions {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink);
}

.hud-zoom {
  padding: 3px 8px;
  gap: 4px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-parchment);
}

.zoom-label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  min-width: 42px;
  text-align: center;
  color: var(--ink);
}

.text-btn {
  border: none;
  background: var(--bg-parchment);
  color: var(--ink);
  font-size: 0.73rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  margin-left: 2px;
}

.text-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* ===== RIGHT INSPECTOR PANEL ===== */
.inspector {
  width: 344px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-linen);
  padding: 6px 6px 0;
  gap: 4px;
  flex-shrink: 0;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-header h3 {
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
}

.badge-soft {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sage);
  background: var(--sage-soft);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.helper-text {
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

/* Upload Box */
.upload-box {
  border: 1.8px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-linen);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.16s ease;
}

.upload-box:hover,
.upload-box:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.upload-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.upload-icon svg {
  width: 22px;
  height: 22px;
}

.upload-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
}

.upload-sub {
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.upload-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.upload-preview img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.upload-preview-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.source-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-replace-hint {
  font-size: 0.74rem;
  color: var(--accent);
  margin-top: 2px;
}

.starter-row {
  margin-top: 10px;
}

.starter-label {
  display: block;
  font-size: 0.73rem;
  color: var(--ink-subtle);
  margin-bottom: 6px;
  font-weight: 600;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.14s;
}

.chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-soft);
}

/* Form Controls */
.control-row {
  margin-bottom: 12px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row > label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 5px;
}

.control-label-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

.control-label-line label {
  font-weight: 600;
  color: var(--ink-muted);
}

.control-label-line strong,
.control-label-line span {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink);
}

.muted-small {
  font-family: var(--font-sans) !important;
  color: var(--ink-subtle) !important;
  font-size: 0.72rem !important;
}

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

.select-input,
.num-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--ink);
}

.select-input:focus,
.num-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 109, 81, 0.14);
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pill-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-parchment);
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 3px;
}

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

.badge-loom {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-hover);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.loom-panel {
  background: var(--bg-linen);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  margin-bottom: 12px;
}

.pill-opt {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s;
}

.pill-opt.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-row label {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}

.toggle-row small {
  font-weight: 400;
  font-size: 0.71rem;
  color: var(--ink-subtle);
}

.switch {
  appearance: none;
  width: 38px;
  height: 22px;
  background: var(--border-strong);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: background 0.18s;
  flex-shrink: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s;
}

.switch:checked {
  background: var(--accent);
}

.switch:checked::after {
  transform: translateX(16px);
}

.control-actions-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.gauge-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-linen);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  margin: 12px 0;
  text-align: center;
}

.gauge-label {
  display: block;
  font-size: 0.68rem;
  color: var(--ink-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.gauge-summary strong {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
}

/* ===== PALETTE LIST ===== */
.palette-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.14s;
}

.palette-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.palette-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.palette-code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-subtle);
  width: 18px;
  text-align: center;
}

.palette-swatch-wrap {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(45, 36, 30, 0.2);
  flex-shrink: 0;
}

.palette-swatch-input {
  position: absolute;
  inset: -6px;
  width: 42px;
  height: 42px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
}

.palette-info {
  flex: 1;
  min-width: 0;
}

.palette-name-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  width: 100%;
  padding: 1px 4px;
  border-radius: 4px;
}

.palette-name-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

.palette-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  padding-left: 4px;
}

.palette-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.palette-action-btn {
  border: none;
  background: transparent;
  color: var(--ink-subtle);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.palette-action-btn:hover {
  background: rgba(45, 36, 30, 0.08);
  color: var(--ink);
}

.yarn-library-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.yarn-lib-swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(45, 36, 30, 0.16);
  cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s;
}

.yarn-lib-swatch:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ===== ROW GUIDE ===== */
.row-progress-wrap {
  margin-top: 4px;
}

.row-progress-bar {
  height: 7px;
  background: var(--bg-parchment);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 5px;
}

.row-progress-fill {
  height: 100%;
  background: var(--sage);
  border-radius: 99px;
  transition: width 0.2s ease;
}

.row-progress-label {
  font-size: 0.74rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.row-guide-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.14s;
}

.row-card:hover {
  border-color: var(--border-strong);
}

.row-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.row-card.done {
  opacity: 0.62;
  background: var(--bg-linen);
}

.row-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.row-card-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.row-card-title {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink);
}

.row-dir-tag {
  font-size: 0.68rem;
  color: var(--ink-subtle);
  background: var(--bg-parchment);
  padding: 1px 6px;
  border-radius: 99px;
}

.row-runs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.run-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  background: var(--bg-linen);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--ink);
}

.run-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* ===== MODALS ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 36, 30, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal-lg {
  max-width: 720px;
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink);
}

.modal-sub {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.icon-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-parchment);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.icon-close:hover {
  background: var(--border);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.projects-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 12px;
}

.project-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-linen);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
}

.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.project-card.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.project-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.project-thumb img {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.project-card-body {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.project-card-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-card-meta {
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.project-delete-btn {
  border: none;
  background: transparent;
  color: var(--ink-subtle);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.88rem;
}

.project-delete-btn:hover {
  background: rgba(185, 55, 45, 0.12);
  color: #b5372d;
}

/* Export options */
.export-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-checks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.export-option-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
  color: var(--ink);
  cursor: pointer;
}

.export-option-check input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.export-preview-box {
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.export-preview-box img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: #fffdf9;
  box-shadow: var(--shadow-sm);
}

.export-preview-hint {
  font-size: 0.72rem;
  color: var(--ink-subtle);
}

.export-cards {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.export-card-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.export-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg-linen);
  cursor: pointer;
  transition: all 0.15s;
}

.export-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.export-card-icon {
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.export-card strong {
  display: block;
  font-size: 0.86rem;
  color: var(--ink);
}

.export-card span {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Printable Pattern Sheet Modal */
.modal-print-sheet {
  max-width: 900px;
  max-height: 92vh;
}

.print-sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.print-sheet-body {
  background: #fffdf9;
}

.print-sheet-chart {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.print-sheet-heading {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin-bottom: 12px;
  color: var(--ink);
}

.print-sheet-rows {
  display: flex;
  flex-direction: column;
}

.print-row-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--bg-canvas);
  font-size: 0.82rem;
  break-inside: avoid;
}

.print-row-num {
  min-width: 118px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
  flex-shrink: 0;
}

.print-row-num small {
  font-weight: 400;
  color: var(--ink-subtle);
}

.print-row-runs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.print-run-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-linen);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.78rem;
}

.print-run-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

/* Print Stylesheet: print ONLY the clean pattern sheet */
@media print {
  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .app-shell,
  .toast,
  .modal-backdrop:not(#printSheetModal),
  .no-print {
    display: none !important;
  }

  #printSheetModal {
    position: static !important;
    background: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    display: block !important;
  }

  .modal-print-sheet {
    max-width: none !important;
    max-height: none !important;
    box-shadow: none !important;
    border: none !important;
    overflow: visible !important;
  }

  .print-sheet-body {
    overflow: visible !important;
    padding: 0 !important;
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fffdf9;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.83rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Responsive tweaks */
@media (max-width: 980px) {
  .topbar-center {
    display: none;
  }
  .inspector {
    width: 300px;
  }
  .hud-dimensions {
    display: none;
  }
}

/* ===== Shared: visually hidden text ===== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== Shared: upgrade / unlock prompt (demo + member studio) ===== */
.gate-card {
  position: relative;
  max-width: 440px;
  padding: 30px 28px 24px;
  text-align: center;
  align-items: center;
}

.gate-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.gate-lock {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 12px;
}

.gate-lock svg {
  width: 26px;
  height: 26px;
}

.gate-card h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.gate-text {
  color: var(--ink-muted);
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 8px 0 18px;
}

.gate-plans {
  list-style: none;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.gate-plans li {
  display: grid;
  gap: 2px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.gate-plans li.featured {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.gate-plans strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--ink);
}

.gate-plans small {
  font-size: 0.68rem;
}

.gate-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.gate-actions .btn {
  text-decoration: none;
}


.gate-actions button.btn,
.gate-actions a.btn {
  text-decoration: none;
}

.gate-note {
  font-size: 0.8rem;
  color: var(--ink-subtle);
  margin: -8px 0 16px;
}

/* ===== Member studio: hide the workspace until sign-in is confirmed ===== */
body[data-mode='member']:not(.member-ready) .app-shell {
  visibility: hidden;
}

body[data-mode='member']:not(.member-ready)::after {
  content: 'Opening your studio…';
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink-muted);
}

.member-account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.member-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  overflow: hidden;
}

.member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.save-indicator.is-error {
  background: #fbe4df;
  color: #9b4532;
}
