:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --border:        #e2e5ea;
  --border-strong: #c9cdd4;
  --accent:        #1d4ed8;
  --accent-light:  #eff4ff;
  --text:          #111827;
  --text-2:        #6b7280;
  --text-3:        #9ca3af;
  --red:           #dc2626;
  --red-light:     #fef2f2;
  --mono:          'DM Mono', monospace;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── HEADER ── */
header {
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}
header h1 { font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
header p  { font-size: 0.75rem; color: var(--text-2); margin-left: 4px; }
.header-sep { color: var(--border-strong); }

#settings-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-2);
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s;
}
#settings-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* ── LAYOUT ── */
.main-layout {
  display: flex;
  gap: 16px;
  padding: 16px;
  width: 100%;
  max-width: 1300px;
  align-items: flex-start;
}

.right-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.card-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

/* ── LEFT PANEL ── */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 215px;
  flex: 1;
  max-width: 320px;
  flex-shrink: 0;
}

.field-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
label { font-size: 0.7rem; font-weight: 500; color: var(--text-2); }

input, select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  padding: 6px 9px;
  border-radius: 6px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,78,216,0.1);
}

.controls-grid-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.controls-grid-row .field-group { margin-bottom: 0; }

/* ── SWATCHES ── */
.outcome-swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 5px;
  border: 1px solid var(--border); cursor: pointer;
  font-size: 0.7rem; font-weight: 500;
  background: var(--surface); color: var(--text-2);
  transition: all 0.12s; white-space: nowrap;
}
.swatch:hover  { border-color: var(--border-strong); color: var(--text); background: var(--bg); }
.swatch.active { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.swatch-dot    { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── BUTTONS ── */
.btn {
  width: 100%; padding: 7px 10px;
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text-2); font-family: 'Inter', sans-serif;
  font-size: 0.75rem; font-weight: 500;
  cursor: pointer; border-radius: 6px; transition: all 0.12s; margin-top: 2px;
}
.btn:hover      { background: var(--bg); color: var(--text); }
.btn-danger     { color: var(--red); border-color: #fca5a5; }
.btn-danger:hover { background: var(--red-light); border-color: var(--red); }

.btn-export {
  padding: 5px 12px; background: var(--accent);
  border: none; color: #fff; font-family: 'Inter', sans-serif;
  font-size: 0.72rem; font-weight: 600;
  cursor: pointer; border-radius: 6px; transition: opacity 0.12s;
}
.btn-export:hover    { opacity: 0.88; }
.btn-export:disabled {
  background: var(--bg); color: var(--text-3);
  border: 1px solid var(--border); cursor: default; opacity: 1;
}

/* ── STATE DISPLAY ── */
.state-display {
  text-align: center;
  font-size: 0.82rem;
  letter-spacing: 0.25em;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  margin-top: 4px;
  padding: 4px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 500;
}

/* ── LEGEND ── */
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; font-size: 0.75rem; }
.legend-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-label { color: var(--text); font-weight: 500; }
.legend-count {
  margin-left: auto; color: var(--text-2); font-size: 0.68rem;
  background: var(--bg); padding: 1px 7px; border-radius: 12px;
  border: 1px solid var(--border); min-width: 24px; text-align: center; font-weight: 500;
}

/* ── FIELD CONTAINER ── */
.center-panel { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }

#field-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  position: relative;
  width: 100%;
  max-width: 80vh;
}
#field-container svg {
  display: block;
  max-height: 80vh;
  max-width: 80vh;
  width: 100%;
  height: auto;
}

.coord-overlay {
  position: absolute; top: 10px; right: 12px;
  font-size: 0.68rem; color: rgba(255,255,255,0.55);
  letter-spacing: 0.04em; pointer-events: none;
  font-family: var(--mono);
  background: rgba(0,0,0,0.25);
  padding: 2px 7px; border-radius: 4px;
}
.click-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 0.65rem; color: rgba(255,255,255,0.3);
  pointer-events: none; white-space: nowrap;
  background: rgba(0,0,0,0.18); padding: 2px 8px; border-radius: 4px;
}

/* ── EDIT PANEL ── */
#edit-panel {
  position: absolute;
  bottom: 14px; left: 14px;
  width: 340px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 12px 14px;
  z-index: 10;
}
#edit-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
#edit-title   { font-size: 0.72rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.07em; }
#edit-close   { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 0.8rem; padding: 2px 4px; border-radius: 4px; transition: background 0.12s; }
#edit-close:hover { background: var(--bg); color: var(--text); }

