* { box-sizing: border-box; }

:root {
  --bg: #f7f7f5;
  --card: #fff;
  --ink: #111;
  --muted: #646464;
  --line: #d9d9d4;
  --soft-line: #ececea;
  --panel-bg: #fafaf8;
  /* functional colors (match canvas drawing) */
  --pos: #d44056;
  --neg: #3873d4;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  overflow: hidden;
  height: 100vh;
}
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}
header {
  padding: 12px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
header h1 {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--ink);
}
header .header-right {
  display: flex; align-items: center; gap: 16px;
}
header .legend {
  display: flex; gap: 14px; font-size: 12px; color: var(--muted);
}
header .legend span.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
  box-shadow: 0 0 0 1px #ffffff, 0 0 0 2px rgba(0,0,0,0.08);
}

.home-link {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d8d2c0;
  border-radius: 50%;
  color: #2f5d4f;
  background: #faf8f1;
  box-shadow: 0 1px 2px rgba(28,43,37,.05), 0 12px 32px -16px rgba(28,43,37,.28);
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease;
}
.home-link:hover,
.home-link:focus-visible {
  border-color: #8a9a5b;
  color: #3f7060;
  transform: translateY(-2px);
  outline: none;
}
.home-link svg { display: block; }

#main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  overflow: hidden;
  min-height: 0;
}
.panel {
  position: relative;
  background: var(--card);
  overflow: hidden;
}
.panel .label {
  position: absolute; top: 10px; left: 12px;
  font-size: 12px; font-weight: 600; color: var(--ink);
  background: rgba(255,255,255,0.92);
  padding: 3px 9px; border-radius: 4px;
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 5;
}
.panel .hint {
  position: absolute; bottom: 10px; left: 12px;
  font-size: 11px; color: var(--muted);
  background: rgba(255,255,255,0.85);
  padding: 3px 9px; border-radius: 4px;
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 5;
}
#canvas2d {
  width: 100%; height: 100%;
  display: block; cursor: crosshair;
}
#canvas3d {
  width: 100%; height: 100%;
}
footer {
  padding: 10px 14px;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.section {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  position: relative;
}
.section .section-title {
  position: absolute;
  top: -8px; left: 8px;
  font-size: 10px; font-weight: 700;
  color: var(--muted);
  background: var(--card);
  padding: 0 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.section.sec-field .section-title { color: var(--pos); }
.section.sec-particle .section-title { color: var(--neg); }
.section.sec-sim .section-title { color: var(--muted); }
.section.sec-view .section-title { color: var(--muted); }

.label-s {
  font-size: 11px; color: var(--muted); margin-right: 2px;
}
button {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.15s;
}
button:hover { background: var(--soft-line); border-color: #bcbcb4; }
button.active { background: var(--ink); color: #ffffff; border-color: var(--ink); }
.sec-field button.active { background: var(--pos); border-color: var(--pos); color: #fff; }
.sec-particle button.active { background: var(--neg); border-color: var(--neg); color: #fff; }
button.danger { background: #fff; border-color: var(--line); color: var(--muted); }
button.danger:hover { background: var(--soft-line); }
button.go { background: var(--ink); border-color: var(--ink); color: #fff; }
button.go:hover { background: #333; }
button.go.running { background: #fff; border-color: var(--line); color: var(--ink); }
input[type=range] { width: 96px; accent-color: var(--ink); }
.slider-val { font-size: 11px; color: var(--ink); min-width: 30px; display: inline-block; text-align: right; font-variant-numeric: tabular-nums; }
label.chk { font-size: 12px; color: var(--ink); display: flex; align-items: center; gap: 4px; cursor: pointer; }
label.chk input { accent-color: var(--ink); }
