* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body { height: 100%; background: #131722; color: #d1d4dc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }

#chartWrap { position: relative; height: 100vh; height: 100dvh; background: #ffffff; }
#chart { width: 100%; height: 100%; }

/* --- Floating Action Menu --- */
.floating-menu {
  position: absolute; top: 16px; left: 16px; z-index: 50;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  transition: opacity 0.2s ease;
}
.floating-menu.hidden { opacity: 0; pointer-events: none; }

.fab-trigger {
  width: clamp(28px, 5vw, 38px);
  height: clamp(28px, 5vw, 38px);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.03);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  outline: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  color: #131722;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.15s;
  user-select: none;
}
.fab-trigger:hover { background: rgba(0, 0, 0, 0.06); }
.fab-trigger:active, .fab-trigger:focus {
  outline: none;
  background: rgba(0, 0, 0, 0.08);
}
.fab-trigger svg {
  width: clamp(14px, 2.5vw, 18px);
  height: clamp(14px, 2.5vw, 18px);
  transition: transform 0.2s ease;
}
.floating-menu.expanded .fab-trigger svg { transform: rotate(90deg); }

.fab-menu-content {
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(30, 34, 45, 0.35);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  opacity: 0; visibility: hidden; transform: translateY(-8px) scale(0.97);
  transform-origin: top left;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.175,0.885,0.32,1.275), visibility 0.2s;
}
.floating-menu.expanded .fab-menu-content {
  opacity: 1; visibility: visible; transform: translateY(0) scale(1);
}

