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

:root {
  --bg: #ffffff;
  --fg: #000000;
  --border: #d0d0d0;
  --border-hover: #a0a0a0;
  --border-active: #000000;
  --panel-bg: #fafafa;
  --hover-bg: #f0f0f0;
  --active-bg: #e8e8e8;
  --suggestion: rgba(0, 0, 0, 0.15);
  --radius: 4px;
}

body {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace;
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.5;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  gap: 20px;
}

.header h1 {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

.btn:active {
  background: var(--active-bg);
}

.btn-secondary {
  background: var(--panel-bg);
}

.btn-xs {
  font-size: 10px;
  padding: 3px 7px;
  height: 24px;
}

.grid-apply-btns {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

/* Grid Controls */
.grid-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.control-row label {
  font-size: 12px;
  color: #666;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--bg);
}

.btn-stepper {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--panel-bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 16px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-family: inherit;
}

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

.btn-stepper:active {
  background: var(--active-bg);
}

.stepper span {
  min-width: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
}

.cell-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: 0.3s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--fg);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--active-bg);
  border-color: var(--border-active);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* Main Layout */
.main {
  display: grid;
  grid-template-columns: 240px 1fr 260px;
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 61px);
  transition: grid-template-columns 0.3s ease;
}

.main:has(.alphabet.collapsed) {
  grid-template-columns: 240px 1fr 0px;
}

/* Panels */
.sidebar, .editor, .alphabet {
  background: var(--bg);
  padding: 20px 16px;
}

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

.panel:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.panel h2 {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  color: #666;
}

/* Form Elements */
.select, .input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.select:focus, .input:focus {
  outline: none;
  border-color: var(--border-active);
}

/* Editor */
.editor {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 32px 24px;
}

.editor-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  margin-bottom: 16px;
}

.current-letter {
  font-size: 36px;
  font-weight: 500;
  letter-spacing: -2px;
}

.grid-info {
  font-size: 11px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.canvas-container {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

#editorCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* Shape Palette */
.shape-palette {
  display: none;
}

/* Preview */
.preview-canvas-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel-bg);
}

#previewCanvas {
  width: 100%;
  display: block;
}

/* Alphabet Grid */
.alphabet {
  overflow: visible;
  position: relative;
  transition: width 0.3s ease, padding 0.3s ease;
  width: 330px;
}

.alphabet.collapsed {
  width: 0;
  padding: 0;
  border-left: none;
}

.alphabet-toggle {
  position: absolute;
  left: -32px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 64px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  z-index: 10;
}

.alphabet-toggle:hover {
  background: var(--hover-bg);
}

.toggle-arrow {
  font-size: 16px;
  transition: transform 0.3s ease;
}

.alphabet.collapsed .toggle-arrow {
  transform: rotate(180deg);
}

.alphabet-content {
  opacity: 1;
  transition: opacity 0.3s ease;
}

.alphabet.collapsed .alphabet-content {
  opacity: 0;
  pointer-events: none;
}

.alphabet h2 {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  color: #666;
}

