:root {
  --bg: #e6e6e6;
  --panel: #f2f2f2;
  --ink: #111111;
  --accent: #ff3c00; /* International Orange */
  --grid: rgba(0, 0, 0, 0.08);
  --border: 1px solid var(--ink);
  --font-mono: "Courier New", Courier, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Background Technical Grid */
.bg-grid {
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: -1;
}

.interface {
  width: 95vw;
  height: 90vh;
  background: var(--panel);
  border: 2px solid var(--ink);
  display: flex;
  flex-direction: column;
  box-shadow: 10px 10px 0px rgba(0,0,0,0.1);
}

/* --- Header --- */
.header {
  border-bottom: 2px solid var(--ink);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -1px;
}

.meta {
  font-size: 10px;
  opacity: 0.6;
}

.status-ticker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: bold;
}

.indicator {
  width: 10px;
  height: 10px;
  background: var(--ink);
  border-radius: 50%;
  animation: blink 2s infinite;
}

@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0.2; } 100% { opacity: 1; } }

/* --- Workspace Layout --- */
.workspace {
  display: grid;
  grid-template-columns: 1fr 300px;
  flex: 1;
  overflow: hidden;
}

/* --- The Viewport (Canvas Area) --- */
.viewport {
  position: relative;
  background: #dcdcdc;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
}

/* The Layers stack on top of each other */
.layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

/* Layer 0: Background display */
.bg-layer {
  width: 100%;
  height: 100%;
  z-index: 0;
}

.checker {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Layer 1: Result (Hidden initially, revealed by scrubbing transparency of layer 2) */
.result-layer {
  z-index: 1;
}

/* Layer 2: The Canvas that holds the Original Image */
.canvas-layer {
  z-index: 2;
}

/* Layer 3: Soap */
.soap {
  position: absolute;
  font-size: 48px;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
}

/* Upload Prompt UI */
.upload-prompt {
  position: absolute;
  z-index: 5;
  text-align: center;
  border: 1px dashed var(--ink);
  padding: 40px;
  pointer-events: none;
  background: rgba(255,255,255,0.5);
}

.sub-prompt { font-size: 12px; opacity: 0.6; }

/* Crosshairs */
.crosshair {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid var(--ink);
}
.tl { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.tr { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.bl { bottom: -1px; left: -1px; border-right: 0; border-top: 0; }
.br { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

#fileInput { display: none; }

/* --- Controls Sidebar --- */
.controls {
  border-left: 2px solid var(--ink);
  background: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.panel-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px dotted #999;
  padding-bottom: 24px;
}
.panel-group.grow { flex: 1; border-bottom: 0; }

.panel-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.label { font-size: 12px; font-weight: bold; }

/* Inputs */
select, button {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 12px;
}

.select-wrapper {
  border: 1px solid var(--ink);
  padding: 0;
  background: #fff;
  flex: 1;
}

select {
  border: none;
  width: 100%;
  padding: 8px;
  background: transparent;
  outline: none;
}

.color-wrapper {
  width: 40px;
  height: 40px;
  border: 1px solid var(--ink);
  padding: 2px;
}

input[type="color"] {
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Checkbox */
.check-box {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.check-box input { display: none; }
.checkmark {
  width: 16px;
  height: 16px;
  border: 1px solid var(--ink);
  display: grid;
  place-items: center;
}
.check-box input:checked + .checkmark::after {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--ink);
}

/* Buttons */
.btn {
  border: 1px solid var(--ink);
  padding: 14px;
  background: transparent;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 2px 2px 0px var(--ink);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.action-btn:not(:disabled):hover {
  background: var(--ink);
  color: #fff;
}

.secondary-btn:not(:disabled):hover {
  background: #eee;
}

/* Progress */
.progress-container {
  display: grid;
  gap: 6px;
}
.progress-label { font-size: 10px; }
.progress-track {
  height: 8px;
  border: 1px solid var(--ink);
  padding: 1px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { height: 40vh; border-left: 0; border-top: 2px solid var(--ink); }
}
