* {
    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: #f45b69;
    --neg: #2d7ff9;
    --path: #1a1a1a;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

a {
    color: inherit;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 24px 0 18px;
}

.eyebrow {
    margin: 0;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--muted);
}

.top-bar h1 {
    margin: 0 0 6px;
    font-size: 30px;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.lede {
    margin: 0;
    max-width: 640px;
    line-height: 1.5;
    color: var(--muted);
    font-size: 14px;
}

.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; }

.layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 0 0 28px;
}

.full-row {
    grid-column: 1 / -1;
}

.controls-card, .canvas-card {
    background: var(--card);
    border-radius: 8px;
    padding: 20px 24px 24px;
    border: 1px solid var(--line);
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.controls-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.controls-actions .ghost-button {
    white-space: nowrap;
}

.controls-header h2,
.canvas-card h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.ghost-button {
    border: 1px solid var(--line);
    color: var(--ink);
    background: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ghost-button:hover {
    background: var(--soft-line);
}

.charge-controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.charge-panel {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-bg);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.dot.positive {
    background: var(--pos);
}

.dot.negative {
    background: var(--neg);
}

.label {
    margin: 0 0 2px;
    font-weight: 700;
}

.small {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
}

.polarity-button {
    padding: 8px 12px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    background: var(--pos);
    color: #fff;
    transition: all 0.15s ease;
}

.polarity-button.negative {
    background: var(--neg);
}

.polarity-button:active {
    transform: translateY(1px);
}

.slider-row {
    display: grid;
    grid-template-columns: 90px 1fr 60px;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.slider-row input[type="range"] {
    width: 100%;
    accent-color: var(--ink);
}

.slider-row .value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.slider-row.slim {
    grid-template-columns: 130px 1fr 60px;
    grid-column: 1 / -1;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--panel-bg);
    border: 1px solid var(--line);
}

.hint {
    margin: 16px 0 0;
    color: var(--muted);
    line-height: 1.4;
    font-size: 14px;
}

.canvas-card {
    position: relative;
    padding: 18px 18px 22px;
}

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

.title-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend {
    display: flex;
    gap: 12px;
    font-size: 13px;
    color: var(--muted);
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-item.stroke::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 3px;
    background: linear-gradient(90deg, var(--pos), var(--neg));
    border-radius: 999px;
}

.legend-item.equip .equip-line {
    display: inline-block;
    width: 18px;
    height: 3px;
    background: linear-gradient(90deg, #8a6cff, #38c6d9);
    border-radius: 999px;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--panel-bg);
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    user-select: none;
}

.toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--ink);
    cursor: pointer;
}

canvas {
    width: 100%;
    height: 520px;
    border-radius: 8px;
    display: block;
    background: #fff;
    border: 1px solid var(--line);
}

.overlay {
    text-align: center;
    margin-top: 12px;
}

.fieldmap-card {
    margin-top: -6px;
}

#fieldMapCanvas {
    height: 460px;
}

.legend-dot.strong-field {
    background: var(--pos);
}

.legend-dot.weak-field {
    background: #6a8bbd;
}

.motion-card {
    margin-top: -6px;
}

.field-type-row {
    display: flex;
    align-items: center;
    gap: 10px;
    grid-column: 1 / -1;
    flex-wrap: wrap;
}

.field-type-label {
    font-weight: 700;
    white-space: nowrap;
}

.field-type-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.field-type-btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 13px;
}

.field-type-btn:hover {
    background: var(--soft-line);
}

.field-type-btn.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}

.motion-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.motion-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.primary-button {
    border: 1px solid var(--ink);
    background: var(--ink);
    color: #fff;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.primary-button:hover {
    opacity: 0.85;
}

.primary-button:active {
    transform: translateY(1px);
}

#motionCanvas {
    height: 420px;
}

.stat-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--panel-bg);
    color: var(--ink);
    border: 1px solid var(--line);
    font-weight: 600;
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

.legend-dot.velocity {
    background: var(--neg);
}

.legend-dot.force {
    background: var(--pos);
}

.legend-dot.path {
    background: var(--path);
}

footer {
    text-align: center;
    padding: 18px 0 32px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .canvas-card {
        order: -1;
    }
}
