/* CSS Architecture Refactoring - Phase 1: Foundation */

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Spacing */

  /* !IMPORTANT! MUST BE IN PIXELS */
  --overlay-padding: 32px;
  --button-gap: 16px;
  --button-margin: 16px;

  /* Sizing */
  --icon-size: 32px;

  /* Z-Index Layers */
  --painting-ui-z-index: 10002;
  --overlay-z-index: 10001;
  --tooltip-z-index: 1000;
  --debug-z-index: 1000;
  --performance-monitor-z-index: 100;
  --painting-backdrop-z-index: 1000;
  --painting-overlay-lowres-z-index: 9999;
  --painting-overlay-hires-z-index: 10000;
  --painting-overlay-left: 0;
  --painting-overlay-top: 0;
  --painting-overlay-width: 0;
  --painting-overlay-height: 0;

  --backdrop-opacity-darkest: 0.87;

  /* Colors (can be overridden dynamically) */
  --icon-color: white;
  --icon-glow-color: #ffffff38;
}

/* ===== PAINTING CONTROLS CONTAINER ===== */
.painting-controls {
  position: absolute;
  top: 0;
  right: 0;
  padding: var(--overlay-padding);
  gap: var(--button-gap);
  z-index: var(--painting-ui-z-index);
  display: none; /* Hidden by default */
  pointer-events: none; /* Container doesn't block clicks */
  background: transparent;
  border-radius: 4px;
}

.painting-controls.vertical-buttons {
  flex-direction: column;
}

.painting-controls.horizontal-buttons {
  flex-direction: row-reverse;
}

.painting-controls.painting-view {
  display: flex;
}

/* Debug border for development */
.painting-controls.debug {
  border: 2px solid red;
}

/* Button styling within container */
.painting-controls button {
  pointer-events: auto; /* Buttons can be clicked */
  cursor: pointer;
  border: none;
}

/* ===== INFO OVERLAY ===== */
.info-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  display: none;
  z-index: var(--overlay-z-index);
  overflow: auto;
  padding: var(--overlay-padding);
  box-sizing: border-box;
}

.info-overlay .gitd-prompt {
  display: block;
  margin-top: 1em;
}

.info-overlay h2 {
  display: inline-block;
  margin-bottom: 0;
  margin: 0 var(--overlay-padding) 1rem 0;
}

.info-overlay ul.metadata {
  list-style: none;
  padding: 0;
  margin: 0 var(--overlay-padding) 1rem 0;
  font-weight: 700;
  display: inline-block;
}

.info-overlay ul.metadata li {
  display: inline-block;
  margin: 0 1em 0.5rem 0;
}

.info-overlay.showing {
  display: block;
}

.info-overlay > div:first-of-type {
  line-height: 1.4;
}

/* Close button positioning within overlay - matches info button position exactly */
.info-overlay .close-btn {
  position: fixed;
  top: var(--overlay-padding);
  right: var(--overlay-padding);
  border: none;
  cursor: pointer;
}

/* ===== LAYOUT STATE CLASSES ===== */
.gallery-view .painting-controls {
  display: none;
}

/* ===== SORT/FILTER CONTAINER ===== */
.sort-filter-container {
  position: fixed;
  color: white;
  font-size: 12px;
  padding: 8px;
  gap: 6px;
  z-index: var(--painting-ui-z-index);
  border-radius: 4px;
  display: none; /* Hidden by default */
  pointer-events: none;
}

.sort-filter-container.gallery-view {
  display: flex;
}

.sort-filter-container.vertical {
  flex-direction: column;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  max-height: 80vh;
  overflow-y: auto;
}

.sort-filter-container.horizontal {
  flex-direction: row;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 95vw;
  width: 100%;
  overflow-x: auto;
}

.tag-group {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}

.sort-filter-container.vertical .tag-group {
  flex-direction: column;
}

.sort-filter-container.horizontal .tag-group {
  flex-direction: row;
  flex-wrap: wrap;
}

.tag-btn {
  background: transparent;
  color: #ffffffc9;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 19px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition:
    backdrop-filter 0.2s,
    background-color 0.2s,
    border-color 0.2s;
  white-space: nowrap;
  position: relative;
  pointer-events: auto;
  --text-stroke-thickness: 2px;
  --text-stroke-color: #000;
  text-shadow:
    calc(-1 * var(--text-stroke-thickness))
      calc(-1 * var(--text-stroke-thickness)) 0 var(--text-stroke-color),
    var(--text-stroke-thickness) calc(-1 * var(--text-stroke-thickness)) 0
      var(--text-stroke-color),
    calc(-1 * var(--text-stroke-thickness)) var(--text-stroke-thickness) 0
      var(--text-stroke-color),
    var(--text-stroke-thickness) var(--text-stroke-thickness) 0
      var(--text-stroke-color),
    0px calc(-1 * var(--text-stroke-thickness)) 0 var(--text-stroke-color),
    var(--text-stroke-thickness) 0px 0 var(--text-stroke-color),
    0px var(--text-stroke-thickness) 0 var(--text-stroke-color),
    calc(-1 * var(--text-stroke-thickness)) 0px 0 var(--text-stroke-color);
  color: #fff;
}