.alphabet-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.letter-card {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.letter-card:hover {
  border-color: var(--border-hover);
  background: var(--hover-bg);
}

.letter-card.active {
  border-color: var(--border-active);
  background: var(--active-bg);
}

.letter-card-header {
  font-size: 9px;
  font-weight: 500;
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.letter-name {
  font-weight: 600;
}

.letter-status {
  font-size: 7px;
  color: #999;
}

.letter-card canvas {
  width: 100%;
  flex: 1;
  display: block;
}

/* Context Menu */
.context-menu {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  padding: 4px;
  min-width: 200px;
}

.context-menu-content {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.context-menu-item {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 8px;
}

.context-menu-item:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

.context-menu-item canvas {
  width: 100%;
  height: 100%;
}

/* Responsive */
@media (max-width: 1200px) {
  .main {
    grid-template-columns: 220px 1fr;
  }
  
  .main:has(.alphabet.collapsed) {
    grid-template-columns: 220px 1fr;
  }
  
  .alphabet {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    width: 100%;
  }
  
  .alphabet.collapsed {
    display: none;
  }
  
  .alphabet-toggle {
    display: none;
  }
  
  .alphabet-grid {
    grid-template-columns: repeat(9, 1fr);
  }
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
  }
  
  .header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .header-actions {
    width: 100%;
    justify-content: stretch;
  }
  
  .header-actions .btn {
    flex: 1;
  }
}

/* Color Input */
.color-input {
  width: 60px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: var(--bg);
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.color-input::-moz-color-swatch {
  border: none;
  border-radius: 3px;
}

/* Header Navigation */
.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  text-decoration: none;
  color: #666;
  font-size: 12px;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--fg);
  background: var(--hover-bg);
}

.nav-link.active {
  color: var(--fg);
  background: var(--active-bg);
  font-weight: 500;
}

/* Letter Navigation */
.letter-navigation {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.btn-nav {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-nav:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

.btn-nav:active {
  background: var(--active-bg);
}

.select-compact {
  flex: 1;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  background: var(--bg);
}

.footer-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
}

.btn-primary:hover {
  background: #333;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: var(--bg);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 500;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.modal-close:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Community Page */
.community-main {
  padding: 32px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.community-header {
  margin-bottom: 32px;
}

.community-subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
}

.community-filters {
  display: flex;
  gap: 12px;
}

.community-filters .input {
  flex: 1;
  margin-bottom: 0;
}

.community-filters .select {
  width: 200px;
  margin-bottom: 0;
}

.fonts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.font-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.15s ease;
  background: var(--bg);
}

.font-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.font-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.font-card-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.font-card-author {
  font-size: 12px;
  color: #666;
}

.font-card-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel-bg);
  margin-bottom: 12px;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.font-card-preview canvas {
  max-width: 100%;
}

.font-card-description {
  font-size: 13px;
  color: #666;
  margin-bottom: 12px;
  line-height: 1.4;
}

.font-card-actions {
  display: flex;
  gap: 8px;
}

.font-card-actions .btn {
  flex: 1;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #999;
}

.empty-state p:first-child {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state .hint {
  font-size: 14px;
  margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .header-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .footer-actions {
    flex-direction: column;
  }
  
  .footer-actions .btn {
    width: 100%;
  }
  
  .community-filters {
    flex-direction: column;
  }
  
  .community-filters .select {
    width: 100%;
  }
  
  .fonts-grid {
    grid-template-columns: 1fr;
  }
}

/* Color Input */
.color-input {
  width: 60px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: var(--bg);
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.color-input::-moz-color-swatch {
  border: none;
  border-radius: 3px;
}

/* Header con navegación */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius);
  text-decoration: none;
  color: #666;
  font-size: 12px;
  transition: all 0.15s ease;
}

.nav-link:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

.nav-link.active {
  background: var(--active-bg);
  color: var(--fg);
  font-weight: 500;
}

/* Navegación de letras */
.letter-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.btn-arrow {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-family: inherit;
  color: var(--fg);
}

.btn-arrow:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

.btn-arrow:active {
  background: var(--active-bg);
}

.select-letter {
  flex: 1;
  height: 40px;
}

/* Editor actions */
.editor-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.btn-primary:hover {
  background: #333;
  border-color: #333;
}

.btn-primary:active {
  background: #000;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-height: 90vh;
  overflow: auto;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 28px;
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  line-height: 1;
  padding: 0;
}

.modal-close:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #666;
  margin-bottom: 8px;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.form-group .hint {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Página de comunidad */
.community-main {
  padding: 32px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.community-header {
  margin-bottom: 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}

.community-subtitle {
  font-size: 14px;
  color: #666;
  margin: 0;
}

.community-actions {
  display: flex;
  gap: 8px;
}

.fonts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.font-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg);
  transition: all 0.15s ease;
}

.font-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.font-card-header {
  margin-bottom: 16px;
}

.font-card-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.font-card-author {
  font-size: 12px;
  color: #666;
}

.font-card-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--panel-bg);
  margin-bottom: 12px;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.font-card-preview canvas {
  max-width: 100%;
  height: auto;
}

.font-card-description {
  font-size: 13px;
  color: #666;
  margin-bottom: 16px;
  line-height: 1.5;
}

.font-card-actions {
  display: flex;
  gap: 8px;
}

.font-card-actions .btn {
  flex: 1;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 100px 20px;
}

.empty-state p:first-child {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 8px;
}

.empty-subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 32px;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .header-nav {
    width: 100%;
  }
  
  .nav-link {
    flex: 1;
    text-align: center;
  }
  
  .editor-actions {
    flex-direction: column;
  }
  
  .editor-actions .btn {
    width: 100%;
  }
  
  .community-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .fonts-grid {
    grid-template-columns: 1fr;
  }
}
/* ===================================================
   EDITOR APP LAYOUT  (body.editor-app — index.html)
   =================================================== */

body.editor-app {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 20px;
}

.topbar-title {
  font-size: 11px;
  font-weight: 500;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.topbar-nav .nav-link {
  padding: 5px 12px;
  font-size: 11px;
}

/* ── Main area: editor + alphabet ── */
.editor-main {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--bg);
}

