/* ── Mobile-first styles for Ant Typography Studio ── */
* { margin: 0; box-sizing: border-box; }
html, body {
  height: 100%; width: 100%;
  overflow: auto;
  background: #0a0a0f;
  color: #eee;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Canvas: full-screen behind everything ── */
#canvas-container {
  /* NOTE: overflow must be auto for pan/scroll */
  position: fixed; inset: 0;
  overflow: auto;
  z-index: 1;
  background: #0a0a0f;
}
#canvas-container canvas {
  display: block; border: none; margin: 0;
  transform-origin: top left;
}

/* ── FAB (Floating Action Button) ── */
#fab-mode {
  position: fixed;
  right: 16px;
  z-index: 30;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px solid #555;
  background: #1a1f28;
  color: #eee;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transition: background 0.15s, border-color 0.15s;
}
#fab-mode.draw-mode {
  background: #2a4a2a;
  border-color: #4a8a4a;
}
#fab-mode.draw-mode #fab-icon::after {
  content: '';
}

/* ── Bottom Sheet ── */
#bottom-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: #111419;
  border-top: 1px solid #3a4048;
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  height: 48px; /* collapsed default */
  max-height: 90vh;
  will-change: height;
}
#bottom-sheet.half { height: 42vh; }
#bottom-sheet.expanded { height: 85vh; }
#bottom-sheet.dragging { transition: none; }

/* ── Drag Handle ── */
#sheet-handle {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  height: 20px;
  cursor: grab;
  touch-action: none;
}
.handle-bar {
  width: 40px; height: 4px;
  background: #555;
  border-radius: 2px;
}

/* ── Mini-bar ── */
#mini-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 6px;
  min-height: 28px;
  overflow-x: auto;
  scrollbar-width: none;
}
#mini-bar::-webkit-scrollbar { display: none; }
#mini-bar button, #mini-bar select {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #555;
  background: #1e2228;
  color: #ddd;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
  flex-shrink: 0;
}
#mini-bar button:active { background: #151920; }
#mini-bar .mini-select {
  max-width: 120px;
  min-height: 32px;
}
#mini-bar .mini-label {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Tab Bar ── */
#tab-bar {
  flex-shrink: 0;
  display: flex;
  gap: 2px;
  padding: 0 8px 4px;
  border-bottom: 1px solid #2a2f38;
}
.tab-btn {
  flex: 1;
  font-size: 11px;
  padding: 6px 4px;
  border: 1px solid #444;
  background: #1e2228;
  color: #999;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  text-align: center;
  min-height: 34px;
}
.tab-btn.active {
  background: #272c34;
  color: #eef3ff;
  border-color: #555;
  border-bottom-color: #272c34;
}

