/* === Font face (non-blocking) === */
@font-face {
  font-family: "Carolita";
  src: url("fonts/Carolita.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ===== Base Page ===== */
body {
  margin: 0;
  padding: 0;
  font-family: "Carolita", "Calibri", sans-serif;
  background: #f7f7f9;
  color: #444;
  display: flex;
  min-height: 100%;
  height: 100%;
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
}

/* ===== Sidebar (controls) ===== */
#controls {
  width: 260px;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  padding: 8px;
  background: #fff;
  border-right: 1px solid #ddd;
  box-shadow: 2px 0 8px rgba(98,98,98,.05);
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
}

/* --- Labels: slider vs section headings (pure CSS, no JS) --- */
#controls p {
  margin: 0 0 2px 0;
  font-weight: 600;
  font-size: 11px;
  color: #333;
  letter-spacing: .1px;
  line-height: 1.35;
}

/* Slider labels = the <p> immediately followed by a range input */
#controls p:has(+ input[type=range]) {
  margin-top: 8px;
  font-weight: 600;
}

/* Section headings (not followed by a range): add soft divider & a touch larger */
#controls p:not(:has(+ input[type=range])) {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #eaeaf0;
  font-size: 12.5px;
  color: #2f2f36;
}

/* ===== Sliders ===== */
#controls input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  margin: 6px 0 12px;
  background: transparent;
}
#controls input[type=range]:focus { outline: none; }

/* Track */
#controls input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: #d0d0d0;
  border-radius: 4px;
}
#controls input[type=range]::-moz-range-track {
  height: 4px;
  background: #d0d0d0;
  border-radius: 4px;
}

/* Thumb */
#controls input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 12px;
  width: 12px;
  border-radius: 50%;
  background: #6baed6;
  margin-top: -4px;
  cursor: pointer;
}
#controls input[type=range]::-moz-range-thumb {
  height: 12px;
  width: 12px;
  border-radius: 50%;
  background: #6baed6;
  cursor: pointer;
}

/* ===== Dropdowns ===== */
#controls select {
  width: 100%;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  font-size: 11px;
}

/* ===== Buttons ===== */
#controls button {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #f2f2f2;
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
  font-size: 11px;
}
#controls button:hover {
  background: #e9e9e9;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* Compact buttons */
#controls .btn-compact { padding: 3px 6px; font-size: 11px; flex: 0 0 auto; }

/* Text inputs */
#controls input[type=text],
#controls textarea {
  padding: 5px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  font-size: 11px;
}

/* Radios & checkboxes: neat alignment */
#controls input[type=checkbox],
#controls input[type=radio] {
  margin-right: 6px;
  accent-color: #4a90e2;
  transform: scale(.96);
}
#controls input[type=radio] + label,
#controls input[type=checkbox] + label { margin-right: 10px; }

/* ===== Inline rows ===== */
.inline-group, .file-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 2px 0;
}
.inline-group > *, .file-group > * { flex: 1; min-width: 90px; }
.inline-group .btn-compact { flex: 0 0 auto; margin-left: auto; }
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 6px;
}
.toggle-grid > * {
  min-width: 0;
  width: 100%;
}
.toggle-grid label {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}
.toggle-grid label span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.toggle-grid .btn-compact {
  margin-left: 0;
  min-width: 0;
}
.display-toggle-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 2px 0;
}
.display-toggle-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 6px;
}
.display-toggle-row > * {
  min-width: 0;
}
.display-toggle-row label {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}
.display-toggle-row label span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.display-pause-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}
.display-pause-row .btn-compact {
  grid-column: 1 / 2;
  width: 100%;
  min-width: 0;
  margin-left: 0;
}
.compact-section-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eaeaf0;
}
.compact-section-label {
  flex: 0 0 58px;
  font-size: 12.5px;
  font-weight: 700;
  color: #2f2f36;
  line-height: 1.2;
}
.compact-section-controls {
  flex: 1 1 auto;
  min-width: 0;
}
.compact-section-row .media-file-row {
  padding: 0;
  gap: 5px;
}
.compact-section-row .media-file-row label.btn-compact {
  padding: 3px 5px;
  font-size: 10.5px;
}

/* ===== Notes ===== */
#comment-container textarea {
  font-size: 11px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #ccc;
  margin-top: 4px;
  margin-bottom: 8px;
  box-sizing: border-box;
  width: 100%;
  height: 56px;
  resize: vertical;
}

