:root {
  --ink: #1c1a16;
  --muted: #5b5750;
  --bg-1: #f3efe6;
  --bg-2: #d9d2c2;
  --panel: rgba(255, 255, 255, 0.74);
  --accent: #1d6e69;
  --accent-2: #c05a2a;
  --edge: rgba(30, 28, 24, 0.15);
  --shadow: 0 30px 80px rgba(26, 24, 20, 0.15);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: linear-gradient(140deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(600px 350px at 15% 20%, rgba(29, 110, 105, 0.18), transparent 60%),
    radial-gradient(700px 400px at 85% 10%, rgba(192, 90, 42, 0.18), transparent 65%),
    radial-gradient(600px 380px at 80% 70%, rgba(31, 64, 88, 0.16), transparent 60%);
  opacity: 0.9;
  z-index: -1;
  animation: drift 16s ease-in-out infinite;
}

@keyframes drift {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-12px); }
  100% { transform: translateY(0px); }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 36px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mark {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #103b38);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 1px;
  box-shadow: var(--shadow);
}

.title {
  font-family: "Palatino", "Book Antiqua", serif;
  font-size: 24px;
  letter-spacing: 0.4px;
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
}

.status {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.6fr) minmax(520px, 1.4fr) minmax(170px, 0.35fr);
  gap: 28px;
  padding: 0 36px 36px;
  min-height: calc(100vh - 120px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  padding-right: 6px;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 160px);
}

.history-rail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  padding-right: 6px;
}

.frame {
  position: relative;
  background: #131312;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.frame img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  animation: fadeIn 0.8s ease;
}

.badge {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.history {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.grid-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.grid-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 12px;
}

.grid-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.grid {
  display: grid;
  gap: 12px;
  flex: 1;
  align-content: stretch;
  justify-content: stretch;
  --grid-cols: 4;
  --grid-rows: 3;
  --tile-size: 200px;
  grid-template-columns: repeat(var(--grid-cols), var(--tile-size));
  grid-template-rows: repeat(var(--grid-rows), calc(var(--tile-size) * 1.25));
  overflow: auto;
  padding-bottom: 6px;
}

.grid-cell {
  border: 0;
  padding: 0;
  background: #131312;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  min-height: calc(var(--tile-size) * 1.1);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.grid-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid-cell:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.18);
}

.grid-cell.picked::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(192, 90, 42, 0.8);
  border-radius: 10px;
  pointer-events: none;
}

.grid-cell.locked::after {
  border-color: rgba(192, 90, 42, 0.9);
}

.grid-cell.target::after {
  border-color: rgba(31, 64, 88, 0.9);
}

.grid-cell.target .lock-badge {
  display: inline-block;
  background: rgba(31, 64, 88, 0.85);
  color: #fff;
  content: "Target";
}

.grid-cell .lock-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  display: none;
}

.grid-cell .select-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  display: none;
}

.grid-cell.picked .select-badge {
  display: inline-block;
}

.grid-cell.locked .lock-badge {
  display: inline-block;
}

.grid.shear img {
  transform: perspective(700px) skew(var(--shear-x, 0deg), var(--shear-y, 0deg));
  transform-origin: center;
}

.history-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

.history-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.history-strip {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  position: relative;
}

.history-item img {
  width: 92px;
  height: 110px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-item:hover img {
  transform: translateY(-3px);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.12);
}

