:root {
  --chrome-bg: #111;
  --chrome-fg: #eee;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  position: fixed;
  background-color: var(--chrome-bg);
  font-family: "jersey", Roboto, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.app-container {
  display: grid;
  grid-template-rows: 10% 70% 20%;
  width: max(100vw, 100vh);
  height: max(100vw, 100vh);
  position: absolute;
  top: 0;
  left: 0;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* This rule now applies to BOTH canvases */
#displayCanvas,
#transitionCanvas {
  position: absolute;
  top: 0;
  left: 0;
  /*width: 100%;
  height: 100%;*/
}

/* Add this new rule for the transition layer */
#transitionCanvas {
  opacity: 0;
  pointer-events: none; /* Ensures it can't be clicked */
  transition: opacity 0.3s ease-in-out;
}

#videoFeed {
  display: none; /* We only need it as a data source */
}

.button-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
}

#reverseCameraBtn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

#resToggleBtn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: -1.5em;
  margin-top: 1em;
}

#ditherBtn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

#ditherBtn.active {
  background-color: #444;
  border-color: #fff;
}

#ditherBtn span {
  transform: scale(0.5);
}

#loadBtn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: -1.5em;
  margin-top: 2.5em;
}

#loadBtn span {
  transform: scale(0.5);
}

#getPaletteBtn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: -1.5em;
  margin-top: 2.5em;
}

#getPaletteBtn span {
  transform: scale(0.5);
}

/* Add this style for the button's "active" (low-res) state */
#resToggleBtn.active {
  background-color: #444;
  border-color: #fff;
}

.res-icon {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5px;
  width: 9px;
  height: 9px;
  transition: all 0.2s ease;
}

/* These are the individual "pixels" of the grid icon */
.res-icon span {
  background-color: #fff;
  transition: background-color 0.2s ease;
}

/* --- The Magic Toggle --- */
/* When the button is active (low-res mode)... */
#resToggleBtn.active .res-icon {
  gap: 0; /* Remove the gap */
  background-color: #fff; /* The container itself becomes the solid square */
}

#resToggleBtn.active .res-icon span {
  background-color: transparent; /* ...and the individual pixels disappear */
}

#shutterBtn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: #e23d28;
  border: 4px solid #fff;
  box-shadow:
    0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  cursor: pointer;
  appearance: none;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

#shutterBtn:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

/* Palette */

#topContainer {
  position: relative;
  left: 50%;
  transform: translate(-50%);
  top: 1vh;
  width: auto;
  display: flex;
}

#palette {
  position: absolute;
  height: calc(0.1 * max(100vh, 100vw));
  width: 100vw;
  z-index: 1000;
}

body.landscape #palette {
  top: 0 !important;
  transform-origin: center center;
  transform: rotate(-90deg);
  top: 20cqw;
  left: calc(-50% + 0.1 * max(100vh, 100vw));
}

#palettePreview {
  display: inline-grid;
  grid-template-columns: repeat(8, 1fr);
  row-gap: 4px;
  width: min(30vh, 30vh);
  position: relative;
  left: 50%;
  transform: translate(-50%);
}

body.landscape #palettePreview {
  width: 50vh;
  left: 30%;
}

#paletteName {
  grid-column: 1 / -1;
  font-family: "Inter", sans-serif;
  font-size: 10px;
  color: var(--chrome-fg);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.swatch {
  width: calc(5 * min(1vh, 1vw));
  height: calc(5 * min(1vh, 1vw));
  border-radius: calc(1 * min(1vh, 1vw));
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* HTML controls: footer */

#controls {
  position: absolute;
  bottom: calc(0.1 * min(100vh, 100vw));
  height: calc(0.1 * max(100vh, 100vw));
  width: 100%;
}

body.landscape #controls {
  position: absolute;
  bottom: 0;
  height: calc(0.1 * max(100vh, 100vw));
  width: 100vh;
  transform: rotate(-90deg);
  transform-origin: left top;
  left: 100%;
}

#buttonContainer {
  position: relative;
  left: 50%;
  transform: translate(-50%);
  top: 1vh;
  width: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
}

body.landscape #buttonContainer {
  transform: translate(-25%, calc(-0.13 * max(100vh, 100vw)));
  left: 0;
}

#shutterBtn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: #e23d28;
  border: 4px solid #fff;
  box-shadow:
    0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  cursor: pointer;
  appearance: none;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

#shutterBtn:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

#shutterBtn.active {
  background-color: #792116;
  border: 4px solid #395d0e;
  box-shadow:
    0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 -8px 0 rgba(0, 0, 0, 0.2);
}

#resToggleBtn.active {
  background-color: #444;
  border-color: #fff;
}

.res-icon span {
  background-color: #fff;
  transition: background-color 0.2s ease;
}

/* --- The Magic Toggle --- */
/* When the button is active (low-res mode)... */
#resToggleBtn.active .res-icon {
  gap: 0; /* Remove the gap */
  background-color: #fff; /* The container itself becomes the solid square */
}

#resToggleBtn.active .res-icon span {
  background-color: transparent; /* ...and the individual pixels disappear */
}

#reverseCameraBtn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #2c2c2e;
  color: #fff;
  font-weight: bold;
  border: 4px solid #555;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  font-size: 24px;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  content: "⇄";
}

/* Settings Button */
#settingsBtn {
  position: relative;
  left: 10%;
  background: none;
  border: none;
  color: var(--chrome-fg);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  z-index: 1001;
}