/* ===== Action Buttons (bottom row) ===== */
#action-group {
  margin-top: auto;
  display: flex;
  gap: 6px;
}
#action-group button { flex: 1; }

/* ===== Canvas Container ===== */
#canvas-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
  overflow: hidden;
  position: relative;
  background: #f5f5f5;
}

@media (max-width: 900px) {
  body {
    display: block;
    min-height: auto;
    height: auto;
    overflow: auto;
  }

  #controls {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #ddd;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 2px 8px rgba(98,98,98,.05);
  }

  #canvas-container {
    height: auto;
    min-height: 60vh;
  }
}

/* ===== File input custom ===== */
.file-group { align-items: center; }
.media-file-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.media-file-row label.btn-compact {
  flex: 1 1 0;
  text-align: center;
}
.file-hidden { display: none !important; }
#controls .media-status {
  min-height: 16px;
  margin-top: -2px;
  margin-bottom: 6px;
  font-size: 10.5px;
  color: #5f6b63;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#controls .media-status:empty {
  display: none;
  min-height: 0;
  margin: 0;
}
#controls .media-status.is-loaded {
  color: #4c8b5e;
}
#controls label.btn-compact {
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #f2f2f2;
  cursor: pointer;
  font-size: 11px;
  flex: 0 0 auto;
  transition: background .2s, box-shadow .2s;
}
#controls label.btn-compact:hover {
  background: #e9e9e9;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* ===== Optional polish ===== */
*, *::before, *::after { box-sizing: border-box; }
#controls button:focus-visible,
#controls select:focus-visible,
#controls input:focus-visible,
#controls textarea:focus-visible {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}
#controls button:active { transform: translateY(.5px); }

/* ===== Primary actions ===== */
#primary-actions button.primary-action {
  width: 100%;
  font-weight: 700;
  font-size: 13px;
  background: #4a90e2;
  color: #fff;
  border: 1px solid #3b7ed0;
  border-radius: 6px;
  padding: 6px 8px;
  transition: background .2s;
}
#primary-actions button.primary-action:hover { background: #3578c0; }
#primary-actions button.primary-action:active { transform: translateY(.5px); }

/* === Header helpers used by protectLog.js === */
#fw-header-row { gap: 8px; }
#fw-header-row .btn-row { display: flex; gap: 6px; }
#fw-secondary-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}
#fw-secondary-actions .fw-secondary-row {
  display: flex;
}

#fw-analysis-actions {
  display: flex;
  justify-content: flex-start;
  padding: 0;
}

.sim-analysis-actions {
  position: absolute;
  top: 42px;
  right: 10px;
  z-index: 100;
  justify-content: flex-end;
  background: transparent;
  border: 0;
}

/* === Start / Save Log (mauve) === */
#fw-header-row button.primary-strong,
#primary-actions button.primary-strong {
  background: #b794c6;
  color: #fff;
  border: 1px solid #a074b8;
  font-weight: 700;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  transition: background .25s ease, box-shadow .25s ease;
  box-shadow: 0 2px 5px rgba(160,120,184,.25);
}
#fw-header-row button.primary-strong:hover,
#primary-actions button.primary-strong:hover {
  background: #a47fbf;
  box-shadow: 0 3px 8px rgba(160,120,184,.35);
}
#fw-header-row button.primary-strong:active,
#primary-actions button.primary-strong:active {
  transform: translateY(.5px);
  background: #996eb8;
}
.primary-strong:focus-visible { outline: 2px solid #8f6bb1; outline-offset: 2px; }
.primary-strong[disabled] { opacity: .65; cursor: default; box-shadow: none; }

/* ---------- COMPACT MODE FOR SHORTER VIEWPORTS ---------- */
@media (max-height: 820px) {
  #controls { padding: 6px; gap: 2px; }
  #controls * { line-height: 1.25; }

  #controls p { margin: 0 0 1px 0; font-size: 10.5px; }
  #controls p:has(+ input[type=range]) { margin-top: 6px; }
  #controls p:not(:has(+ input[type=range])) {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #f0f0f3;
    font-size: 12px;
  }

  #controls input[type=range] { margin: 4px 0 8px; }
  #controls input[type=range]::-webkit-slider-thumb,
  #controls input[type=range]::-moz-range-thumb {
    height: 11px; width: 11px;
  }

  #controls input[type=radio],
  #controls input[type=checkbox] {
    transform: scale(0.92);
    margin-right: 4px;
  }
  #controls input[type=radio] + label,
  #controls input[type=checkbox] + label { margin-right: 8px; }

  .inline-group, .file-group { gap: 4px; padding: 0; }
  .inline-group > *, .file-group > * { min-width: 80px; }
  .inline-group .btn-compact { margin-left: auto; }
  .toggle-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .toggle-grid > * { min-width: 0; }
  .toggle-grid .btn-compact { margin-left: 0; }
  .display-toggle-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .display-toggle-row > * { min-width: 0; }

  #controls button { padding: 3px 5px; font-size: 10.5px; }
  #primary-actions button.primary-action { padding: 5px 6px; font-size: 12px; }
  #fw-header-row button.primary-strong { padding: 5px 8px; font-size: 11.5px; }

  #controls input[type=text],
  #controls textarea { padding: 4px; }

  #comment-container textarea { height: 44px; margin-bottom: 6px; }

  #action-group { gap: 4px; }
}