body.editor-app .editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  gap: 0;
  background: var(--bg);
}

body.editor-app .editor-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

body.editor-app .canvas-container {
  /* Aspect-ratio is set dynamically by JS to match the grid cols/rows */
  width: min(calc(100vh - 180px), calc(100% - 16px));
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

/* Alphabet panel: fill full height */
body.editor-app .alphabet {
  border-left: 1px solid var(--border);
  overflow: visible; /* keep toggle button visible outside bounds */
  display: flex;
  flex-direction: column;
}

body.editor-app .alphabet-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* clip grid, not the toggle */
}

body.editor-app .alphabet-content h2 {
  flex-shrink: 0;
}

body.editor-app .alphabet-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

body.editor-app .alphabet-tab {
  flex: 1;
  padding: 7px 0;
  font-size: 10px;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #999;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

body.editor-app .alphabet-tab:hover {
  color: var(--fg);
}

body.editor-app .alphabet-tab.active {
  color: var(--fg);
  border-bottom-color: var(--fg);
}

/* Alternativas: card de añadir */
body.editor-app .alt-add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

body.editor-app .alt-add-card:hover {
  border-color: var(--fg);
  background: var(--hover-bg);
}

body.editor-app .alt-add-icon {
  font-size: 22px;
  font-weight: 300;
  color: #aaa;
  line-height: 1;
}

body.editor-app .alt-add-card:hover .alt-add-icon {
  color: var(--fg);
}

/* Hide moved editor-actions */
body.editor-app .editor-actions {
  display: none;
}

/* ── Bottom bar ── */
.bottombar {
  display: flex;
  align-items: center;
  height: 56px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.bar-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  height: 100%;
  border-right: 1px solid var(--border);
  flex: 1;
}

.bar-group-preview {
  flex: 1;
  min-width: 140px;
  max-width: 300px;
}

.bar-actions {
  border-right: none;
  flex: none;
  gap: 8px;
  padding: 0 20px;
}

.bar-label {
  font-size: 10px;
  color: #bbb;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.bar-hint {
  font-size: 16px;
  color: #ddd;
  font-weight: 300;
}

.bar-sub {
  font-size: 10px;
  color: #999;
  white-space: nowrap;
}

/* Compact steppers inside bottom bar */
.bottombar .stepper {
  padding: 2px 4px;
  gap: 4px;
}

.bottombar .btn-stepper {
  width: 20px;
  height: 20px;
  font-size: 13px;
}

.bottombar .stepper span {
  min-width: 14px;
  font-size: 12px;
}

/* Letter nav */
.bottombar .letter-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0;
}

.bottombar .btn-arrow {
  width: 26px;
  height: 26px;
  font-size: 12px;
}

.bottombar .select-letter {
  height: 26px;
  width: 60px;
  padding: 2px 4px;
  font-size: 12px;
  margin-bottom: 0;
}

/* Buttons in bottom bar */
.bottombar .btn {
  padding: 5px 10px;
  font-size: 11px;
}

/* Compact select for brush/cell */
.select-sm {
  height: 26px;
  padding: 2px 6px;
  font-size: 12px;
  width: auto;
  min-width: 80px;
  margin-bottom: 0;
}

/* Color input in bottom bar */
.bottombar .color-input {
  width: 26px;
  height: 26px;
}

/* brushControls: show as flex row when visible */
.bottombar #brushControls:not([style*="none"]) {
  display: flex !important;
  align-items: center;
  gap: 6px;
}
.bottombar #brushControls {
  margin-top: 0 !important;
}

/* proportionsControls: show as flex row when visible */
.bottombar #proportionsControls:not([style*="none"]) {
  display: flex !important;
  align-items: center;
  gap: 6px;
}
.bottombar #proportionsControls {
  margin-top: 0 !important;
}

/* cellControls: show as flex row when visible */
.bottombar #cellControls:not([style*="none"]) {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
}

/* Preview strip */
.input-mini {
  padding: 4px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
  border-radius: var(--radius);
  width: 96px;
  height: 26px;
}

.input-mini:focus {
  outline: none;
  border-color: var(--border-active);
}

.preview-canvas-wrap-mini {
  flex: 1;
  height: 36px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  display: flex;
  align-items: center;
}

.preview-canvas-wrap-mini canvas {
  height: 100%;
  width: auto;
  display: block;
}

/* Alphabet grid: columns + row height set dynamically by JS */
body.editor-app .alphabet-grid {
  flex: 1;
  min-height: 0;
  grid-template-columns: repeat(4, 1fr); /* overridden by updateAlphabetLayout() */
  grid-auto-rows: 1fr;
  gap: 3px;
  overflow: hidden;
}