#settingsBtn .iconoir-settings {
  font-size: 24px; /* Ensure icon size matches button */
}

/* Modal Styles */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1001; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  font-size: 1.2rem;
  overflow: auto; /* Enable scroll if needed */
  background-color: rgba(0, 0, 0, 0.7); /* Black w/ opacity */
  backdrop-filter: blur(5px); /* Optional: for a frosted glass effect */
}

#modal-content {
  background-color: #002b36; /* Solarized dark base */
  margin: 15% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: 80%; /* Could be more or less, depending on screen size */
  max-width: 500px; /* Max width for larger screens */
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  color: var(--chrome-fg);
  position: relative;
}

#modal-content a {
  color: #990;
  text-decoration: none;
}

#modal-content code {
  color: #900;
}

#modal-content h1,
#modal-content h2,
#modal-content h3,
#modal-content h4 {
  margin-inline-start: 0;
  margin-inline-end: 0;
  margin-block-start: 0;
  margin-block-end: 0.3rem;
}

#modal-content p {
  margin-inline-start: 0;
  margin-inline-end: 0;
  margin-block-start: 0;
  margin-block-end: 0.3rem;
}

.close-button {
  color: var(--chrome-fg);
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close-button:hover,
.close-button:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

#palette-modal-content {
  padding-right: 1em;
  padding-left: 1em;
}

#palette-grid {
  padding-top: 2em;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(25vw, 25vh), 1fr));
  gap: 15px;
  max-height: 90vh;
  overflow-y: auto;
}

#palette-grid::-webkit-scrollbar {
  display: none; /* For Chrome, Safari, and Opera */
}

#palette-grid {
  -ms-overflow-style: none; /* For Internet Explorer and Edge */
  scrollbar-width: none; /* For Firefox */
}

.palette-grid-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  cursor: pointer;
  border: 2px solid #555;
  border-radius: 5px;
  transition:
    transform 0.2s ease,
    border-color 0.2s ease;
  height: fit-content;
  align-items: center;
}

.delete-palette-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: none;
  border: none;
  color: #ff6b6b;
  font-size: 16px;
  cursor: pointer;
  padding: 2px;
  display: block; /* Always visible */
}

.palette-name {
  font-family: "Inter", sans-serif;
  font-size: 10px;
  color: var(--chrome-fg);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-transform: uppercase;
}

.mini-swatch-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
}

.palette-grid-item:hover {
  border-color: #fff;
  transform: scale(1.01);
}

.mini-swatch {
  width: 100%;
  padding-bottom: 100%; /* Creates a square aspect ratio */
  border-radius: 3px;
}

/* --- Palette Extractor Modal --- */
#palette-extractor-modal-content {
  background-color: #1a1a1a;
  color: #f0f0f0;
  font-family: "Inter", sans-serif;
  font-size: 1rem;
  margin: 1em 0.5em;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: 0.2em;
  padding: 0.3em;
}

#extractor-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.extractor-title {
  text-align: center;
  font-size: 1.5rem;
  font-family: "jersey", sans-serif;
  margin-bottom: 0.5rem;
}

.extractor-controls {
  background-color: #2c2c2e;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.extractor-controls label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.extractor-controls input[type="range"] {
  width: 100%;
}

#color-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 8px;
  padding: 8px;
  background-color: #2c2c2e;
  border-radius: 8px;
}

.color-swatch {
  width: 90%;
  padding-bottom: 100%;
  border-radius: 6px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.2s ease-in-out;
  position: relative;
}

.color-swatch:not(.selected) {
  transform: scale(0.95);
}
.color-swatch:not(.selected)::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 142%; /* Roughly 100% * sqrt(2) to cover the diagonal */
  height: 2px;
  backdrop-filter: invert(1);
  /* Center the line and rotate it into position */
  transform: translate(-50%, -50%) rotate(-45deg);
}
/*
.color-swatch:not(.selected)::after {
  content: " ";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.4);
  border-radius: 4px;
}
*/
.final-palette-container {
  background-color: #2c2c2e;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 50px;
}

#palette-image {
  background-color: #fff;
}

.name-input-container {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

#new-palette-name {
  width: 100%;
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid #555;
  background-color: #333;
  color: #fff;
  font-family: "Inter", sans-serif;
  box-sizing: border-box;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

.modal-buttons button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: "Inter", sans-serif;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

#cancel-palette-btn {
  background-color: #444;
  color: #fff;
}

#cancel-palette-btn:hover {
  background-color: #555;
}

#save-palette-btn {
  background-color: #3b82f6;
  color: #fff;
}

#save-palette-btn:hover {
  background-color: #4a90e2;
}

#save-palette-btn:disabled {
  background-color: #555;
  cursor: not-allowed;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes blink {
  0%,
  100% {
    border-color: #555;
  }
  50% {
    border-color: #e23d28;
  }
}

#reverseCameraBtn.blink {
  animation: blink 1s ease-in-out infinite;
}

.hidden {
  display: none;
}

/* --- Confirmation Modal --- */
#confirm-modal-content {
  background-color: #1a1a1a;
  color: #f0f0f0;
  font-family: "Inter", sans-serif;
  text-align: center;
  padding: 2rem;
  margin: 30% auto;
}

#confirm-modal-content h3 {
  margin-top: 0;
}

#confirm-modal-confirm-btn {
  background-color: #e23d28;
  color: #fff;
}
