/* Brutalist, dark, lamp in a void */
:root {
  --bg: #000000;
  --fg: #f5f5f5;
  --muted: #9a9a9a;
  --line: #444444;

  --step-0: clamp(14px, 1.6vw, 15px);
  --step-1: clamp(16px, 2vw, 18px);
  --space:  clamp(10px, 2vw, 16px);

  /* vignette control, updated from JS */
  --vig-x: 50%;
  --vig-y: 60%;
  --vig-radius: 390px;
  --vig-color: #ff8b3d; /* default amber */
  --vig-strength: 1;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

html, body { margin: 0; }

html, body {
  touch-action: manipulation;
}

body {
  min-height: 100svh;
  background: #000; /* pure void */
  color: var(--fg);
  font: var(--step-0)/1.5 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;

  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;

  padding: max(0px, env(safe-area-inset-top))
           max(0px, env(safe-area-inset-right))
           max(0px, env(safe-area-inset-bottom))
           max(0px, env(safe-area-inset-left));
}

/* permanent black mask over the whole world */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;     
  background: #000;
  opacity: var(--vig-strength);   
}

body.lit::before {
  background: radial-gradient(
    circle var(--vig-radius) at var(--vig-x) var(--vig-y),
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0.75) 180px,
    rgba(0,0,0,0.95) 260px,
    rgba(0,0,0,1) var(--vig-radius)
  );
}

/* Type */
h1 {
  margin: 0;
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

/* Simple layout helpers */
.row { display: flex; }
.col { display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; text-align: center; }
.space { justify-content: space-between; padding: var(--space) calc(var(--space) + 4px); }
.gap12 { gap: max(8px, 2vw); }
.gap8  { gap: max(4px, 1vw); }
.gap24 { gap: max(8px, 2vw); }


main {
  max-width: 760px;
  margin: clamp(8px, 2vw, 16px) auto clamp(12px, 3vw, 24px);
  padding: 0 clamp(10px, 3vw, 14px);
}

footer { padding: 20px; color: var(--muted); }

/* Lamp world: sits under the mask */
.lamp {
  position: relative;
  width: min(520px, 92vw);
  aspect-ratio: 3/4;
  display: grid;
  place-items: end center;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.06));
  --flame-scale: 0.7;
  opacity: 0;
  transition: opacity 800ms ease;
}

.lamp {
  position: relative;
  width: min(520px, 92vw);
  aspect-ratio: 3/4; /* shorter lamp box */
  display: grid;
  place-items: end center;
  /* rest unchanged */
}


body.lit .lamp {
  opacity: 1;
}

.lamp-base {
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  object-position: center bottom;
  filter: grayscale(85%) contrast(110%) brightness(0.7);
  mix-blend-mode: multiply;
  user-select: none;
  pointer-events: none;
  z-index: 100;
}

.flame-mount {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 28%;
  aspect-ratio: 3/4;
  transform: translate(-50%, -50%) scale(var(--flame-scale));
  transform-origin: center;
  will-change: transform;
}

@media (max-width: 420px) {
  .lamp { --flame-scale: 0.6; }
  .flame-mount { width: 32%; top: 40%; } 
  button, select { padding: 10px 10px; }
  select { min-width: 48vw; }
}

/* Flame SVG */
.flame-root {
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 220ms ease;
  will-change: opacity;
}

.flame-root[data-lit="true"] { opacity: 1; }

/* Status text */
#status {
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 3.6vw, 14px);
}

/* Controls */
button, select, label { font-size: 16px; }

button, select {
  appearance: none;
  background: #111;
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 4px;
  cursor: pointer;
}

button:hover, select:hover { background: #191919; }
button:active { background: #202020; }
button[disabled] { opacity: 0.5; cursor: default; }

button:focus-visible, select:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

label {
  color: var(--muted);
  gap: 6px;
}

select { min-width: 120px; }

/* UI layer: always above the mask */
.ui-layer {
  position: relative;
  z-index: 10000;
}

.icon-btn {
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  padding: 6px 10px;
  min-height: 40px;
  cursor: pointer;
}

/* Settings gear */
#settingsBtn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 30px;
  color: var(--muted);
  line-height: 1;
}

#settingsBtn:hover { color: var(--fg); }
#settingsBtn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Modal */
.modal.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 11000; /* above mask and UI */
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(0,0,0,0.6);
  overflow: auto;
  min-height: 100svh;
}

.modal-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;

  width: min(640px, 96vw);
  max-height: calc(100svh - 2 * max(16px, env(safe-area-inset-top)));
  overflow: auto;

  background: #050505;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-title {
  margin: 0;
  font-size: clamp(16px, 4.8vw, 18px);
  font-weight: 600;
  color: var(--fg);
}

.close-btn {
  border: none;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  background: #111;
  color: var(--fg);
}

.modal-head { margin: 0; }
.muted { color: var(--muted); margin: 0; }

.modal-box .row {
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

.modal-controls .row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.reset-btn {
  background: #111;
  color: var(--fg);
  border: 1px solid #b66;
  padding: 10px 14px;
  cursor: pointer;
}

.reset-btn:hover { background: #191919; }
.reset-btn:active { background: #202020; }
.reset-btn:focus-visible {
  outline: 2px solid rgb(195, 46, 46);
  outline-offset: 2px;
}

.small {
  font-size: clamp(12px, 3.2vw, 13.6px);
  line-height: 1.3;
}

.muted,
.muted.small {
  text-align: center;
  display: block;
}

@media (max-width: 480px) {
  .modal-header { padding-bottom: 8px; }
  .modal-controls { gap: 12px; margin-top: 10px; }
  .modal-controls .row { gap: 8px; }
}

@media (min-resolution: 2dppx) {
  :root { --line: rgba(68,68,68,0.8); }
}

@media (prefers-reduced-motion: reduce) {
  .flame-root { transition: none; }
  * { scroll-behavior: auto; }
}

header.row.space {
  align-items: center;
}