/* Prototype / experiment buttons */
#fw-header-row .ghost-toggle,
#fw-secondary-actions .ghost-toggle {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #cdbce6;
  background: #fff;
  color: #6b4fa3;
  font-weight: 600;
}
#fw-header-row .ghost-toggle:hover,
#fw-secondary-actions .ghost-toggle:hover { background: #f4f0fb; }
#fw-header-row .ghost-toggle.active,
#fw-secondary-actions .ghost-toggle.active {
  background: #efe9f7;
  border-color: #b9a1e1;
}

#fw-secondary-actions .proto-btn,
#fw-secondary-actions .analytics-btn,
#fw-secondary-actions .solver-btn {
  width: 100%;
}

#fw-secondary-actions .proto-btn {
  margin-top: 0;
}

#fw-secondary-actions .analytics-btn,
#fw-secondary-actions .solver-btn {
  margin-top: 0;
}

#fw-secondary-actions #fw-solver-row {
  gap: 3px;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

#controls #fw-secondary-actions #fw-solver-row .solver-btn {
  appearance: none;
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0 !important;
  padding: 4px 5px !important;
  border: 1px solid #7fb5dd !important;
  border-radius: 6px !important;
  background: #dff0fb !important;
  color: #1f5f8f !important;
  font-size: 10.5px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  box-shadow: none !important;
}

#controls #fw-secondary-actions #fw-solver-row .solver-btn:hover {
  background: #cbe7f8 !important;
  border-color: #5fa4d4 !important;
}

#controls #fw-secondary-actions #fw-solver-row .solver-btn.active {
  background: #4a9ed3 !important;
  border-color: #2f84bb !important;
  color: #fff !important;
}

/* ============================
   Analytics popup
   ============================ */
.analytics-panel {
  position: fixed;
  top: 96px;
  right: 16px;
  width: 420px;
  max-width: 90vw;
  max-height: 60vh;
  background: #ffffff;
  border: 1px solid #d7d7e0;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: both;
  z-index: 1200;
  font-size: 11px;
}

.analytics-panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #f5f3fb;
  border-bottom: 1px solid #e2ddf2;
  font-weight: 600;
  cursor: move;
  user-select: none;
}

