*, *::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:    #5b21b6;
  --accent-dim:#4c1d95;
  --amber:     #d97706;
  --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(--amber);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.logo-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: opacity 0.2s;
  color: inherit;
}
.logo-link:hover { opacity: 0.85; }

.logo-img {
  height: 44px;
  width: auto;
  display: block;
}

.logo-text {
  font-family: var(--display);
  color: #fff;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
}
.logo-text span {
  font-family: var(--mono);
  color: var(--amber);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: -2px;
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.header-badge {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.85);
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 3px 10px;
  border-radius: 2px;
  letter-spacing: 0.08em;
}

/* ── LAYOUT ── */
.app {
  display: flex;
  min-height: calc(100vh - 59px);
}

/* ── SIDEBAR ── */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

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

.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);
}
.toggle-icon {
  font-size: 0.65rem;
  color: var(--text3);
  transition: transform 0.2s;
}
.section-header.collapsed .toggle-icon { transform: rotate(-90deg); }
.section-header.collapsed { border-bottom: none; }

.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-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.04em;
}

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

/* ── INPUTS ── */
input[type="text"],
input[type="number"],
select {
  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 {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,33,182,0.12);
  background: #fff;
}

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

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

/* ── BUTTONS ── */
.btn-primary {
  width: 100%;
  padding: 0.65rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  width: 100%;
  padding: 0.55rem 1rem;
  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-secondary.active {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}
.btn-test {
  width: 100%;
  padding: 0.55rem 1rem;
  background: #7dd3fc;
  color: #fff;
  border: 1px solid #7dd3fc;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-test:hover {
  background: #38bdf8;
  border-color: #38bdf8;
}
.btn-secondary.active:hover {
  background: #b45309;
  border-color: #b45309;
}

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

/* ── MAIN ── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1.25rem;
  overflow-y: auto;
  background: var(--bg);
}

/* ── CANVAS + INFO ── */
.canvas-and-info {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  align-items: start;
}

.canvas-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0d0a1a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  overflow: hidden;
}
.canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── INFO PANEL ── */
#infoPanel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-height: 80px;
}
#infoPanel h3 {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border2);
}

/* ── TABLE ── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.72rem;
}
.table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  color: var(--text3);
  font-weight: 600;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 0.4rem 0.5rem; color: var(--text); }
.table tr:hover td { background: var(--surface2); }
.table tr.selected td { background: rgba(91,33,182,0.08); }

/* ── FORCE BOX ── */
.force-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: rgba(217,119,6,0.07);
  border-left: 3px solid var(--amber);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text2);
  line-height: 1.9;
}
.force-main {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--amber);
  margin-top: 0.25rem;
}

/* ── GRAPH AREA ── */
.graph-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.graph-area h3 {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border2);
}
.graph-area canvas {
  width: 100%;
  max-width: 100%;
}

/* ── TUTORIAL ── */
.tutorial-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#btnTutorialToggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.1rem;
  background: var(--surface2);
  border: none;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}
#btnTutorialToggle:hover { background: var(--border2); }

.tutorial-icon { font-size: 0.6rem; color: var(--text3); }

#tutorialContent {
  display: none;
  padding: 1rem;
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.tutorial-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 0.85rem;
  border-left: 3px solid var(--accent);
}
.tutorial-card h4 {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.tutorial-card p {
  font-size: 0.78rem;
  color: var(--text2);
  margin: 0.25rem 0;
  line-height: 1.5;
}
.tutorial-card ul {
  padding-left: 1rem;
  font-size: 0.75rem;
  color: var(--text2);
  line-height: 1.7;
}

/* ── RESPONSIVE ── */
@media (max-width: 1024px) {
  .sidebar { width: 270px; }
}

@media (max-width: 900px) {
  .canvas-and-info { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
  .site-header { padding: 0 1rem; height: auto; min-height: 56px; }
  .logo-img { height: 36px; }
  .main { padding: 0.85rem; gap: 0.85rem; }
}

@media (max-width: 480px) {
  .main { padding: 0.65rem; gap: 0.65rem; }
  .logo-text { font-size: 0.9rem; }
  .header-badge { display: none; }
  .btn-row { grid-template-columns: 1fr; }
}