/* ── Tab Content ── */
#tab-content {
  flex: 1;
  overflow: auto;
  position: relative;
}
.tab-pane {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 10px 20px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #566070 #151a22;
}
.tab-pane.active { display: block; }
.tab-pane::-webkit-scrollbar { width: 6px; }
.tab-pane::-webkit-scrollbar-track { background: #151a22; }
.tab-pane::-webkit-scrollbar-thumb { background: #566070; border-radius: 3px; }

/* ── Section Cards ── */
.section-card {
  margin-bottom: 8px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 8px 10px;
  background: #272c34;
}
.section-card h4 {
  font-size: 10px;
  color: #d6ddeb;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  border-bottom: 1px solid #4b5563;
  padding-bottom: 3px;
}

/* ── Tool Grid (Draw/Erase) ── */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.tool-col-head {
  font-size: 10px;
  color: #aab3bf;
  text-align: center;
  border: 1px solid #444b55;
  border-radius: 4px;
  padding: 4px 0;
  background: #2b313a;
}

/* ── Toggle Grid (View toggles) ── */
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

/* ── Clear Grid ── */
.clear-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

/* ── Buttons (shared) ── */
.mode-btn, .clear-btn {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 11px;
  padding: 8px 8px;
  border: 1px solid #555;
  background: #1e2228;
  color: #ddd;
  border-radius: 6px;
  cursor: pointer;
  min-height: 36px;
}
.mode-btn:active, .clear-btn:active { background: #151920; }
.mode-btn.active {
  background: #151920;
  color: #eef3ff;
  border-color: #0f1217;
}

/* ── Panel Grid / Rows (reused from desktop for sim/colors/rec tabs) ── */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
.panel-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  min-height: 36px;
}
.panel-row label {
  font-size: 11px;
  white-space: nowrap;
  min-width: 90px;
}
.panel-row input[type="range"] {
  flex: 1;
  min-width: 60px;
  height: 28px;
}
.panel-row input[type="number"] {
  width: 60px;
  font-size: 11px;
  padding: 4px 6px;
  background: #1a1e24;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  min-height: 32px;
}
.panel-row input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1px solid #555;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 0;
}
.panel-row select {
  font-size: 11px;
  padding: 4px 6px;
  background: #1a1e24;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  min-height: 32px;
}
.panel-row button {
  font-size: 11px;
  padding: 6px 10px;
  border: 1px solid #555;
  background: #1e2228;
  color: #ddd;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  min-height: 36px;
}
.panel-row button:active { background: #151920; }
.panel-row button.active {
  background: #151920;
  color: #eef3ff;
  border-color: #0f1217;
}
.panel-toggle-btn {
  width: 100%;
  padding: 6px 10px;
  min-height: 36px;
}
.panel-toggle-btn.active {
  background: #151920;
  color: #eef3ff;
  border-color: #0f1217;
}
.panel-row span[id$="-val"] {
  min-width: 30px;
  text-align: right;
  font-size: 11px;
  color: #bbb;
}

/* ── Ctrl Row (flex row for buttons/inputs) ── */
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  font-size: 11px;
}
.ctrl-row label {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctrl-row input[type="text"],
.ctrl-row input[type="number"] {
  font-size: 11px;
  padding: 4px 6px;
  background: #1a1e24;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  min-height: 32px;
}
.ctrl-row select {
  font-size: 11px;
  padding: 4px 6px;
  background: #1a1e24;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  min-height: 32px;
}
.ctrl-row button {
  font-size: 11px;
  padding: 6px 10px;
  border: 1px solid #555;
  background: #1e2228;
  color: #ddd;
  border-radius: 6px;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
}
.ctrl-row button:active { background: #151920; }

/* ── HUD Cards ── */
.hud-card {
  border: 1px solid #444b55;
  border-radius: 6px;
  padding: 6px 8px;
  background: #2a3038;
  color: #e7eef9;
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 4px;
}
.hud-title { color: #b7c9e3; font-size: 10px; margin-bottom: 2px; }
.hud-row {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  white-space: nowrap;
  overflow: auto;
  text-overflow: ellipsis;
}

/* ── Text Align Group ── */
.text-align-group {
  display: inline-flex;
  gap: 2px;
}
.text-align-btn {
  min-width: 32px;
  padding: 6px 8px;
  font-size: 11px;
  border: 1px solid #555;
  background: #1e2228;
  color: #ddd;
  border-radius: 4px;
  cursor: pointer;
  min-height: 36px;
}
.text-align-btn.active {
  background: #151920;
  color: #eef3ff;
  border-color: #0f1217;
}

/* ── Sliders (dynamically built by ui-sliders.js) ── */
#sliders {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slider-block {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  min-height: 36px;
}
.slider-block label { min-width: 90px; }
.slider-block input { flex: 1; height: 28px; }
.slider-block .val { min-width: 30px; text-align: right; }

/* ── Range inputs ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 28px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #555;
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #aaa;
  margin-top: -8px;
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: #555;
  border-radius: 2px;
  border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #aaa;
  border: none;
  cursor: pointer;
}

/* ── Swatch color picker (reused from desktop) ── */
.swatch-picker { position: relative; display: inline-block; }
.swatch-btn {
  width: 28px; height: 24px;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
.swatch-btn:hover { border-color: #999; }
.swatch-dropdown {
  display: none; position: absolute; top: 100%; left: 0;
  z-index: 130;
  background: #222; border: 1px solid #555;
  border-radius: 6px; padding: 6px; width: 180px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.swatch-dropdown.open { display: block; }
.swatch-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.swatch-cell {
  width: 26px; height: 22px;
  border: 1px solid #444; border-radius: 3px;
  cursor: pointer; padding: 0;
}
.swatch-cell:hover { border-color: #fff; }
.swatch-custom-btn {
  display: block; width: 100%; margin-top: 4px;
  font-size: 10px; padding: 4px;
  background: #333; color: #aaa; border: 1px solid #555;
  border-radius: 4px; cursor: pointer; text-align: center;
}

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
  z-index: 50;
}
.modal.open { display: flex; }
.modal-card {
  width: min(95vw, 700px);
  max-height: 85vh;
  overflow: auto;
  background: #1a1a1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 14px;
  color: #ddd;
}
.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-top h2 { font-size: 16px; }
.notes-pre {
  white-space: pre-wrap; font-size: 12px; line-height: 1.45;
  color: #ccc; background: #111; border: 1px solid #333;
  border-radius: 6px; padding: 10px;
}

/* ── Color Preview Modal (MiniSim) — mobile stacked layout ── */
#color-preview-modal {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
  background: rgba(0,0,0,0.92);
  z-index: 100;
}
#color-preview-modal.open { display: flex; }
.color-preview-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  background: #1a1a1e;
}
.color-preview-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}
.color-preview-top h2 { font-size: 14px; }
.color-preview-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
  padding: 8px;
  gap: 8px;
}
.color-preview-left {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
#color-preview-canvas {
  width: 100%;
  max-width: 400px;
  height: 200px;
  border: 1px solid #555;
  background: #0a0a0f;
}
.preview-info { font-size: 10px; color: #888; text-align: center; }
.color-preview-right {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  padding-right: 4px;
}
.preview-control-split {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow: auto;
}
.preview-controls-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 50vh;
  padding-right: 4px;
}
.preview-controls-col .panel-section { margin-bottom: 0; }
.color-preview-footer {
  display: flex; gap: 8px;
  justify-content: flex-end; align-items: center;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-top: 1px solid #333;
  flex-shrink: 0;
}
.color-preview-footer button, .color-preview-top button {
  font-size: 12px; padding: 6px 12px;
  border: 1px solid #555; background: #1e2228; color: #ddd;
  border-radius: 6px; cursor: pointer;
  min-height: 36px;
}
.color-preview-footer button:active, .color-preview-top button:active {
  background: #151920;
}
/* MiniSim panel rows — single column on mobile */
#color-preview-modal .panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  font-size: 11px;
}
#color-preview-modal .panel-row > label:first-child {
  min-width: 100px;
  white-space: nowrap;
}
#color-preview-modal .panel-row input[type="range"] {
  flex: 1;
  min-width: 80px;
  height: 28px;
}
#color-preview-modal .panel-grid {
  grid-template-columns: 1fr;
  gap: 4px;
}
#color-preview-modal .panel-row span[id$="-val"] {
  min-width: 30px;
  text-align: right;
}
#color-preview-modal .panel-row.preview-checkbox-row {
  display: flex;
}
#color-preview-modal .panel-row.preview-checkbox-row > .panel-toggle-btn {
  width: 100%;
}
#color-preview-modal .panel-row.preview-presets-row {
  flex-wrap: wrap;
}
#color-preview-modal .preview-swatch-slot { display: none; }
#color-preview-modal .preview-swatch-pair {
  display: inline-flex; gap: 4px; align-items: center;
}
#color-preview-modal .swatch-dropdown { z-index: 130; }
.panel-section {
  margin-bottom: 6px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 8px 10px;
  background: #272c34;
}
.panel-section h4 {
  font-size: 10px;
  color: #d6ddeb;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  border-bottom: 1px solid #4b5563;
  padding-bottom: 2px;
}
#preview-user-preset-msg {
  font-size: 9px; color: #999;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#preview-copy-status {
  font-size: 10px; color: #9ad3ff;
  min-width: 70px; text-align: left;
}