.edit-row   { display: flex; gap: 8px; }
.edit-field { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.edit-label { font-size: 0.65rem; font-weight: 500; color: var(--text-2); }
.edit-field input, .edit-field select { padding: 4px 7px; font-size: 0.75rem; border-radius: 5px; }
.edit-swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.edit-swatches .swatch { font-size: 0.65rem; padding: 3px 7px; }
.edit-swatches.trajectory-swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.edit-swatches.trajectory-swatches .swatch { justify-content: center; padding: 3px 4px; }


#edit-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
}
#edit-delete-btn {
  background: none; border: 1px solid #fca5a5; color: var(--red);
  font-family: 'Inter', sans-serif; font-size: 0.72rem; font-weight: 500;
  padding: 5px 12px; border-radius: 6px; cursor: pointer; transition: all 0.12s;
}
#edit-delete-btn:hover { background: var(--red-light); }
#edit-save-btn {
  background: var(--accent); border: none; color: white;
  font-family: 'Inter', sans-serif; font-size: 0.72rem; font-weight: 600;
  padding: 5px 14px; border-radius: 6px; cursor: pointer; transition: opacity 0.12s;
}
#edit-save-btn:hover { opacity: 0.88; }

.dot-selected > circle,
.dot-selected > rect,
.dot-selected > polygon { stroke: #1d4ed8 !important; stroke-width: 2.5 !important; }

/* ── TABLE ── */
#table-container-el {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  max-width: 80vh;
}

.table-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.table-header .card-title { margin-bottom: 0; border: none; padding: 0; }
.event-count { font-size: 0.72rem; color: var(--text-2); font-weight: 500; }

.table-scroll { max-height: 200px; overflow-y: auto; }
.table-scroll::-webkit-scrollbar { width: 4px; }
.table-scroll::-webkit-scrollbar-track { background: var(--bg); }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
thead tr { background: var(--bg); position: sticky; top: 0; z-index: 1; }
th {
  padding: 7px 12px; text-align: left; color: var(--text-2);
  font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  font-size: 0.65rem; border-bottom: 1px solid var(--border);
}
td { padding: 6px 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

.outcome-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; font-size: 0.68rem; font-weight: 500;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.delete-btn {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 0.8rem; padding: 0 3px;
  line-height: 1; transition: color 0.12s;
}
.delete-btn:hover { color: var(--red); }
.empty-state { text-align: center; padding: 28px; color: var(--text-3); font-size: 0.78rem; }

/* ── FILTER BAR ── */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg); align-items: center;
}
.filter-bar-label {
  font-size: 0.63rem; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; margin-right: 2px;
}
.filter-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 12px;
  border: 1px solid var(--border); background: white;
  font-size: 0.68rem; font-weight: 500; color: var(--text-2);
  cursor: pointer; transition: all 0.12s; white-space: nowrap; user-select: none;
}
.filter-chip:hover  { border-color: var(--border-strong); color: var(--text); }
.filter-chip.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.filter-input {
  background: white; border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font-size: 0.7rem; font-family: 'Inter', sans-serif;
  color: var(--text); outline: none; transition: border-color 0.15s;
}
.filter-input:focus      { border-color: var(--accent); }
.filter-input::placeholder { color: var(--text-3); }
.filter-clear {
  margin-left: auto; background: none; border: none;
  font-size: 0.68rem; color: var(--text-3); cursor: pointer;
  padding: 3px 6px; border-radius: 4px;
  font-family: 'Inter', sans-serif; transition: color 0.12s; white-space: nowrap;
}
.filter-clear:hover  { color: var(--red); }
.filter-divider { width: 1px; height: 14px; background: var(--border); flex-shrink: 0; }

/* ── SETTINGS MODAL ── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.35); z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: white; border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  width: 500px; max-width: 95vw;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2  { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 1rem; padding: 2px 6px;
  border-radius: 4px; line-height: 1; transition: background 0.12s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body         { padding: 20px; }
.modal-section-title {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-2);
  margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.settings-grid      { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin-bottom: 20px; }
.settings-field     { display: flex; flex-direction: column; gap: 3px; }
.settings-label     { font-size: 0.78rem; font-weight: 500; color: var(--text); }
.settings-sub       { font-size: 0.65rem; color: var(--text-3); }
.settings-input-row { display: flex; align-items: center; gap: 7px; margin-top: 4px; }
.settings-input {
  background: white; border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 6px 10px;
  font-size: 0.8rem; font-family: 'Inter', sans-serif; color: var(--text);
  width: 90px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.settings-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29,78,216,0.1); }
.settings-unit        { font-size: 0.72rem; color: var(--text-3); }

.preset-btn {
  padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--bg); font-family: 'Inter', sans-serif;
  font-size: 0.75rem; font-weight: 500; color: var(--text-2); cursor: pointer; transition: all 0.12s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.settings-apply-btn {
  background: var(--accent); border: none; color: white;
  font-family: 'Inter', sans-serif; font-size: 0.78rem; font-weight: 600;
  padding: 7px 18px; border-radius: 6px; cursor: pointer; transition: opacity 0.12s;
}
.settings-apply-btn:hover { opacity: 0.88; }
.settings-cancel-btn {
  background: none; border: 1px solid var(--border-strong); color: var(--text-2);
  font-family: 'Inter', sans-serif; font-size: 0.78rem; font-weight: 500;
  padding: 7px 14px; border-radius: 6px; cursor: pointer; transition: all 0.12s;
}
.settings-cancel-btn:hover { background: var(--bg); }

/* Wall points */
.wall-points-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; margin-top: 8px; }
.wall-points-table th {
  text-align: left; font-size: 0.65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-2); padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.wall-points-table td { padding: 4px 4px; vertical-align: middle; }
