:root {
  color-scheme: dark;
  --bg: #111316;
  --surface: #191d22;
  --surface-2: #20262c;
  --line: #343b44;
  --text: #edf0f2;
  --muted: #a7b0b9;
  --accent: #3fb579;
  --accent-2: #f3c74f;
  --danger: #e35d6a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.5vw, 2.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.file-button,
.view-button,
.favorite-button,
.pill-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  min-height: 38px;
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.file-button {
  display: inline-grid;
  place-items: center;
  padding: 0 13px;
  font-weight: 650;
  user-select: none;
}

.file-button.secondary {
  color: var(--muted);
}

.file-button.danger {
  color: #ffd5d9;
  border-color: rgba(227, 93, 106, 0.42);
  background: rgba(227, 93, 106, 0.12);
}

.file-button.danger:hover {
  border-color: var(--danger);
}

.file-button.is-hidden {
  display: none;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button:hover,
.view-button:hover,
.favorite-button:hover,
.pill-button:hover {
  border-color: var(--accent);
}

.view-toggle {
  display: grid;
  grid-auto-flow: column;
  gap: 6px;
  align-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.view-toggle::before {
  content: "Grid";
  align-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.view-toggle legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.view-button {
  display: grid;
  grid-template-columns: 28px auto;
  align-items: center;
  gap: 7px;
  width: 62px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.view-button-wide {
  width: 76px;
}

.layout-icon {
  display: grid;
  gap: 2px;
  width: 26px;
  height: 20px;
}

.layout-icon i {
  display: block;
  min-width: 0;
  min-height: 0;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.72;
}

.layout-icon-1 {
  grid-template-columns: 1fr;
}

.layout-icon-2 {
  grid-template-columns: repeat(2, 1fr);
}

.layout-icon-4 {
  grid-template-columns: repeat(2, 1fr);
}

.layout-icon-5 {
  grid-template-columns: 1.35fr 1fr 1fr;
  grid-template-rows: repeat(2, 1fr);
}

.layout-icon-5 i:first-child {
  grid-row: 1 / -1;
}

.layout-icon-6 {
  grid-template-columns: repeat(3, 1fr);
}

.layout-icon-8 {
  grid-template-columns: repeat(4, 1fr);
}

.view-count {
  font-size: 0.82rem;
  font-weight: 800;
}

.view-button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #07120d;
  font-weight: 800;
}

.favorites-band {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}

.band-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.favorites-rail {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding: 7px 0;
}

.pill-button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
}

.pill-button.is-empty {
  cursor: default;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 170px);
  text-align: center;
}

.empty-dropzone {
  display: grid;
  gap: 8px;
  justify-items: center;
  width: min(560px, 100%);
  min-height: 180px;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(32, 38, 44, 0.56);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.empty-dropzone:hover,
.empty-dropzone:focus-visible {
  border-color: var(--accent);
  background: rgba(63, 181, 121, 0.1);
  color: var(--text);
  outline: none;
}

body.is-dragging-file .empty-dropzone {
  border-color: var(--accent);
  background: rgba(63, 181, 121, 0.16);
  color: var(--text);
  transform: translateY(-2px);
}

.empty-dropzone strong {
  display: block;
  color: var(--text);
  font-size: 1.2rem;
}

.empty-state.is-hidden {
  display: none;
}

.pane-grid.is-hidden {
  display: none;
}

.pane-grid {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  min-height: calc(100vh - 136px);
}

.pane-grid-1 {
  grid-template-columns: minmax(0, 1fr);
}

.pane-grid-2,
.pane-grid-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pane-grid-5 {
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 0.75fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.pane-grid-5 .pane:first-child {
  grid-row: 1 / -1;
}

.pane-grid-6,
.pane-grid-8 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.pane {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: visible;
}

.pane-toolbar {
  position: relative;
  z-index: 12;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: #15191d;
}

.lut-picker {
  position: relative;
  min-width: 0;
}

.lut-picker-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}

.lut-picker-button::after {
  content: "";
  width: 0;
  height: 0;
  margin-left: 10px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.72;
}

.lut-picker-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lut-menu,
.lut-submenu {
  position: absolute;
  z-index: 30;
  display: none;
  min-width: 255px;
  overflow: visible;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 29, 34, 0.96);
  box-shadow: var(--shadow);
}

.lut-menu {
  top: calc(100% + 6px);
  left: 0;
}

.lut-picker[data-menu-mode="inline"] > .lut-menu {
  width: min(460px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 135px));
  overflow-y: auto;
}

.lut-picker[data-menu-mode="inline"] .lut-inline-body {
  display: block;
}

.lut-picker[data-menu-mode="inline"] .lut-submenu {
  display: none;
}

.lut-picker.opens-left > .lut-menu {
  right: 0;
  left: auto;
}

.lut-submenu {
  top: -8px;
  left: calc(100% - 1px);
}

.lut-submenu.is-leaf-list {
  max-height: min(520px, calc(100vh - 120px));
  overflow-y: auto;
}

.lut-picker.is-open > .lut-menu,
.lut-menu-branch.is-active > .lut-submenu,
.lut-menu-branch:hover > .lut-submenu,
.lut-menu-branch:focus-within > .lut-submenu {
  display: block;
}

.lut-menu-branch {
  position: relative;
}

.lut-menu-item,
.lut-menu-branch-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
  cursor: pointer;
}