/* ── Tool indicator overlay on canvas ── */
#tool-indicator {
  position: fixed;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(0,0,0,0.7);
  color: #eee;
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
#tool-indicator.visible { opacity: 1; }

/* ── Misc ── */
#tick-display, #model-info { font-size: 10px; color: #888; margin-top: 4px; }
#model-info a { color: #6e8efb; }
#render-progress { font-size: 11px; color: #8cf; margin: 4px 0; }
#render-memory-hint { font-size: 10px; color: #666; margin: 2px 0; }
#grid-cell-count { font-size: 10px; color: #666; }
@keyframes hint-flash {
  0% { background: #6e8efb; color: #fff; }
  100% { background: #1e2228; color: #ddd; }
}
.hint-flash { animation: hint-flash 1.5s ease-out; }
#btn-record.active {
  background: #d32f2f; border-color: #d32f2f;
  animation: rec-pulse 1.2s infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.7; }
}

/* ── Safe area padding for notched devices ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #bottom-sheet { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Landscape adjustments ── */
@media (orientation: landscape) and (max-height: 500px) {
  #bottom-sheet { max-height: 70vh; }
  #bottom-sheet.half { height: 50vh; }
  #bottom-sheet.expanded { height: 70vh; }
  #fab-mode { width: 44px; height: 44px; font-size: 18px; }
}

/* ── Larger tablet (iPad) ── */
@media (min-width: 768px) {
  .tool-grid { grid-template-columns: 1fr 1fr; }
  .toggle-grid { grid-template-columns: 1fr 1fr 1fr; }
  .clear-grid { grid-template-columns: 1fr 1fr 1fr; }
  .panel-row label { min-width: 110px; }
  #color-preview-canvas { height: 280px; }
}

/* Hide scrollbars on canvas container while keeping scroll functional */
#canvas-container::-webkit-scrollbar { width: 0; height: 0; display: none; }
#canvas-container { -ms-overflow-style: none; scrollbar-width: none; }