.wall-pt-input {
  width: 80px; padding: 4px 7px; border: 1px solid var(--border-strong);
  border-radius: 5px; font-size: 0.75rem; font-family: 'Inter', sans-serif;
  color: var(--text); background: white; outline: none; transition: border-color 0.15s;
}
.wall-pt-input:focus { border-color: var(--accent); }
.wall-pt-remove {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 0.85rem; padding: 2px 6px;
  border-radius: 4px; transition: color 0.12s;
}
.wall-pt-remove:hover { color: var(--red); }
.wall-mode-toggle { display: flex; gap: 6px; margin-bottom: 12px; }
.wall-mode-btn {
  flex: 1; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--bg);
  font-family: 'Inter', sans-serif; font-size: 0.74rem; font-weight: 500;
  color: var(--text-2); cursor: pointer; transition: all 0.12s; text-align: center;
}
.wall-mode-btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.wall-add-btn {
  margin-top: 8px; padding: 5px 12px; border-radius: 6px;
  border: 1px dashed var(--border-strong); background: none;
  font-family: 'Inter', sans-serif; font-size: 0.74rem; font-weight: 500;
  color: var(--text-2); cursor: pointer; transition: all 0.12s; width: 100%;
}
.wall-add-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.wall-hint { font-size: 0.65rem; color: var(--text-3); margin-top: 6px; line-height: 1.5; }

/* ── ANIMATIONS ── */
@keyframes dotPop {
  0%   { r: 5;  opacity: 0.9; }
  40%  { r: 13; opacity: 0.4; }
  100% { r: 5;  opacity: 0.85; }
}
.dot-new { animation: dotPop 0.35s ease-out; }

/* ── MOBILE TAB BAR ── */
.mobile-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  z-index: 200; padding-bottom: env(safe-area-inset-bottom);
}
.mobile-tabs-inner { display: flex; }
.mobile-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px 8px; background: none; border: none; cursor: pointer;
  font-family: 'Inter', sans-serif; font-size: 0.62rem; font-weight: 500;
  color: var(--text-3); transition: color 0.12s; -webkit-tap-highlight-color: transparent;
}
.mobile-tab.active { color: var(--accent); }
.mobile-tab svg    { width: 20px; height: 20px; }

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  body { font-size: 14px; }

  header { padding: 10px 14px; gap: 8px; }
  header h1 { font-size: 0.9rem; }
  header p, .header-sep { display: none; }
  #settings-btn { padding: 5px 8px; font-size: 0.72rem; }

  .mobile-tabs { display: block; }

  .main-layout { flex-direction: column; padding: 10px 10px 70px; gap: 0; }

  .left-panel    { width: 100%; gap: 10px; }
  .right-column  { width: 100%; }
  .center-panel  { width: 100%; gap: 10px; }
  #table-container-el { width: 100%; }

  .card { padding: 12px; }

  .controls-grid-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .controls-grid-row .field-group { margin-bottom: 0; }

  #base-out-control { height: 72px; }
  .swatch { padding: 6px 10px; font-size: 0.72rem; }

  .filter-bar {
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding: 6px 10px; gap: 5px;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-divider { display: none; }

  .table-scroll { max-height: 320px; }
  table { font-size: 0.7rem; }
  th, td { padding: 5px 8px; }
  .col-hide-mobile { display: none; }

  #edit-panel {
    position: fixed; bottom: 64px; left: 8px; right: 8px; width: auto;
    max-height: 60vh; overflow-y: auto; z-index: 150;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  }

  .modal {
    width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; display: flex; flex-direction: column;
  }
  .modal-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 12px; }

  .coord-overlay { display: none; }
  .click-hint    { font-size: 0.58rem; left: auto; right: 10px; transform: none; }

  .btn         { padding: 10px; font-size: 0.8rem; }
  .btn-export  { padding: 7px 12px; font-size: 0.74rem; }
}
