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

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface2: #f0ede6;
  --border: #d4cfc5;
  --border2: #e8e4dc;
  --text: #1a1814;
  --text2: #4a4640;
  --text3: #7a756e;
  --accent: #1a3a6b;
  --accent2: #c0392b;
  --accent3: #2e7d32;
  --gold: #b5860d;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;
  --display: 'Playfair Display', serif;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-deep: 0 2px 8px rgba(0,0,0,0.12), 0 8px 32px rgba(0,0,0,0.08);
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* HEADER */
.site-header {
  background: var(--accent);
  border-bottom: 3px solid var(--gold);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.site-header .logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo-img {
  height: 48px;
  width: auto;
  display: block;
}
.logo-text {
  display: flex;
  flex-direction: column;
}
.site-header .logo-text {
  font-family: var(--display);
  color: #fff;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}
.site-header .logo-text span {
  color: var(--gold);
  font-size: 0.7rem;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: block;
  margin-top: -2px;
}
.logo-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: opacity 0.3s ease;
  color: inherit;
}
.logo-link:hover {
  opacity: 0.8;
}
.header-badge {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 3px 10px;
  border-radius: 2px;
  letter-spacing: 0.08em;
}

/* LAYOUT */
.app-wrap {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 56px);
}

/* SIDEBAR */
.sidebar {
  grid-row: 1 / 3;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  border-bottom: 1px solid var(--border2);
  padding: 0;
}
.sidebar-section:last-child { border-bottom: none; flex: 1; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.section-header h3 {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
}
.section-header .toggle-icon {
  font-size: 0.65rem;
  color: var(--text3);
  transition: transform 0.2s;
}
.section-header.collapsed .toggle-icon { transform: rotate(-90deg); }

.section-body {
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.section-body.hidden { display: none; }

/* FIELDS */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.field label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.04em;
  font-family: var(--mono);
}
.field small {
  font-size: 0.68rem;
  color: var(--text3);
  font-family: var(--mono);
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(26,58,107,0.12);
  background: #fff;
}
textarea { resize: vertical; min-height: 60px; line-height: 1.5; }

input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 2px 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }

.check-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text2);
  cursor: pointer;
}
.check-field input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* SERIES LIST */
.series-list { display: flex; flex-direction: column; gap: 0.5rem; }

