*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* joshlu.info brand tokens */
:root {
  --bg-page:    #f2f2f2;
  --bg-panel:   #ffffff;
  --bg-card:    #ffffff;
  --bg-input:   #f5f5f5;

  --border:         rgba(0, 0, 0, 0.07);
  --border-hover:   rgba(0, 0, 0, 0.14);
  --border-active:  rgba(0, 0, 0, 0.22);
  --border-dashed:  rgba(0, 0, 0, 0.35);

  --text-primary: #000000;
  --text-body:    #666666;
  --text-label:   #aaaaaa;
  --text-faded:   #cccccc;
  --text-value:   #333333;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 12px;

  --font-sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: stretch;
  letter-spacing: -0.01em;
}

.app {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2rem 1.25rem;
  overflow: hidden;
}

/* Hero */
.hero {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: baseline;
  column-gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.hero h1 {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.hero-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-close {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-faded);
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.nav-close:hover {
  color: var(--text-label);
  background: rgba(0, 0, 0, 0.05);
}

.lede {
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-body);
  font-weight: 400;
  margin: 0;
}

.preview-col {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.canvas-card {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  border: 1px dashed var(--border-dashed);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#canvas {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 1;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-top: 0.75rem;
  font-size: 0.72rem;
  color: var(--text-label);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.meta-sep { color: var(--text-faded); }

.meta-pause.is-paused { color: var(--text-body); }

/* Controls panel — flush right, full viewport height */
.controls {
  width: 360px;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  align-self: flex-start;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 2.5rem 1.75rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.25rem 0;
}

.control-group:first-of-type {
  padding-top: 0;
}

.group-label {
  font-size: 0.68rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-label);
  margin-bottom: 0.15rem;
}

/* Selects — match slider field containers */
select {
  width: 100%;
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  padding: 0.72rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

select:hover {
  border-color: var(--border-hover);
  background: #efefef;
}

select:focus {
  outline: none;
  border-color: var(--border-active);
}

/* Sliders — unified pill containers (light reference) */
.slider-field {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.72rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.slider-field:hover {
  border-color: var(--border-hover);
  background: #efefef;
}

.slider-field:focus-within { border-color: var(--border-active); }

.slider-field.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.slider-field.is-disabled:hover {
  border-color: var(--border);
  background: var(--bg-input);
}

.slider-label {
  font-size: 0.84rem;
  color: var(--text-body);
  white-space: nowrap;
  flex-shrink: 0;
}

.slider-val {
  font-size: 0.84rem;
  color: var(--text-value);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 2.5rem;
  text-align: right;
}

.slider-field input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  --val: 50%;
}

.slider-field input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.18) 0%,
    rgba(0, 0, 0, 0.18) var(--val),
    rgba(0, 0, 0, 0.06) var(--val),
    rgba(0, 0, 0, 0.06) 100%
  );
}

.slider-field input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 2px;
  height: 16px;
  margin-top: -7px;
  border-radius: 1px;
  background: #888888;
  cursor: ew-resize;
  transition: background 0.15s;
}

.slider-field input[type="range"]:hover::-webkit-slider-thumb,
.slider-field input[type="range"]:focus::-webkit-slider-thumb {
  background: #000000;
}

.slider-field input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: rgba(0, 0, 0, 0.06);
}

.slider-field input[type="range"]::-moz-range-progress {
  height: 2px;
  border-radius: 1px;
  background: rgba(0, 0, 0, 0.18);
}

.slider-field input[type="range"]::-moz-range-thumb {
  width: 2px;
  height: 16px;
  border: none;
  border-radius: 1px;
  background: #888888;
  cursor: ew-resize;
}

.slider-field input[type="range"]:focus { outline: none; }

/* Toggle pills */
.toggle-row { margin-top: 0.15rem; }

.view-toggle-row {
  display: flex;
  gap: 0.5rem;
}

.view-toggle-row .toggle-pill {
  flex: 1;
  text-align: center;
}

.iso-controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.toggle-pill {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-body);
  background: transparent;
  border: 1px dashed var(--border-dashed);
  border-radius: var(--radius-lg);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.toggle-pill:hover {
  border-color: var(--border-active);
  color: var(--text-primary);
}

.toggle-pill.active {
  border-style: solid;
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: var(--bg-input);
}

/* Tile style buttons */
.tile-style-grid {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.tile-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-body);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  padding: 0;
}

.tile-icon {
  width: 16px;
  height: 16px;
  border: 1px solid currentColor;
  border-radius: 2px;
  display: block;
  flex-shrink: 0;
}

.tile-icon-solid {
  background: currentColor;
  opacity: 0.35;
}

.tile-icon-hst-slash {
  background: linear-gradient(to bottom right, rgba(0, 0, 0, 0.5) 50%, rgba(0, 0, 0, 0.14) 50%);
}

.tile-icon-hst-back {
  background: linear-gradient(to bottom left, rgba(0, 0, 0, 0.5) 50%, rgba(0, 0, 0, 0.14) 50%);
}

.tile-icon-hourglass {
  background:
    linear-gradient(to bottom right, transparent calc(50% - 0.5px), currentColor calc(50% - 0.5px), currentColor calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom left, transparent calc(50% - 0.5px), currentColor calc(50% - 0.5px), currentColor calc(50% + 0.5px), transparent calc(50% + 0.5px));
  opacity: 0.55;
}

.tile-icon-sq-in-sq {
  background: transparent;
  box-shadow: inset 0 0 0 4px currentColor;
  opacity: 0.35;
}

.tile-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.tile-btn.active {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: #efefef;
}

/* Color rows */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.72rem 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.color-row-label {
  font-size: 0.84rem;
  color: var(--text-body);
  flex-shrink: 0;
}

.palette-grid {
  display: flex;
  gap: 0.45rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.swatch-wrapper { position: relative; }

.swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}

.swatch:hover {
  transform: scale(1.04);
  box-shadow: 0 0 0 1px var(--border-active);
}

.color-picker-hidden {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.bg-swatch-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.bg-swatch {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
}

.bg-swatch-wrap input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Buttons */
.btn-ghost {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-body);
  background: transparent;
  border: 1px dashed var(--border-dashed);
  border-radius: var(--radius-lg);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.export-row {
  display: flex;
  gap: 0.5rem;
}

/* Export progress */
.export-progress {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.progress-track {
  flex: 1;
  height: 2px;
  background: var(--bg-input);
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--text-primary);
  border-radius: 1px;
  transition: width 0.15s;
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-label);
  min-width: 4.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 900px) {
  body { flex-direction: column; }

  .app {
    height: auto;
    overflow: visible;
    padding: 2rem 1.5rem;
  }

  .preview-col {
    flex: none;
  }

  .canvas-card {
    flex: none;
    aspect-ratio: 1;
  }

  .controls {
    width: 100%;
    height: auto;
    position: static;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 2rem 1.5rem;
  }
}
