/* ─── NOMULAN — Конструктор цветных мантр ─── */

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

:root {
  --bg:        #0f0f12;
  --surface:   #1a1a22;
  --surface2:  #22222e;
  --border:    #2e2e3e;
  --text:      #e8e8f0;
  --text-dim:  #666680;
  --accent:    #4234A6;
  --accent2:   #36A9E8;

  /* Nomulan palette */
  --c1: #171717;
  --c2: #E83E8C;
  --c3: #FF6A00;
  --c4: #28BA52;
  --c5: #36A9E8;
  --c6: #4234A6;
  --c7: #FFFFFF;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
}

/* ── Layout ── */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 4px;
}

.header-spacer { flex: 1; }

.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

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

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ── Palette ── */
.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.palette-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.15s;
  position: relative;
}

.palette-cell:hover { transform: scale(1.08); }

.palette-cell.active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}

.palette-cell[data-color="7"] {
  border-color: var(--border);
}

.palette-cell[data-color="7"].active {
  border-color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  user-select: none;
}

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

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn-generate {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  color: #fff;
  width: 100%;
  justify-content: center;
  padding: 10px;
  font-weight: 600;
  font-size: 14px;
}

.btn-generate:hover { filter: brightness(1.15); }

.btn-danger {
  border-color: #c0392b;
  color: #e74c3c;
}

.btn-danger:hover { background: #2d1212; }

.btn-icon {
  padding: 7px 8px;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* ── Mode selector ── */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:hover { color: var(--text); border-color: #444; }

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mode-btn .ti { font-size: 14px; }

/* ── Canvas area ── */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}

/* ── Grid ── */
.mosaic-wrapper {
  position: relative;
  user-select: none;
}

.mosaic-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  --cell: 72px;
  gap: 1px;
  background: #111;
  border: 1px solid #111;
  border-radius: 2px;
  cursor: crosshair;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  position: relative;
  transition: filter 0.05s;
}

.cell:hover { filter: brightness(1.2); }

/* Цифра в клетке */
.cell-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  pointer-events: none;
  user-select: none;
  opacity: 0.75;
}

/* Замок закреплённой клетки */
.cell.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M12 1a5 5 0 0 1 5 5v3h1a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2h1V6a5 5 0 0 1 5-5m0 2a3 3 0 0 0-3 3v3h6V6a3 3 0 0 0-3-3m0 9a2 2 0 0 0-2 2a2 2 0 0 0 2 2a2 2 0 0 0 2-2a2 2 0 0 0-2-2z'/%3E%3C/svg%3E")
    center / 14px no-repeat;
  pointer-events: none;
  border-radius: 1px;
}

/* ── Right panel ── */
.right-panel {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ── Projects list ── */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}

.project-item:hover { background: var(--surface2); }

.project-item.active { border-color: var(--accent); }

.project-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.project-mini {
  display: grid;
  grid-template-columns: repeat(7, 6px);
  grid-template-rows: repeat(7, 6px);
  gap: 0;
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.project-mini-cell {
  width: 6px;
  height: 6px;
}

/* ── Matrix output ── */
.matrix-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--accent2);
  word-break: break-all;
  letter-spacing: 0.05em;
}

/* ── Tool row ── */
.tool-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* ── Fill all ── */
.fill-all-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.fill-cell {
  aspect-ratio: 1;
  border-radius: 5px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}

.fill-cell:hover { transform: scale(1.1); }

.fill-cell[data-color="7"] { border-color: var(--border); }

/* ── Mantra output ── */
.mantra-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 2;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
}

.mantra-output .mantra-line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mantra-sound {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--surface2);
  font-size: 11px;
  letter-spacing: 0.05em;
}

/* ── Auth overlay ── */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,15,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.auth-box h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.auth-box input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-box input:focus { border-color: var(--accent); }

.auth-error {
  color: #e74c3c;
  font-size: 13px;
}

/* ── Toasts ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: slide-in 0.2s ease;
  max-width: 280px;
}

.toast.success { border-color: #28BA52; color: #5dda7e; }
.toast.error   { border-color: #c0392b; color: #e74c3c; }

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Dialog ── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,15,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog h3 { font-size: 16px; }

.dialog input {
  padding: 9px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 100%;
}

.dialog input:focus { border-color: var(--accent); }

.dialog-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar { width: 180px; }
  .right-panel { width: 160px; }
  .mosaic-grid { --cell: 52px; }
}

@media (max-width: 640px) {
  .app-body { flex-direction: column; }

  .sidebar, .right-panel {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
  }

  .right-panel { border-top: 1px solid var(--border); border-left: none; }

  .sidebar { flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .sidebar-section { flex-shrink: 0; }

  .canvas-area { padding: 12px; }
  .mosaic-grid { --cell: 44px; }
}
.right-panel-resizer {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  transition: background 0.15s;
}
.right-panel-resizer:hover { background: var(--accent); }