.analytics-panel-header .analytics-close {
  border: 1px solid #c9c3df;
  background: #fff;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  font-size: 14px;
  padding: 0;
  cursor: pointer;
}
.analytics-panel-header .analytics-close:hover { background: #f0eef8; }

.analytics-panel-body {
  padding: 6px 8px;
  overflow: auto;
  background: #fcfcff;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.analytics-table th,
.analytics-table td {
  padding: 3px 6px;
  border-bottom: 1px solid #ececf3;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analytics-table thead th {
  position: sticky;
  top: 0;
  background: #f5f5fb;
  z-index: 1;
  font-weight: 600;
}

.analytics-table tbody tr:nth-child(even) { background: #fafafe; }
.analytics-table tbody tr.row-frozen { background: #fff2f2; }

.analytics-clear {
  margin-left: auto;
  margin-right: 6px;
  padding: 3px 6px;
  font-size: 10px;
  border-radius: 4px;
  border: 1px solid #c9c3df;
  background: #fff;
  cursor: pointer;
}
.analytics-clear:hover { background: #f3f0fa; }

.analytics-title { font-weight: 600; }

.exp-mode-toggle { display: flex; gap: 4px; margin-left: auto; }

.exp-mode-btn {
  padding: 2px 6px;
  font-size: 10px;
  border-radius: 4px;
  border: 1px solid #c9c3df;
  background: #fff;
  cursor: pointer;
}
.exp-mode-btn:hover { background: #f3f0fa; }
.exp-mode-btn.active { background: #e3ddfa; border-color: #b3a2f0; }

.analytics-clear,
.analytics-close { margin-left: 4px; }

.analytics-chart-container {
  width: 100%;
  height: 220px;
  padding: 4px 0;
}

/* ============================
   Solver popup
   ============================ */
.solver-panel {
  position: fixed;
  top: 96px;
  right: 16px;
  width: 360px;
  min-width: 300px;
  min-height: 220px;
  max-width: 90vw;
  max-height: calc(100vh - 24px);
  background: #ffffff;
  border: 1px solid #d7d7e0;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1210;
  font-size: 11px;
}

.solver-resize-handle {
  position: absolute;
  z-index: 2;
  touch-action: none;
}

.solver-resize-n,
.solver-resize-s {
  left: 8px;
  right: 8px;
  height: 8px;
  cursor: ns-resize;
}

.solver-resize-n { top: -4px; }
.solver-resize-s { bottom: -4px; }

.solver-resize-e,
.solver-resize-w {
  top: 8px;
  bottom: 8px;
  width: 8px;
  cursor: ew-resize;
}

.solver-resize-e { right: -4px; }
.solver-resize-w { left: -4px; }

.solver-resize-ne,
.solver-resize-nw,
.solver-resize-se,
.solver-resize-sw {
  width: 12px;
  height: 12px;
}

.solver-resize-ne {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.solver-resize-nw {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.solver-resize-se {
  right: -4px;
  bottom: -4px;
  cursor: nwse-resize;
}

.solver-resize-sw {
  left: -4px;
  bottom: -4px;
  cursor: nesw-resize;
}

.solver-panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #f5f3fb;
  border-bottom: 1px solid #e2ddf2;
  font-weight: 600;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.solver-title { flex: 1; }

.solver-close {
  border: 1px solid #c9c3df;
  background: #fff;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}

.solver-panel-body {
  padding: 8px;
  overflow: auto;
  background: #fcfcff;
  min-height: 0;
}

.solver-field {
  display: grid;
  grid-template-columns: 122px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.solver-field input,
.solver-field select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid #cfcfd8;
  border-radius: 5px;
  font-size: 11px;
  background: #fff;
}

.solver-run {
  width: 100%;
  margin: 2px 0 6px;
  padding: 5px 8px;
  border: 1px solid #a074b8;
  border-radius: 6px;
  background: #b794c6;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.solver-run:disabled {
  opacity: 0.7;
  cursor: default;
}

.solver-status {
  min-height: 16px;
  margin-bottom: 6px;
  color: #555;
}

.solver-status.is-error { color: #b42318; }

.solver-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.solver-results-all {
  max-height: min(46vh, 420px);
  overflow: auto;
  border: 1px solid #ececf3;
  border-radius: 6px;
  background: #fff;
}

.solver-results-all .solver-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.solver-table th,
.solver-table td {
  padding: 4px 5px;
  border-bottom: 1px solid #ececf3;
  text-align: left;
  white-space: nowrap;
}

.solver-table th {
  background: #f5f5fb;
  font-weight: 600;
}

.solver-table th:nth-child(1),
.solver-table td:nth-child(1),
.solver-table th:nth-child(2),
.solver-table td:nth-child(2),
.solver-table th:nth-child(3),
.solver-table td:nth-child(3) {
  width: 13%;
}

.solver-table th:nth-child(4),
.solver-table td:nth-child(4) {
  width: 17%;
}

.solver-table th:nth-child(5),
.solver-table td:nth-child(5) {
  width: 9%;
}

.solver-table th:nth-child(6),
.solver-table td:nth-child(6) {
  width: 23%;
  white-space: normal;
}

.solver-table th:nth-child(7),
.solver-table td:nth-child(7) {
  width: 12%;
}

.solver-current-row td {
  background: #fff8e8;
  font-weight: 700;
}

.solver-compact-row td {
  background: #f3faf2;
}

.solver-current-row.solver-compact-row td {
  background: #fff8e8;
}

.solver-large-row td {
  background: #f1f7fb;
}

.solver-current-row.solver-large-row td {
  background: #fff8e8;
}

.solver-table td.solver-move-cell {
  font-weight: 700;
}

.solver-table td.solver-move-increase {
  background: #e7f6df;
  color: #315c2b;
}

.solver-table td.solver-move-decrease {
  background: #fdecef;
  color: #6a3f46;
}

.solver-table td.solver-primary-move,
.solver-compare-table td.solver-primary-move {
  font-weight: 800;
}

.solver-table td.solver-primary-move-increase,
.solver-compare-table td.solver-primary-move-increase {
  background: #d8f0cf;
  box-shadow: none;
  color: #245c1f;
}

.solver-table td.solver-primary-move-decrease,
.solver-compare-table td.solver-primary-move-decrease {
  background: #fbdde3;
  box-shadow: none;
  color: #6a3f46;
}

.solver-table td.solver-error-cell,
.solver-compare-table td.solver-error-cell {
  background: #fff3d6;
  color: #7a4a00;
  font-weight: 800;
}

.solver-table td.solver-approx-cell,
.solver-compare-table td.solver-approx-cell {
  background: #f5faf0;
  color: #45612f;
  font-weight: 700;
}

.solver-next-card {
  margin: 0 0 8px;
  padding: 8px;
  border: 1px solid #d7c7e4;
  border-radius: 6px;
  background: #fbf8ff;
  color: #3f3a45;
}

.solver-next-strategy {
  margin: 0;
}

.solver-next-separator {
  height: 1px;
  margin: 10px 0;
  border: 0;
  background: #d9d5e2;
}

.solver-compare-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 8px;
}

.solver-compare-table th,
.solver-compare-table td {
  padding: 4px 5px;
  border-bottom: 1px solid #ececf3;
  text-align: left;
  white-space: nowrap;
}

.solver-compare-table th {
  background: #f5f5fb;
  font-weight: 600;
}

.solver-compare-table th:nth-child(1),
.solver-compare-table td:nth-child(1) {
  width: 15%;
}

.solver-compare-table th:nth-child(2),
.solver-compare-table td:nth-child(2),
.solver-compare-table th:nth-child(3),
.solver-compare-table td:nth-child(3),
.solver-compare-table th:nth-child(4),
.solver-compare-table td:nth-child(4) {
  width: 14%;
}

.solver-compare-table th:nth-child(5),
.solver-compare-table td:nth-child(5) {
  width: 18%;
}

.solver-compare-table th:nth-child(6),
.solver-compare-table td:nth-child(6) {
  width: 11%;
}

.solver-compare-table th:nth-child(7),
.solver-compare-table td:nth-child(7) {
  width: 14%;
}

.solver-next-title {
  font-weight: 800;
  margin-bottom: 3px;
  font-size: 12px;
}

.solver-next-subtitle {
  color: #555;
  margin-bottom: 4px;
}

.solver-next-moves {
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
}

.solver-next-moves li {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
  padding: 2px 0;
  border-radius: 5px;
  font-weight: 500;
}

.solver-next-move-increase {
  color: #3b5d35;
}

.solver-next-move-decrease {
  color: #6f4c52;
}

.solver-next-moves li.solver-next-primary {
  font-weight: 650;
}

.solver-next-param {
  flex: 0 0 auto;
  min-width: 96px;
  padding: 2px 5px;
  border-radius: 5px;
  font-weight: 700;
}

.solver-next-values {
  color: #444;
}

.solver-next-move-increase .solver-next-param {
  background: #f1f8ee;
  color: #315c2b;
}

.solver-next-move-decrease .solver-next-param {
  background: #fff4f5;
  color: #6a3f46;
}

.solver-next-result,
.solver-next-note {
  color: #555;
  margin-top: 3px;
}

.solver-table button.solver-apply-btn,
.solver-compare-table button.solver-apply-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 2px 6px;
  border: 1px solid #9fc8e4;
  border-radius: 999px;
  background: #f8fcff;
  color: #235f86;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
  box-shadow: none;
}

.solver-table button.solver-apply-btn:hover,
.solver-compare-table button.solver-apply-btn:hover {
  background: #e7f5fd;
  border-color: #68a9d8;
  box-shadow: none;
}

.solver-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  color: #666;
  font-size: 10px;
}

.solver-legend span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.solver-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid transparent;
}

.solver-key-current {
  background: #fff8e8;
  border-color: #e1c77d !important;
}

.solver-key-increase {
  background: #e4f7df;
  border-color: #7fc66f !important;
}

.solver-key-decrease {
  background: #fff1f3;
  border-color: #e8b8c0 !important;
}

/* ============================
   Wingbeat solver popup
   ============================ */
#fw-secondary-actions .wingbeat-solver-btn {
  width: 100%;
  margin-top: 0;
}

#controls #fw-solver-row {
  gap: 3px;
  justify-content: flex-start;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

#controls #fw-solver-row button.solver-btn {
  appearance: none;
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0 !important;
  padding: 4px 5px !important;
  border: 1px solid #9fc8e4 !important;
  border-radius: 6px !important;
  background: #f8fcff !important;
  color: #28658d !important;
  font-size: 10.5px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  box-shadow: none !important;
}

#controls #fw-solver-row button.solver-btn:hover {
  background: #eef7fd !important;
  border-color: #75acd3 !important;
}

#controls #fw-solver-row button.solver-btn.active {
  background: #e1f1fb !important;
  border-color: #5fa4d4 !important;
  color: #195f91 !important;
}

#canvas-container #fw-solver-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: flex-end;
  align-items: stretch;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

#canvas-container #fw-solver-row button.solver-btn {
  appearance: none;
  flex: 0 0 auto;
  width: 82px !important;
  min-width: 0 !important;
  padding: 4px 6px !important;
  border: 1px solid #9fc8e4 !important;
  border-radius: 6px !important;
  background: #f8fcff !important;
  color: #28658d !important;
  font-size: 10.5px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  box-shadow: none !important;
}

#canvas-container #fw-solver-row button.solver-btn:hover {
  background: #eef7fd !important;
  border-color: #75acd3 !important;
}

#canvas-container #fw-solver-row button.solver-btn.active {
  background: #e1f1fb !important;
  border-color: #5fa4d4 !important;
  color: #195f91 !important;
}