.fab-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: transparent; border: none; border-radius: 6px;
  color: #e8eaed;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 0.15s; white-space: nowrap;
  outline: none;
}
.fab-item:hover { background: rgba(255, 255, 255, 0.1); }
.fab-item svg { color: #9aa0ac; transition: color 0.15s; }
.fab-item:hover svg { color: #ffffff; }

/* --- Annotations (Dark Glass + Premium) --- */
.annotation-layer { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.annotation-pins { position: absolute; inset: 0; pointer-events: none; }

.note-pin {
  position: absolute; width: 12px; height: 12px; border-radius: 50%;
  background: #ffffff;
  border: 2px solid rgba(30, 34, 45, 0.8);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transform: translate(-50%,-50%); pointer-events: auto; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s;
}
.note-pin:hover {
  transform: translate(-50%,-50%) scale(1.3);
  background: #2962ff; /* Turns blue on hover */
  border-color: #ffffff;
  box-shadow: 0 4px 12px rgba(41,98,255,0.4);
}

.note-popup {
  position: absolute; display: block; min-width: 200px; max-width: 280px;
  background: rgba(30, 34, 45, 0.75);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
  pointer-events: auto; z-index: 100;
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.175,0.885,0.32,1.275), visibility 0.18s;
  transform: translate(-100%,-50%) scale(0.92); transform-origin: right center;
  margin-left: -18px;
}
.note-popup.flip-right {
  transform: translate(0%,-50%) scale(0.92); transform-origin: left center;
  margin-left: 18px;
}
.note-popup.active { opacity: 1; visibility: visible; }
.note-popup.active:not(.flip-right) { transform: translate(-100%,-50%) scale(1); }
.note-popup.active.flip-right { transform: translate(0%,-50%) scale(1); }

/* The arrow points back to the candle */
.note-leader {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 0; height: 0; right: -9px;
  border-top: 9px solid transparent; border-bottom: 9px solid transparent;
  border-left: 9px solid rgba(30, 34, 45, 0.75);
}
.note-popup.flip-right .note-leader {
  right: auto; left: -9px;
  border-left: none; border-right: 9px solid rgba(30, 34, 45, 0.75);
}

/* The text area */
.note-text {
  width: 100%; background: transparent; border: none;
  padding: 14px 14px 14px 14px; color: #e8eaed;
  font-family: inherit; font-size: 13px; font-weight: 400;
  resize: vertical; outline: none; line-height: 1.5;
  border-radius: 10px;
  transition: box-shadow 0.2s ease;
  min-height: 48px;
}
.note-text::placeholder { color: #787b86; font-style: italic; }
.note-text:focus {
  box-shadow: inset 0 0 0 2px rgba(41, 98, 255, 0.3);
}

/* The subtle delete icon */
.note-delete {
  position: absolute; top: 8px; right: 8px;
  background: transparent; color: #787b86;
  border: none; border-radius: 4px;
  width: 20px; height: 20px; font-size: 12px; font-weight: bold;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  outline: none;
}
.note-delete:hover {
  color: #ff4757;
  background: rgba(255, 71, 87, 0.1);
}

/* --- Popups & Settings --- */
:root {
  --surface-overlay-bg: rgba(30, 34, 45, 0.85);
  --surface-overlay-border: rgba(255, 255, 255, 0.08);
  --surface-overlay-blur: 16px;
  --shadow-overlay: 0 20px 40px -10px rgba(0, 0, 0, 0.55);
  --shadow-modal: 0 32px 64px -12px rgba(0, 0, 0, 0.7);
  --radius-lg: 12px; --radius-md: 8px; --radius-sm: 6px;
  --text-primary: #e8eaed; --text-secondary: #9aa0ac;
  --accent: #2962ff; --accent-hover: #1e53e5;
}

.context-menu {
  display: none; position: fixed; z-index: 1000;
  padding: 6px; min-width: 160px;
  background: var(--surface-overlay-bg);
  backdrop-filter: blur(var(--surface-overlay-blur));
  border: 1px solid var(--surface-overlay-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  animation: contextMenuIn 0.15s ease-out;
}
@keyframes contextMenuIn {
  from { opacity: 0; transform: scale(0.96) translateY(-6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.context-menu.active { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px; cursor: pointer; color: var(--text-primary);
  border-radius: var(--radius-sm); transition: background 0.15s;
  font-weight: 500; font-size: 13px;
  outline: none;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.menu-item svg { color: var(--text-secondary); }
.menu-item:hover svg { color: var(--accent); }

.settings-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px);
  z-index: 1000; opacity: 0; transition: opacity 0.2s;
}
.settings-overlay.active { display: block; opacity: 1; }

.settings-panel {
  display: none; position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  width: 400px; max-width: calc(100vw - 32px);
  background: var(--surface-overlay-bg);
  backdrop-filter: blur(var(--surface-overlay-blur));
  border: 1px solid var(--surface-overlay-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  z-index: 1001; opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.settings-panel.active {
  display: flex; flex-direction: column;
  opacity: 1; transform: translate(-50%, -50%) scale(1);
}

.settings-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-weight: 600; font-size: 15px; color: var(--text-primary);
}
.close-btn {
  background: transparent; border: none; color: var(--text-secondary);
  font-size: 16px; cursor: pointer; transition: color 0.15s;
  outline: none;
}
.close-btn:hover { color: #ef5350; }

.settings-tabs {
  display: flex; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0 16px; gap: 8px;
}
.tab-btn {
  background: none; border: none; padding: 12px 8px;
  color: var(--text-secondary); font-size: 13px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  outline: none;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.settings-body {
  padding: 16px; max-height: 65vh; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
.settings-body::-webkit-scrollbar { width: 6px; }
.settings-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }

.tab-content { display: none; flex-direction: column; gap: 20px; }
.tab-content.active { display: flex; }

.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section-title {
  font-size: 11px; text-transform: uppercase; color: var(--text-secondary);
  letter-spacing: 0.08em; font-weight: 600; margin-bottom: 2px;
}

.toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; cursor: pointer; padding: 4px 0; color: var(--text-primary);
  outline: none;
}
.toggle-row input[type="checkbox"] { display: none; }
.toggle-switch {
  position: relative; width: 36px; height: 20px;
  background: rgba(255, 255, 255, 0.1); border-radius: 20px; transition: background 0.2s;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #fff;
  border-radius: 50%; transition: transform 0.2s;
}
.toggle-row input:checked + .toggle-switch { background: var(--accent); }
.toggle-row input:checked + .toggle-switch::after { transform: translateX(16px); }

.btn-save, .btn-reset {
  width: 100%; padding: 9px; border-radius: var(--radius-md);
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background 0.15s; border: 1px solid transparent;
  margin-top: 4px;
  outline: none;
}
.btn-save { background: var(--accent); color: #fff; }
.btn-save:hover { background: var(--accent-hover); }
.btn-reset {
  background: rgba(255, 255, 255, 0.06); color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.08);
}
.btn-reset:hover { background: rgba(255, 255, 255, 0.1); }

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-group label { font-size: 12px; color: var(--text-primary); font-weight: 500; }
.mt-4 { margin-top: 8px; }

.select-input {
  width: 100%; padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm); color: #fff; font-size: 13px;
  outline: none; cursor: pointer;
}
.select-input:focus { border-color: var(--accent); }
.select-input option { background: #1e222d; color: #fff; }

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="range"] {
  flex: 1; accent-color: var(--accent); height: 4px;
  background: rgba(255, 255, 255, 0.1); border-radius: 2px;
  -webkit-appearance: none; outline: none;
}
.color-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  background: var(--accent); border-radius: 50%; cursor: pointer; border: 2px solid #1e222d;
}
.color-row span {
  font-size: 12px; color: var(--text-secondary);
  width: 40px; text-align: right; font-variant-numeric: tabular-nums;
}
input[type="color"] {
  width: 28px; height: 28px; padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #131722; cursor: pointer; border-radius: var(--radius-sm);
  outline: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-cell { display: flex; flex-direction: column; gap: 4px; }
.color-cell label { font-size: 12px; color: var(--text-secondary); }

.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-overlay-bg);
  backdrop-filter: blur(var(--surface-overlay-blur));
  border: 1px solid var(--surface-overlay-border);
  color: #fff; padding: 10px 20px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