@supports (-webkit-text-stroke: 1px black) or (text-stroke: 1px black) {
  .tag-btn {
    -webkit-text-stroke: var(--text-stroke-thickness) var(--text-stroke-color);
    text-stroke: var(--text-stroke-thickness) var(--text-stroke-color);
    paint-order: stroke fill;
    text-shadow: none;
  }
}

.tag-btn,
.tag-btn.active {
  backdrop-filter: brightness(100%) blur(6px);
}

.tag-btn:hover {
  color: white;
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.tag-btn.active {
  color: white;
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.7);
}

.tag-btn.selected {
  color: white;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.tag-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.tag-close {
  position: absolute;
  font-weight: bold;
  font-size: 30px;
  font-style: normal;
  cursor: pointer;
  right: -4px;
  top: -19px;
}

.tag-btn:disabled:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ===== TOOLTIP STYLES ===== */
.tooltip {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  border-radius: 4px;
  font-size: 14px;
  z-index: var(--tooltip-z-index);
  pointer-events: none;
  opacity: 0;
  white-space: pre-line;
  max-width: 300px;
  line-height: 1.5;
  padding: 1em 1em 1.5em 1em;
}

.tooltip strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.tooltip p {
  display: block;
  margin: 0.5em 0 0 0;
  font-weight: 500;
}

.tooltip.showing {
  opacity: 1;
}

/* ===== PAINTING OVERLAY STYLES ===== */
.painting-overlay-lowres {
  position: absolute;
  pointer-events: none;
  object-fit: fill;
  z-index: var(--painting-overlay-lowres-z-index);
  display: block;
  top: var(--painting-overlay-top);
  left: var(--painting-overlay-left);
  width: var(--painting-overlay-width);
  height: var(--painting-overlay-height);
}

.painting-overlay-hires {
  position: absolute;
  pointer-events: none;
  object-fit: fill;
  z-index: var(--painting-overlay-hires-z-index);
  opacity: 0;
  transition: opacity 500ms;
  image-rendering: high-quality;
  -webkit-image-smoothing: high;
  image-smoothing: high;
  top: var(--painting-overlay-top);
  left: var(--painting-overlay-left);
  width: var(--painting-overlay-width);
  height: var(--painting-overlay-height);
}

.painting-overlay-hires.loaded {
  opacity: 1;
}

.painting-overlay-gitd {
  position: absolute;
  pointer-events: none;
  object-fit: fill;
  display: block;
  transition: opacity 500ms;
  opacity: 0;
  z-index: var(--painting-overlay-lowres-z-index); /* Same as low-res */
  top: var(--painting-overlay-top);
  left: var(--painting-overlay-left);
  width: var(--painting-overlay-width);
  height: var(--painting-overlay-height);
}

.painting-overlay-gitd.active {
  opacity: 1;
}

/* ===== PERFORMANCE MONITOR STYLES ===== */
.performance-monitor {
  position: absolute;
  top: 60px;
  left: 10px;
  color: white;
  font-family: monospace;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 10px;
  z-index: var(--performance-monitor-z-index);
  user-select: text;
  max-width: 300px;
  line-height: 1.4;
}

.performance-monitor button {
  margin-top: 10px;
  padding: 5px;
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
/*@media (max-width: 768px) {
  :root {
    --overlay-padding: 20px;
    --icon-size: 1.8em;
  }
}

@media (max-width: 480px) {
  :root {
    --overlay-padding: 15px;
    --icon-size: 1.5em;
    --button-gap: 8px;
  }
}*/

.icon-button {
  background-color: #ffffffcf;
  display: block;
  width: var(--icon-size);
  height: var(--icon-size);
  opacity: var(--icon-opacity);
  position: relative;
  box-shadow:
    0 0 4px 1px var(--icon-glow-color),
    0 0 11px 7px var(--icon-glow-color);
  border-radius: 50%;
}

.icon-button:hover {
  background-color: white;
}

.icon-button::after {
  content: "";
  background: var(--icon-color, white);
  display: block;
  width: var(--icon-size);
  height: var(--icon-size);
  position: absolute;
  top: 0;
  left: 0;

  mask-size: var(--icon-size);
  -mask-size: var(--icon-size);
  -webkit-mask-size: var(--icon-size);

  -mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;

  mask-image: var(--mask-image-url);
  -mask-image: var(--mask-image-url);
  -webkit-mask-image: var(--mask-image-url);
}

/* ===== ICON STYLES ===== */
.info-btn {
  --mask-image-url: url('data:image/svg+xml,<svg version="1.1" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"><path d="m128 256a128 128 0 1 0 0-256 128 128 0 1 0 0 256zm-20-88h12v-32h-12c-6.65 0-12-5.35-12-12s5.35-12 12-12h24c6.65 0 12 5.35 12 12v44h4c6.65 0 12 5.35 12 12s-5.35 12-12 12h-40c-6.65 0-12-5.35-12-12s5.35-12 12-12zm20-104a16 16 0 1 1 0 32 16 16 0 1 1 0-32z" stroke-width=".5"/></svg>');
}

.close-btn {
  --mask-image-url: url('data:image/svg+xml,<svg width="256" height="256" version="1.1" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"><path d="m128 0a128 128 0 0 0-128 128 128 128 0 0 0 128 128 128 128 0 0 0 128-128 128 128 0 0 0-128-128zm-31.955 84.025c3.0688 0 6.1281 1.1754 8.4531 3.5254l23.5 23.5 23.5-23.5c4.7-4.7 12.303-4.7 16.953 0s4.7 12.299 0 16.949l-23.5 23.5 23.5 23.5c4.7 4.7 4.7 12.299 0 16.949s-12.303 4.7-16.953 0l-23.5-23.5-23.5 23.5c-4.7 4.7-12.299 4.7-16.949 0-4.65-4.7-4.7-12.299 0-16.949l23.5-23.5-23.5-23.5c-4.7-4.7-4.7-12.299 0-16.949 2.35-2.35 5.4273-3.5254 8.4961-3.5254z" stroke-width=".62845"/></svg>');
}

.lights-icon {
  --mask-image-url: url('data:image/svg+xml,<svg width="256" height="256" fill="%23e3e3e3" version="1.1" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"><path d="m128 1.25e-6a128 128 0 0 0-128 128 128 128 0 0 0 128 128 128 128 0 0 0 128-128 128 128 0 0 0-128-128zm-27.055 42.318h54.111v45.096c5.5616 4.359 9.961 9.6525 13.193 15.891 3.2319 6.2381 4.8457 12.971 4.8457 20.186 0 12.476-4.3999 23.107-13.193 31.9-8.7934 8.7934-19.426 13.193-31.902 13.193-12.476 0-23.107-4.3999-31.9-13.193-8.7934-8.7934-13.193-19.424-13.193-31.9-1e-6 -7.2152 1.6119-13.948 4.8438-20.186 3.2319-6.2381 7.6335-11.531 13.195-15.891zm18.037 18.039v18.936c1.5032-0.30062 3.0064-0.51765 4.5098-0.66797 1.5032-0.1503 3.0064-0.23047 4.5098-0.23047s3.0045 0.08018 4.5078 0.23047c1.5032 0.15033 3.0064 0.36735 4.5098 0.66797v-18.936zm9.0176 36.076c-7.5158 0-13.902 2.6295-19.162 7.8906-5.2605 5.2611-7.8926 11.651-7.8926 19.166s2.6315 13.904 7.8926 19.164 11.647 7.8926 19.162 7.8926 13.905-2.6315 19.166-7.8926c5.2605-5.2611 7.8926-11.649 7.8926-19.164s-2.6315-13.905-7.8926-19.166c-5.2611-5.2605-11.651-7.8906-19.166-7.8906zm-90.188 18.039h27.057v18.037h-27.057zm153.32 0h27.055v18.037h-27.055zm-110.94 48.705 12.629 12.629-18.938 18.938-12.627-12.631zm95.615 0 18.936 18.936-12.629 12.631-18.936-18.938zm-56.824 23.445h18.037v27.059h-18.037z" stroke-width=".81995"/></svg>');
}

/* ===== UTILITY CLASSES ===== */
.hidden {
  display: none;
}

#loadingOverlay.loading-complete #loadingBar,
#loadingOverlay.loading-complete #loadingBarProgress,
#loadingOverlay.loading-complete #loadingText {
  visibility: hidden;
}

.showing {
  display: block !important;
}

.flex-showing {
  display: flex !important;
}

/* Transition utilities */
.fade-in {
  opacity: 0;
  transition: opacity 300ms ease;
}

.fade-in.active {
  opacity: 1;
}

.fade-out {
  opacity: 1;
  transition: opacity 300ms ease;
}

.fade-out.active {
  opacity: 0;
}

/* ===== PAINTING VIEW BACKDROP ===== */
.painting-view-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--painting-backdrop-z-index);
  opacity: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.85) 70%,
    rgba(0, 0, 0, 1) 95%
  );
}

.lil-gui.autoPlace {
  left: 15px;
}

.painting-controls .info-btn,
.painting-controls .close-btn {
  display: none;
}
.painting-controls.show-info .info-btn {
  display: block;
}
.painting-controls.show-close .close-btn {
  display: block;
}