.wingbeat-panel {
  position: fixed;
  top: 120px;
  right: 40px;
  width: 560px;
  min-width: 320px;
  min-height: 220px;
  max-width: 90vw;
  max-height: calc(100vh - 24px);
  background: #ffffff;
  border: 1px solid #d7d7e0;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1211;
  font-size: 11px;
}

.wingbeat-panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #f4f7ef;
  border-bottom: 1px solid #dbe8cd;
  font-weight: 600;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.wingbeat-title { flex: 1; }

.wingbeat-close {
  border: 1px solid #bdcda9;
  background: #fff;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}

.wingbeat-panel-body {
  padding: 8px;
  overflow: auto;
  background: #fcfef9;
  min-height: 0;
}

.wingbeat-field {
  display: grid;
  grid-template-columns: 122px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.wingbeat-field input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid #cfcfd8;
  border-radius: 5px;
  font-size: 11px;
  background: #fff;
}

.wingbeat-field textarea {
  width: 100%;
  min-height: 92px;
  padding: 4px 6px;
  border: 1px solid #cfcfd8;
  border-radius: 5px;
  font-size: 11px;
  line-height: 1.3;
  background: #fff;
  resize: vertical;
}

.wingbeat-field-tall {
  align-items: start;
}

.wingbeat-hint {
  margin: 0 0 6px;
  color: #666;
  font-size: 10px;
}

.wingbeat-run {
  width: 100%;
  margin: 2px 0 6px;
  padding: 5px 8px;
  border: 1px solid #7fa363;
  border-radius: 6px;
  background: #91b873;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.wingbeat-run:disabled {
  opacity: 0.7;
  cursor: default;
}

.wingbeat-status {
  min-height: 16px;
  margin-bottom: 6px;
  color: #555;
}

.wingbeat-status.is-error { color: #b42318; }

.wingbeat-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.wingbeat-table th,
.wingbeat-table td {
  padding: 4px 5px;
  border-bottom: 1px solid #ececf3;
  text-align: left;
  white-space: nowrap;
}

.wingbeat-table th {
  background: #f5f8ef;
  font-weight: 600;
}

.wingbeat-table th:nth-child(1),
.wingbeat-table td:nth-child(1) {
  width: 12%;
}

.wingbeat-table th:nth-child(2),
.wingbeat-table td:nth-child(2),
.wingbeat-table th:nth-child(7),
.wingbeat-table td:nth-child(7),
.wingbeat-table th:nth-child(8),
.wingbeat-table td:nth-child(8) {
  width: 8%;
}

.wingbeat-table th:nth-child(3),
.wingbeat-table td:nth-child(3),
.wingbeat-table th:nth-child(4),
.wingbeat-table td:nth-child(4),
.wingbeat-table th:nth-child(5),
.wingbeat-table td:nth-child(5) {
  width: 11%;
}

.wingbeat-table th:nth-child(6),
.wingbeat-table td:nth-child(6) {
  width: 15%;
}

.wingbeat-table th:nth-child(9),
.wingbeat-table td:nth-child(9) {
  width: 12%;
}

.wingbeat-row-exact td:first-child,
.wingbeat-row-near td:first-child {
  color: #245c1f;
  font-weight: 700;
}

.wingbeat-row-empty td {
  color: #777;
  background: #fafafa;
}

.wingbeat-cell-increase {
  background: #e7f6df;
  color: #315c2b;
  font-weight: 700;
}

.wingbeat-cell-decrease {
  background: #fdecef;
  color: #6a3f46;
  font-weight: 700;
}

.wingbeat-error-exact {
  color: #245c1f;
  font-weight: 700;
}

.wingbeat-error-near {
  background: #fff8e8;
  color: #7a4a00;
  font-weight: 700;
}

.wingbeat-error-far {
  background: #fff3d6;
  color: #7a4a00;
  font-weight: 700;
}

.wingbeat-table button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 2px 6px;
  border: 1px solid #9fc8e4;
  border-radius: 999px;
  background: #f8fcff;
  color: #235f86;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
}

.wingbeat-table button:hover { background: #e7f5fd; }

.wingbeat-resize-handle {
  position: absolute;
  z-index: 2;
  touch-action: none;
}

.wingbeat-resize-n,
.wingbeat-resize-s {
  left: 8px;
  right: 8px;
  height: 8px;
  cursor: ns-resize;
}

.wingbeat-resize-n { top: -4px; }
.wingbeat-resize-s { bottom: -4px; }

.wingbeat-resize-e,
.wingbeat-resize-w {
  top: 8px;
  bottom: 8px;
  width: 8px;
  cursor: ew-resize;
}

.wingbeat-resize-e { right: -4px; }
.wingbeat-resize-w { left: -4px; }

.wingbeat-resize-ne,
.wingbeat-resize-nw,
.wingbeat-resize-se,
.wingbeat-resize-sw {
  width: 12px;
  height: 12px;
}

.wingbeat-resize-ne {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.wingbeat-resize-nw {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.wingbeat-resize-se {
  right: -4px;
  bottom: -4px;
  cursor: nwse-resize;
}

.wingbeat-resize-sw {
  left: -4px;
  bottom: -4px;
  cursor: nesw-resize;
}

/* ===== Link color swatches ===== */
#controls input[type=color] {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 3px;
  cursor: pointer;
  flex: 0 0 auto;
  background: none;
  -webkit-appearance: none;
}
#controls input[type=color]::-webkit-color-swatch-wrapper {
  padding: 1px;
  border-radius: 2px;
}
#controls input[type=color]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

/* ===== Canvas scale buttons ===== */
#canvas-container {
  position: relative;
}

/* ===== Sidebar readout section ===== */
.readout-row {
  padding: 1px 0;
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Floating readout overlay ===== */
.readout-overlay {
  position: absolute;
  bottom: 60px;
  left: 12px;
  min-width: 160px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 200;
  user-select: none;
}

.readout-overlay-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  cursor: move;
  border-radius: 8px 8px 0 0;
  background: rgba(245,243,251,0.9);
}

.readout-overlay-body {
  padding: 6px 10px;
  font-family: monospace;
  line-height: 1.65;
  color: #333;
}

.ro-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 13px;
  line-height: 18px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  flex: 0 0 auto;
}
.ro-btn:hover { background: #f0eef8; }

/* Canvas fills container flush, no border gap */
#canvas-container canvas {
  display: block;
  flex-shrink: 0;
}
