/*
 * Sidebar Panel — persistent right-side properties panel that replaces the
 * cursor-anchored right-click sprite menu (see code-docs/sidebar/).
 * Official tokens: navy #212F52, blue #0677BB, Rubik, white-frosted, radius 12.
 * Purely additive: hidden when window.Sidebar.enabled === false.
 */

#sidebar-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 288px;
  z-index: 60; /* above canvas + bottom controls, below modals */
  background-color: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-family: Rubik, sans-serif;
  color: #212f52;
  display: flex;
  flex-direction: column;
  /* Not overflow: hidden - that clipped the open/close tab (.sp-tab), which sits
     just outside the panel's left edge. The contents scroll in .sp-content. */
  transform: translateX(calc(100% + 16px)); /* collapsed = off-screen right */
  transition: transform 0.25s ease;
  box-sizing: border-box;
}

#sidebar-panel.sp-open {
  transform: translateX(0);
}

/* Collapse/expand tab on the left edge of the panel. */
.sp-tab {
  position: absolute;
  left: -30px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 60px;
  border: none;
  border-radius: 10px 0 0 10px;
  background-color: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.18);
  color: #212f52;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sp-tab svg {
  width: 16px;
  height: 16px;
  transition: transform 0.25s ease;
}
/* Closed, the panel sits 4px past the screen edge (hiding its shadow): keep the
   whole tab on screen. */
#sidebar-panel:not(.sp-open) .sp-tab {
  left: -34px;
}
/* Chevron points right (collapse) when open, left (expand) when closed. */
#sidebar-panel.sp-open .sp-tab svg {
  transform: rotate(180deg);
}

/* ---- Header ---- */
.sp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  flex-shrink: 0;
}
.sp-title {
  font-size: 16px;
  font-weight: 600;
  color: #212f52;
}
.sp-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(33, 47, 82, 0.35);
  flex-shrink: 0;
}
.sp-select-mode-btn {
  margin-left: auto;
  border: 1px solid rgba(33, 47, 82, 0.3);
  background: transparent;
  color: #212f52;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}
.sp-select-mode-btn.sp-active {
  background: #0677bb;
  border-color: #0677bb;
  color: #fff;
}

/* ---- Content ---- */
.sp-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0 16px 16px;
  /* Scrollable but with no visible scrollbar (Firefox + IE/Edge legacy). */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
/* Hide the scrollbar in WebKit/Blink while keeping scroll functional. */
.sp-content::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.sp-empty {
  color: rgba(33, 47, 82, 0.6);
  font-size: 14px;
  font-style: italic;
  padding: 24px 4px;
  text-align: center;
}

.sp-hint {
  margin-top: 8px;
  font-size: 12px;
  color: rgba(33, 47, 82, 0.6);
  line-height: 1.4;
}

/* Grouped section */
.sp-section {
  margin-top: 12px;
}
.sp-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(33, 47, 82, 0.55);
  margin-bottom: 6px;
}

/* Read-only rows */
.sp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
}
.sp-row .sp-key {
  color: rgba(33, 47, 82, 0.7);
}
.sp-row .sp-val {
  color: #212f52;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Sail-state readout */
.sp-sailstate {
  background-color: rgba(6, 119, 187, 0.08);
  border: 1px solid rgba(6, 119, 187, 0.2);
  border-radius: 8px;
  padding: 8px 10px;
}
.sp-sailstate .sp-row {
  padding: 3px 0;
}
.sp-pos {
  font-weight: 600;
  color: #0677bb;
}

.sp-text-input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
  color: #212f52;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(33, 47, 82, 0.2);
  border-radius: 6px;
  outline: none;
}
.sp-text-input:focus {
  border-color: #0677bb;
}

/* Color grid */
.sp-colorgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 22px);
  gap: 6px;
  margin-top: 4px;
}
.sp-color {
  width: 22px;
  height: 22px;
  aspect-ratio: 1;
  border-radius: 5px;
  border: 2px solid transparent;
  border-radius: 6px;
  border: 2px solid #d7dbe3;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.sp-color:hover {
  transform: scale(1.08);
}
.sp-color.sp-color-active {
  border-color: #212f52;
}

/* "No color" swatch: a checkerboard pattern, the standard transparency cue */
.sp-color-none {
  background-image: linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%),
    linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
  background-color: #fff;
}