.serie-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}
.serie-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border2);
}
.serie-num {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.06em;
}
.serie-eq-preview {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.serie-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.serie-body {
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-add-serie {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.55rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text3);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-add-serie:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(26,58,107,0.04);
}

/* ACTIONS */
.sidebar-actions {
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-primary {
  width: 100%;
  padding: 0.75rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: #152f58; }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  width: 100%;
  padding: 0.6rem 1.2rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover {
  border-color: var(--text2);
  color: var(--text);
  background: var(--surface2);
}

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

/* MAIN AREA */
.main-area {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* TOOLBAR */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding-right: 1rem;
  border-right: 1px solid var(--border2);
}
.toolbar-group:last-child { border-right: none; }
.toolbar-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 0.2rem;
}

.tb-btn {
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.tb-btn:hover { background: var(--surface2); border-color: var(--text3); }
.tb-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tb-select {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.tb-select:focus { outline: none; border-color: var(--accent); }

/* CANVAS AREA */
.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: auto;
}

.canvas-container {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: var(--shadow-deep);
  overflow: hidden;
  position: relative;
}

.canvas-container canvas {
  display: block;
}

/* STATUS BAR */
.status-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.35rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.status-msg {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text3);
}
.status-msg.error { color: var(--accent2); }
.status-msg.ok { color: var(--accent3); }
.status-coords {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text3);
}

/* PRESETS */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.preset-btn {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 0.67rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s;
  line-height: 1.3;
}
.preset-btn .preset-name { font-weight: 600; display: block; }
.preset-btn .preset-eq { color: var(--text3); font-size: 0.62rem; display: block; margin-top: 1px; }
.preset-btn:hover { border-color: var(--accent); background: rgba(26,58,107,0.04); }

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

/* Notification */
.notif {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.75rem 1.2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 999;
}
.notif.show { transform: translateY(0); opacity: 1; }

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Responsive */
@media (max-width: 900px) {
  .app-wrap { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; }
  .sidebar { grid-row: auto; max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
  .main-area { grid-row: auto; }
  .toolbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 1rem; }
  .toolbar-group { padding-right: 0.5rem; border-right: none; }
}

/* Tablets (768px and down) */
@media (max-width: 768px) {
  .site-header {
    padding: 0 1rem;
    height: auto;
    min-height: 56px;
  }
  .site-header .logo {
    gap: 0.5rem;
  }
  .logo-img {
    height: 40px;
  }
  .site-header .logo-text {
    font-size: 0.95rem;
  }
  .sidebar {
    max-height: 40vh;
    overflow-y: auto;
  }
  .section-body {
    padding: 0.75rem;
    gap: 0.5rem;
  }
  .field label, .section-header h3 {
    font-size: 0.68rem;
  }
  input[type="text"], input[type="number"], select, textarea {
    font-size: 0.75rem;
    padding: 0.4rem;
  }
  .canvas-wrap {
    padding: 1rem;
  }
  .toolbar {
    padding: 0.5rem 0.75rem;
    gap: 0.3rem;
  }
  .toolbar-label {
    font-size: 0.6rem;
  }
  .tb-btn, .tb-select {
    font-size: 0.65rem;
    padding: 0.25rem 0.4rem;
  }
  .btn-primary, .btn-secondary {
    font-size: 0.7rem;
    padding: 0.5rem 1rem;
  }
}

/* Mobile (480px and down) */
@media (max-width: 480px) {
  body {
    line-height: 1.4;
  }
  .site-header {
    padding: 0.5rem;
    gap: 0.3rem;
  }
  .logo-img {
    height: 32px;
  }
  .site-header .logo-text {
    font-size: 0.8rem;
  }
  .site-header .logo-text span {
    font-size: 0.55rem;
    margin-top: -1px;
  }
  .header-badge {
    font-size: 0.6rem;
    padding: 2px 6px;
  }
  .app-wrap {
    min-height: calc(100vh - 56px);
  }
  .sidebar {
    max-height: 35vh;
    overflow-y: auto;
  }
  .sidebar-section {
    border-bottom: 1px solid var(--border2);
  }
  .section-header {
    padding: 0.5rem 0.75rem;
  }
  .section-header h3 {
    font-size: 0.62rem;
  }
  .section-body {
    padding: 0.6rem;
    gap: 0.4rem;
  }
  .field label {
    font-size: 0.62rem;
  }
  .field small {
    font-size: 0.6rem;
  }
  input[type="text"], input[type="number"], select, textarea {
    font-size: 0.7rem;
    padding: 0.35rem;
  }
  .field-row {
    gap: 0.4rem;
  }
  .check-field {
    font-size: 0.7rem;
    gap: 0.3rem;
  }
  .check-field input[type="checkbox"] {
    width: 13px;
    height: 13px;
  }
  .btn-add-serie {
    font-size: 0.65rem;
    padding: 0.4rem;
  }
  .serie-item {
    margin-bottom: 0.25rem;
  }
  .serie-header {
    padding: 0.4rem;
    gap: 0.3rem;
  }
  .serie-num {
    font-size: 0.6rem;
  }
  .serie-eq-preview {
    font-size: 0.7rem;
  }
  .serie-color-dot {
    width: 8px;
    height: 8px;
  }
  .serie-body {
    padding: 0.5rem;
  }
  .canvas-wrap {
    padding: 0.5rem;
  }
  .canvas-container {
    border: 1px solid var(--border);
  }
  .toolbar {
    padding: 0.4rem 0.5rem;
    gap: 0.2rem;
    flex-direction: column;
  }
  .toolbar-group {
    width: 100%;
    flex-wrap: wrap;
    padding-right: 0;
    border-right: none;
    gap: 0.2rem;
  }
  .toolbar-label {
    font-size: 0.55rem;
    margin-right: 0.1rem;
  }
  .tb-btn {
    font-size: 0.6rem;
    padding: 0.2rem 0.3rem;
  }
  .tb-select {
    font-size: 0.65rem;
    padding: 0.2rem 0.3rem;
  }
  .status-bar {
    padding: 0.3rem 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .status-msg, .status-coords {
    font-size: 0.62rem;
  }
  .sidebar-actions {
    padding: 0.75rem;
    gap: 0.4rem;
  }
  .btn-primary, .btn-secondary {
    font-size: 0.65rem;
    padding: 0.4rem 0.8rem;
  }
  .btn-row {
    gap: 0.4rem;
  }
  .presets-grid {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }
  .preset-btn {
    font-size: 0.6rem;
    padding: 0.35rem;
  }
  .preset-btn .preset-name {
    font-size: 0.62rem;
  }
  .preset-btn .preset-eq {
    font-size: 0.55rem;
  }
  .theme-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
  }
  .theme-btn {
    font-size: 0.55rem;
    padding: 0.3rem;
  }
  .theme-btn .theme-preview {
    height: 16px;
    margin-bottom: 2px;
  }
  .help-text {
    font-size: 0.6rem;
    padding: 0.4rem;
  }
  .notif {
    bottom: 1rem;
    right: 0.5rem;
    font-size: 0.65rem;
    padding: 0.5rem 0.8rem;
  }
}

/* Select styling */
select option { font-family: var(--mono); }

.sep { height: 1px; background: var(--border2); margin: 0.1rem 0; }

/* Color palette row */
.palette-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.palette-swatch {
  width: 22px;
  height: 22px;
  border-radius: 2px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.palette-swatch:hover { transform: scale(1.15); }
.palette-swatch.active { border-color: var(--text); }

/* Theme selector */
.theme-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}
.theme-btn {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.62rem;
  transition: all 0.12s;
  background: var(--bg);
  color: var(--text2);
}
.theme-btn:hover { border-color: var(--accent); }
.theme-btn.active { border-color: var(--accent); background: rgba(26,58,107,0.08); font-weight: 700; color: var(--accent); }
.theme-btn .theme-preview {
  width: 100%;
  height: 20px;
  border-radius: 2px;
  margin-bottom: 4px;
  border: 1px solid rgba(0,0,0,0.1);
}

.help-text {
  font-family: var(--mono);
  font-size: 0.67rem;
  color: var(--text3);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  line-height: 1.6;
}