.lut-menu-item:hover,
.lut-menu-item:focus-visible,
.lut-menu-branch.is-active > .lut-menu-branch-button,
.lut-menu-branch:hover > .lut-menu-branch-button,
.lut-menu-branch-button:focus-visible {
  background: #2f72dd;
  color: #fff;
  outline: none;
}

.lut-menu-item.is-selected {
  color: var(--accent-2);
}

.lut-menu-item.is-selected:hover,
.lut-menu-item.is-selected:focus-visible {
  color: #fff;
}

.lut-inline-branch {
  display: block;
}

.lut-inline-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  padding: 0 10px 0 calc(10px + (var(--menu-depth) * 16px));
}

.lut-inline-summary::-webkit-details-marker {
  display: none;
}

.lut-inline-summary::before {
  content: "";
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  opacity: 0.72;
  transition: transform 120ms ease;
}

.lut-inline-branch[open] > .lut-inline-summary::before {
  transform: rotate(90deg);
}

.lut-inline-summary:hover,
.lut-inline-summary:focus-visible {
  background: #2f72dd;
  color: #fff;
  outline: none;
}

.lut-inline-item {
  padding-left: calc(25px + (var(--menu-depth) * 16px));
}

.lut-menu-branch-button::after {
  content: "";
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  opacity: 0.7;
}

.lut-picker.is-disabled .lut-picker-button {
  color: var(--muted);
  cursor: default;
}

.lut-picker.is-disabled .lut-picker-button::after,
.lut-picker.is-disabled .lut-menu {
  display: none;
}

/* Left-most panes need menus to open inward so submenus stay in view less often. */
.pane:nth-child(4n) .lut-submenu,
.pane:nth-child(4n - 1) .lut-submenu {
  right: calc(100% - 1px);
  left: auto;
}

.lut-menu-branch.is-open-right > .lut-submenu {
  right: auto;
  left: calc(100% - 1px);
}

.lut-menu-branch.is-open-left > .lut-submenu {
  right: calc(100% - 1px);
  left: auto;
}

.lut-select {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
}

.lut-select:disabled {
  color: var(--muted);
  opacity: 1;
  cursor: default;
}

.favorite-button {
  width: 40px;
  padding: 0;
  font-size: 1.15rem;
}

.favorite-button.is-active {
  color: #211600;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.pane.is-reference .favorite-button {
  color: var(--muted);
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 220px;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #12161a 25%, transparent 25%),
    linear-gradient(-45deg, #12161a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #12161a 75%),
    linear-gradient(-45deg, transparent 75%, #12161a 75%);
  background-color: #0d0f12;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.canvas-placeholder {
  position: absolute;
  color: var(--muted);
  font-weight: 700;
}

.has-image .canvas-placeholder {
  display: none;
}

.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 20;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(17, 19, 22, 0.88);
  color: var(--text);
  text-align: center;
  pointer-events: none;
}

.drop-overlay strong,
.drop-overlay span {
  display: block;
}

.drop-overlay strong {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.drop-overlay span {
  color: var(--muted);
}

body.has-photo.is-dragging-file .drop-overlay {
  display: grid;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    justify-content: flex-start;
  }

  .pane-grid-6,
  .pane-grid-5,
  .pane-grid-8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pane-grid-5 .pane:first-child {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .controls {
    width: 100%;
  }

  .file-button {
    flex: 1 1 145px;
  }

  .view-toggle {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-flow: row;
  }

  .view-toggle::before {
    grid-column: 1 / -1;
  }

  .view-button {
    width: 100%;
  }

  .pane-grid,
  .pane-grid-2,
  .pane-grid-4,
  .pane-grid-5,
  .pane-grid-6,
  .pane-grid-8 {
    grid-template-columns: minmax(0, 1fr);
  }

  .pane-grid-5 {
    grid-template-rows: auto;
  }

  .pane-grid-5 .pane:first-child {
    grid-column: auto;
  }

  .pane {
    min-height: 320px;
  }
}