/* Smaller, lower-emphasis color grid (e.g. Wind Shift arrow/circle colors) */
.sp-colorgrid-sm {
  grid-template-columns: repeat(auto-fill, 16px);
  gap: 3px;
}
.sp-colorgrid-sm .sp-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border-width: 1px;
}

/* Buttons + toggles */
.sp-btn {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: Rubik, sans-serif;
  border: none;
  border-radius: 8px;
  background-color: #212f52;
  color: #fff;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.sp-btn:hover {
  background-color: #454c5c;
}
.sp-btn-block {
  display: block;
  width: 100%;
}
.sp-btn-danger {
  background-color: #eb0202;
}
.sp-btn-danger:hover {
  background-color: #b40202;
}
.sp-btn-toggle {
  background-color: rgba(105, 115, 138, 0.336);
  color: #212f52;
}
.sp-btn-toggle.sp-toggle-on {
  background-color: #0677bb;
  color: #fff;
}

.sp-btn-row {
  display: flex;
  gap: 8px;
}
.sp-btn-row .sp-btn {
  flex: 1;
}

/* Boat type selector grid */
.sp-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.sp-type-btn {
  width: 100%;
}

/* Sail manual controls */
.sp-sail-controls {
  margin-top: 6px;
}
.sp-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.sp-slider-row input[type="range"] {
  flex: 1;
  accent-color: #0677bb;
}
.sp-slider-row.sp-disabled {
  opacity: 0.45;
  pointer-events: none;
}
.sp-slider-val {
  width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.sp-text-input {
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.sp-text-input:focus {
  outline: none;
  border-color: #0677bb;
  box-shadow: 0 0 0 2px rgba(6, 119, 187, 0.2);
}

.sp-select {
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background-color: #fff;
  color: #212f52;
}
.sp-select:focus {
  outline: none;
  border-color: #0677bb;
}

/* Roundings Drawn (marks) */
.sp-rounding-block {
  border: 1px solid rgba(33, 47, 82, 0.15);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}
.sp-rounding-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sp-rounding-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(33, 47, 82, 0.7);
}
.sp-rounding-remove {
  border: none;
  background: none;
  color: rgba(33, 47, 82, 0.5);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.sp-rounding-remove:hover {
  color: #eb0202;
}
.sp-rounding-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.sp-rounding-row .sp-rounding-field {
  flex: 1;
}
.sp-rounding-field {
  margin-top: 6px;
}
.sp-rounding-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(33, 47, 82, 0.55);
}
.sp-rounding-angle-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp-rounding-angle-row .sp-text-input {
  flex: 1;
}
.sp-rounding-angle-unit {
  font-size: 13px;
  font-weight: 600;
  color: rgba(33, 47, 82, 0.55);
}

/* Selected sprite highlight (applied to the sprite element on the canvas). */
.sprite-selected {
  outline: 2px solid #0677bb !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(6, 119, 187, 0.25) !important;
  border-radius: 6px;
}
.sprite-selected-round {
  box-shadow: 0 0 0 4px rgba(6, 119, 187, 0.35) !important;
  border-radius: 50%;
}

/* Selected Wind Shift bubble: darken its border so it's clear which one
   right-click opened the panel for. */
.windshift-selected {
  border: 2px solid rgba(0, 0, 0, 0.55) !important;
  box-sizing: border-box;
}

/* The video / image / timer / quiz / rule box whose properties are open. */
.extra-selected {
  outline: 2px solid #0677bb !important;
  outline-offset: 3px;
}

/* Multi-selected sprites (Select mode, sidebar-panel.js) — distinct from the
   single-selection outline above so both states are visually distinguishable. */
.sprite-multiselected {
  outline: 2px dashed #ff5c00 !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(255, 92, 0, 0.25) !important;
}

/* Select mode: the box dragged on empty board to select what it touches */
.sp-marquee {
  position: fixed;
  z-index: 5000;
  pointer-events: none;
  border: 1.5px dashed #ff5c00;
  background: rgba(255, 92, 0, 0.08);
  border-radius: 2px;
}

/* Select-mode: list of currently selected sprites */
.sp-multi-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sp-multi-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(33, 47, 82, 0.06);
  font-size: 13px;
}
.sp-multi-label {
  color: #212f52;
  font-weight: 500;
}
.sp-multi-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.sp-multi-expand {
  border: 1px solid rgba(6, 119, 187, 0.4);
  background: rgba(6, 119, 187, 0.08);
  color: #0677bb;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.sp-multi-expand:hover {
  background: rgba(6, 119, 187, 0.18);
}
.sp-multi-remove {
  border: none;
  background: none;
  color: rgba(33, 47, 82, 0.5);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.sp-multi-remove:hover {
  color: #eb0202;
}

/* ---- Desktop reflow: when the sidebar is open, move the overlay controls out
 *      from under it so nothing interactive is occluded (see step 06). The
 *      canvas itself is left to sit under the translucent panel — same as the
 *      timeline panel — because insetting #cropContainer would shift the sprite
 *      coordinate space and risk drag/hit-test drift. The Tools menu is left
 *      alone: its closed state is parked off-screen via a transform, so nudging
 *      it would reveal the hidden panel — the tab simply tucks behind the
 *      sidebar while a sprite is selected (deselect to reach Tools). Mobile
 *      overlays instead, so these only apply above the mobile breakpoint.
 *      Sidebar footprint = 288 width + 12 right gap = ~300. ---- */
#timeline-panel,
#top-right-ui,
#zoom-pan-controls,
#help_btn,
#report_bug,
#chat-toggle {
  transition: right 0.25s ease, bottom 0.25s ease;
}