/* Invisible spacer to complete the last row (no orphaned card) */
.placeholder-card {
  visibility: hidden;
  min-height: 0;
}

/* Cards fill their grid cell — canvas covers the whole card */
body.editor-app .letter-card {
  aspect-ratio: unset;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  position: relative;
}

/* Canvas fills the full card */
body.editor-app .letter-card canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* Overlay: invisible by default, appears on hover */
body.editor-app .letter-card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.82);
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

body.editor-app .letter-card:hover .letter-card-overlay {
  opacity: 1;
}

body.editor-app .letter-card.active .letter-card-overlay {
  opacity: 1;
  background: rgba(0, 0, 0, 0.55);
}

body.editor-app .letter-card.active .letter-card-overlay .letter-name,
body.editor-app .letter-card.active .letter-card-overlay .letter-status {
  color: #fff;
}

body.editor-app .letter-card-overlay .letter-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--fg);
}

body.editor-app .letter-card-overlay .letter-status {
  font-size: 8px;
  color: #888;
}

/* ========================================
   COMMUNITY APP
   ======================================== */

body.community-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sticky controls bar below topbar */
.community-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.sample-input {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  background: var(--panel-bg);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s;
}

.sample-input:focus {
  border-color: var(--border-active);
}

/* Scrollable font list */
.font-list {
  flex: 1;
  overflow-y: auto;
}

/* Individual font entry */
.font-entry {
  padding: 28px 32px;
  border-bottom: 1px solid var(--border);
}

.font-entry:last-child {
  border-bottom: none;
}

.font-entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.font-entry-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Font name rendered in the actual font */
.font-entry-name {
  font-size: 52px;
  line-height: 1;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.font-entry-meta {
  font-size: 11px;
  color: #999;
  font-family: 'SF Mono', 'Monaco', monospace;
}

.font-entry-download {
  flex-shrink: 0;
  margin-top: 8px;
}

/* Sample text (global input drives this) */
.font-entry-sample {
  font-size: 30px;
  line-height: 1.35;
  color: var(--fg);
  margin-bottom: 10px;
  word-break: break-word;
}

/* Alphabet specimen row */
.font-entry-alphabet {
  font-size: 16px;
  color: #aaa;
  letter-spacing: 0.05em;
  word-break: break-all;
}

/* Empty state */
.community-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  text-align: center;
  color: #999;
}

.community-empty-icon {
  font-size: 48px;
  color: var(--border);
}

.community-empty-title {
  font-size: 15px;
  color: var(--fg);
}

.community-empty-sub {
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
}

/* ── Brush shape graphical picker ── */
.shape-picker {
  display: flex;
  gap: 4px;
  align-items: center;
}

.shape-btn {
  width: 28px;
  height: 28px;
  padding: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.shape-btn:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

.shape-btn.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.shape-btn svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Eraser button active state */
#btnEraser.active {
  background: #ff5050;
  color: #fff;
  border-color: #ff5050;
}
#btnEraser.active:hover {
  background: #e04040;
  border-color: #e04040;
}

/* Canvas cursor when eraser is active */
.eraser-cursor {
  cursor: cell;
}

/* ── Preview button in bottombar ── */
.btn-preview-open {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-preview-open:hover {
  background: var(--hover-bg);
  border-color: var(--border-hover);
}

/* ── Preview Overlay ── */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.preview-overlay.open {
  transform: translateY(0);
  pointer-events: all;
}

.preview-overlay-topbar {
  display: flex;
  align-items: center;
  height: 56px;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
}

.preview-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.preview-close:hover {
  background: var(--hover-bg);
}
.preview-close svg {
  display: block;
}

.preview-overlay-title {
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.preview-size-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
}
.preview-size-controls #fontSizeLabel {
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.preview-overlay-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 32px 40px;
  position: relative;
}

#previewOverlayCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.preview-empty-hint {
  position: absolute;
  font-size: 13px;
  color: #ccc;
  pointer-events: none;
  text-align: center;
}

.preview-overlay-input-row {
  padding: 20px 40px 28px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-overlay-input {
  width: 100%;
  font-family: inherit;
  font-size: 22px;
  border: none;
  border-bottom: 2px solid var(--border);
  outline: none;
  background: transparent;
  color: var(--fg);
  padding: 8px 0;
  letter-spacing: 0.2px;
  transition: border-color 0.15s;
}
.preview-overlay-input:focus {
  border-bottom-color: var(--fg);
}
.preview-overlay-input::placeholder {
  color: #ddd;
}