.history-item.picked img {
  border-color: rgba(192, 90, 42, 0.9);
  box-shadow: 0 0 0 2px rgba(192, 90, 42, 0.3);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-section {
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  padding: 0;
  overflow: visible;
  margin-bottom: 4px;
}

.panel-section summary {
  list-style: none;
  cursor: pointer;
  font-size: 15px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  line-height: 1.3;
  color: var(--ink);
}

.panel-section summary::-webkit-details-marker {
  display: none;
}

.panel-section summary::after {
  content: ">";
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.panel-section[open] summary::after {
  transform: rotate(90deg);
}

.panel-section[open] summary {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.panel-body {
  padding: 18px;
}

.panel-body.compact {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-body.compact .row {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.panel-body.compact .row.field {
  flex-direction: column;
  align-items: stretch;
}

.panel-body.compact .row.field label {
  flex: 0 0 auto;
  width: 100%;
  margin-bottom: 4px;
}

.span-2 {
  width: 100%;
}

.row button {
  width: 100%;
}

.row .btn {
  flex: 1;
  min-width: 0;
}

.feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}

.feature-btn {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.feature-btn.active {
  border-color: rgba(29, 110, 105, 0.6);
  color: var(--ink);
  background: rgba(29, 110, 105, 0.12);
}

.feature-hint,
.feature-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.row.field label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.field-inline select,
.field-inline input[type="number"] {
  min-width: 80px;
  flex: 1;
}

select,
input[type="number"],
input[type="text"] {
  width: 100%;
  max-width: 100%;
}

.mini-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.hidden {
  display: none;
}

input[type="number"],
input[type="text"],
select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  font-size: 14px;
}

input[type="checkbox"] {
  transform: scale(1.2);
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-width: 120px;
}

.row.field:has(input[type="range"]) {
  flex-direction: row;
  align-items: center;
}

.row.field:has(input[type="range"]) label {
  flex: 0 0 auto;
  margin-bottom: 0;
  margin-right: 8px;
}

.btn {
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn.small {
  padding: 6px 10px;
  font-size: 12px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
  transform: none;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #1b4f4b);
  color: #fff;
  border: none;
}

.btn.ghost {
  background: transparent;
}

.sliders {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 6px;
}

.slider-item {
  display: grid;
  grid-template-columns: 70px 1fr 50px;
  align-items: center;
  gap: 10px;
}

.slider-item label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.mono {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.note {
  background: rgba(29, 110, 105, 0.1);
}

.note-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.note-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: minmax(280px, 0.7fr) minmax(520px, 1.3fr);
  }
  .history-rail {
    grid-column: 2;
    max-height: none;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .stage {
    min-height: auto;
  }
  .history-rail {
    grid-column: auto;
  }
}

.zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 12, 12, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.zoom-overlay.active {
  display: flex;
}

.zoom-card {
  background: #111;
  border-radius: 20px;
  padding: 16px;
  width: 500px;
  max-width: min(90vw, 500px);
  max-height: min(860px, 90vh);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.zoom-card img {
  width: 100%;
  height: auto;
  border-radius: 16px;
}

.zoom-close {
  align-self: flex-end;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.context-menu {
  position: fixed;
  display: none;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.15);
  z-index: 60;
}

.context-menu.active {
  display: flex;
}

.context-menu button {
  border: none;
  background: transparent;
  padding: 6px 10px;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
}

.context-menu button:hover {
  background: rgba(29, 110, 105, 0.12);
}

.selection-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
  padding-right: 4px;
}

.selection-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.help-content {
  max-height: 450px;
  overflow-y: auto;
  padding-right: 6px;
}

.help-section {
  margin-bottom: 20px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h4 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin: 0 0 10px 0;
  font-weight: 600;
}

.help-section p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  margin: 0 0 8px 0;
}

.help-section ul,
.help-section ol {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0;
  padding-left: 20px;
}

.help-section li {
  margin-bottom: 6px;
}

.help-section li:last-child {
  margin-bottom: 0;
}

.help-section a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.help-section a:hover {
  color: var(--accent-2);
  text-decoration: underline;
}

/* Hair Dialog */
.hair-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.hair-dialog-overlay[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
}

.hair-dialog {
  background: white;
  border-radius: 20px;
  padding: 30px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.hair-dialog-overlay[aria-hidden="false"] .hair-dialog {
  transform: scale(1);
}

.hair-dialog h3 {
  margin: 0 0 8px 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.hair-dialog-note {
  margin: 0 0 20px 0;
  font-size: 14px;
  color: var(--muted);
}

.hair-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.preset-btn {
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(29, 110, 105, 0.05);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.preset-btn:hover {
  background: rgba(29, 110, 105, 0.12);
  border-color: var(--accent);
}

.preset-btn:active {
  transform: scale(0.98);
}

.hair-input-group {
  margin-bottom: 24px;
}

.hair-input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.hair-input-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  font-size: 14px;
  box-sizing: border-box;
}

.hair-input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 110, 105, 0.1);
}

.hair-dialog-actions {
  display: flex;
  gap: 10px;
}

.hair-dialog-actions .btn {
  flex: 1;
}
