html, body { height: 100%; margin: 0; overflow: hidden; background: #ffffff; }
#hud {
  position: fixed; left: 12px; top: 172px; z-index: 10;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 13px; line-height: 1.35;
  color: #0b0f14; background: rgba(255,255,255,.92);
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 12px; padding: 14px 16px; max-width: 340px;
  backdrop-filter: blur(8px);
}
#hud b { color: #0b0f14; }
#hud .row { margin-top: 10px; }
#hud .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: #3a4653; }
#hud .small { font-size: 12px; color: #3a4653; }
a { color: #0b5fff; text-decoration: none; }
a:hover { text-decoration: underline; }
canvas { display:block; }

/* Fullscreen button */
.fullscreen-btn {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 14px;
  background: linear-gradient(to bottom, #333, #222);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.fullscreen-btn:hover {
  background: linear-gradient(to bottom, #444, #333);
}

/* Floating collapse button (hidden by default) */
.collapse-btn {
  display: none;
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.15s ease;
}
.collapse-btn:hover {
  background: rgba(0, 0, 0, 0.85);
  border-color: rgba(255, 255, 255, 0.5);
}

/* Fullscreen mode - hide UI elements but keep date and angle readouts */
body.fullscreen-mode #hud,
body.fullscreen-mode #rightPanel,
body.fullscreen-mode #timelineBar {
  display: none !important;
}
body.fullscreen-mode .collapse-btn {
  display: block;
}

/* Mobile mode - hide everything except small year display */
body.mobile-mode #angleReadout,
body.mobile-mode #yearReadout #yearInput,
body.mobile-mode .collapse-btn {
  display: none !important;
}
body.mobile-mode #yearReadout #yearBig {
  font-size: 24px;
}

/* Right Panel */
#rightPanel {
  position: fixed;
  right: 12px;
  top: 120px;
  bottom: 165px;
  width: 360px;
  z-index: 10;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#rightPanel .panel-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #888;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

#rightPanel .preset-buttons {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.story-preset-btn {
  flex: 1;
  padding: 10px 8px;
  background: #0066aa;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.story-preset-btn:hover {
  background: #0088dd;
}

.story-preset-btn.active {
  background: #d00000;
  box-shadow: 0 2px 8px rgba(208,0,0,0.3);
}

#storyContent {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: #333;
}

#storyContent h2 {
  font-size: 18px;
  font-weight: 700;
  color: #111;
  margin: 0 0 12px 0;
  line-height: 1.3;
}

#storyContent p {
  margin: 0 0 14px 0;
}

#storyContent ul {
  margin: 0 0 14px 0;
  padding-left: 20px;
}

#storyContent li {
  margin-bottom: 6px;
}

/* Custom scrollbar for story content */
#storyContent::-webkit-scrollbar {
  width: 6px;
}
#storyContent::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
  border-radius: 3px;
}
#storyContent::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
}
#storyContent::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.3);
}

/* HUD Sections */
.hud-section {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.hud-section:last-of-type {
  margin-bottom: 8px;
  padding-bottom: 0;
  border-bottom: none;
}
.section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #888;
  margin-bottom: 10px;
}

/* Modern Box-Style Toggles */
.toggle-group {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toggle-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 70px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.04);
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  gap: 6px;
}

.toggle-box:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
}

.toggle-box input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-box .toggle-label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-align: center;
  transition: color 0.15s ease;
}

/* Lock icon - hidden by default */
.toggle-box .lock-icon {
  display: none;
  font-size: 12px;
}

/* Show lock icon when lock toggle is checked */
.toggle-box.lock-toggle:has(input:checked) .lock-icon {
  display: inline;
}

/* Selected state for radio toggles */
.toggle-box:has(input:checked) {
  background: #d00000;
  border-color: #d00000;
  box-shadow: 0 2px 8px rgba(208,0,0,0.3);
}

.toggle-box:has(input:checked) .toggle-label {
  color: #fff;
}