@media (min-width: 769px) {
  body.sidebar-open #timeline-panel { right: 312px; }
  body.sidebar-open #top-right-ui { right: 310px; }
  body.sidebar-open #zoom-pan-controls { right: 306px; }
  body.sidebar-open #help_btn { right: 306px; }
  body.sidebar-open #report_bug { right: 393px; }
  body.sidebar-open #chat-toggle { right: 320px; }
}

/* ---- Mobile: overlay full-height drawer instead of squeezing ---- */
@media (max-width: 768px) {
  #sidebar-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(86vw, 320px);
    border-radius: 0;
  }
  #sidebar-panel.sp-open {
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.35);
  }
  /* On mobile the sidebar overlays; keep the timeline full-width. */
  body.sidebar-open #timeline-panel {
    right: 6px;
  }
}

/* Text bubble: its text, editable in the panel too */
.sp-text-area { resize: vertical; min-height: 60px; line-height: 1.4; }

/* Keyboard shortcuts list (shortcuts.js; Ctrl/⌘ + / or Help → Keyboard shortcuts) */
.st-shortcuts-back { position: fixed; inset: 0; z-index: 6000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, 0.45); }
.st-shortcuts { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px 24px 24px; border-radius: 14px; background: #fff; color: #212F52; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); font-family: Rubik, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.st-shortcuts-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.st-shortcuts-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.st-shortcuts-close { width: 34px; height: 34px; border: none; border-radius: 50%; background: none; font-size: 22px; line-height: 1; color: #64748b; cursor: pointer; }
.st-shortcuts-close:hover { background: #f1f5f9; }
.st-shortcuts-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 4px 28px; }
.st-shortcuts section h3 { margin: 14px 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; }
.st-shortcut { display: flex; align-items: baseline; gap: 12px; padding: 5px 0; font-size: 14px; border-top: 1px solid #f1f5f9; }
.st-shortcut-keys { flex: 0 0 160px; white-space: nowrap; color: #475569; font-size: 12px; }
.st-shortcut-what { flex: 1 1 auto; }
.st-shortcut kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 5px; background: #f8fafc; font: 600 12px/1.6 Rubik, -apple-system, sans-serif; text-align: center; color: #212F52; }

/* Arrival / start time of a boat position (boat-timing.js) */
.sp-time-row {
  align-items: center;
  margin-bottom: 6px;
}
.sp-time-row .sp-text-input {
  flex: 1;
  margin-top: 0;
}
.sp-time-btn {
  margin-bottom: 6px;
}

/* A clock's time (extramenu.js createTimer): big, even-width digits, and
   start-sequence presets. */
.sp-time-input {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 8px;
}
.sp-time-presets {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 8px;
}
.sp-time-presets .sp-btn {
  font-variant-numeric: tabular-nums;
}
.sp-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