/* "None" lock option - different color when selected */
.toggle-box.lock-toggle:has(input[value="none"]:checked) {
  background: #666;
  border-color: #666;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Checkbox toggle (slightly different style) */
.toggle-box.checkbox:has(input:checked) {
  background: #0066aa;
  border-color: #0066aa;
  box-shadow: 0 2px 8px rgba(0,102,170,0.3);
}

/* Disabled/locked slider groups */
.slider-group.locked {
  opacity: 0.4;
  pointer-events: none;
}
.slider-group.locked .slider-title::after {
  content: ' 🔒';
  font-size: 10px;
}

/* Slider Groups */
.slider-group {
  margin-bottom: 14px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.slider-title {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.slider-value {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: #000;
  min-width: 100px;
  text-align: right;
}

#hud input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

#hud input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #fff;
  border: 2px solid #d00000;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: transform 0.1s ease;
}

#hud input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

#hud input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #fff;
  border: 2px solid #d00000;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#angleReadout{
  position: fixed; left: 12px; top: 12px; z-index: 20;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-weight: 900;
  font-size: 56px;
  line-height: 1.0;
  color: #d00000;
  background: transparent;
  padding: 0;
  margin: 0;
  pointer-events: none;
  user-select: none;
}
#angleReadout .sub{
  font-size: 28px;
  font-weight: 800;
  margin-top: 6px;
}

#yearReadout {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 20;
  text-align: right;
}

#yearReadout #yearBig {
  display: block;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-weight: 900;
  font-size: 56px;
  line-height: 1.0;
  color: #d00000;
}

#yearReadout input[type="number"] {
  margin-top: 8px;
  width: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 4px;
  text-align: right;
}


.btn {
  appearance: none;
  border: 1px solid rgba(0,0,0,.35);
  background: rgba(255,255,255,.85);
  color: #000;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
}
.btn:hover { background: rgba(255,255,255,1); }
.btn:active { transform: translateY(1px); }

/* Timeline bar at bottom */
#timelineBar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 150px;
  background: rgba(255,255,255,0.95);
  border-top: 1px solid rgba(0,0,0,0.15);
  padding: 12px 24px 14px;
  z-index: 100;
  backdrop-filter: blur(6px);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* Timeline controls */
#timelineControls {
  position: absolute;
  top: 12px;
  right: 24px;
  z-index: 10;
}

.timeline-mode-btn {
  padding: 4px 12px;
  background: #666;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.timeline-mode-btn:hover {
  background: #555;
}

.timeline-mode-btn[data-mode="expanded"] {
  background: #0066aa;
}

.timeline-mode-btn[data-mode="expanded"]:hover {
  background: #0077bb;
}

/* Preset markers on timeline */
#presetMarkers {
  position: relative;
  width: 100%;
  height: 30px;
  flex-shrink: 0;
  margin-bottom: 8px;
}

.preset-marker {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.preset-marker:hover {
  transform: translateX(-50%) scale(1.05);
}

.preset-marker-btn {
  background: #0066aa;
  color: white;
  border: none;
  font-size: 9px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.preset-marker-btn:hover {
  background: #0088dd;
}

.preset-marker-btn.active {
  background: #d00000;
  box-shadow: 0 2px 6px rgba(208,0,0,0.4);
}

.preset-marker-btn.active + .preset-marker-line {
  background: #d00000;
}

.preset-marker-line {
  width: 2px;
  height: 6px;
  background: #0066aa;
}

#tickScale {
  position: relative;
  width: 100%;
  height: 22px;
  flex-shrink: 0;
  margin-bottom: 6px;
}

#tickScale .tick {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}

#tickScale .tick-line {
  width: 1px;
  background: rgba(0,0,0,0.4);
}

#tickScale .tick-line.major { height: 10px; width: 2px; }
#tickScale .tick-line.medium { height: 6px; }
#tickScale .tick-line.minor { height: 4px; background: rgba(0,0,0,0.25); }

#tickScale .tick-label {
  font-size: 9px;
  color: #555;
  margin-top: 2px;
  white-space: nowrap;
}

#dynastyTrack {
  position: relative;
  width: 100%;
  height: 28px;
  flex-shrink: 0;
  margin-bottom: 10px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(0,0,0,0.08);
}

#dynastyTrack .dynasty {
  position: absolute;
  height: 100%;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.3);
  box-sizing: border-box;
}

#timelineBar input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
  margin: 0;
  background: transparent;
}

#timelineBar input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 12px;
  background: linear-gradient(to bottom, #ddd, #ccc);
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.2);
}

#timelineBar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #fff;
  border: 2px solid #666;
  border-radius: 50%;
  margin-top: -5px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

#timelineBar input[type="range"]::-moz-range-track {
  width: 100%;
  height: 12px;
  background: linear-gradient(to bottom, #ddd, #ccc);
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.2);
}

#timelineBar input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #fff;
  border: 2px solid #666;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

