/* Brutalist, almost bare */
:root {
  --bg: #F8F8F4;   /* natural white */
  --fg: #1f1f1f;   /* readable body text */
  --muted: #6e6e6e;/* secondary text */
  --line: #3a3a3a; /* hairline borders */

  /* fluid type and spacing */
  --step-0: clamp(14px, 1.6vw, 15px);
  --step-1: clamp(16px, 2vw, 18px);
  --space:  clamp(10px, 2vw, 16px);
}

* { box-sizing: border-box; }

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

html, body { margin: 0; }

body {
  min-height: 100svh;
  /* falls back to flat paper if no vignette is set */
  background: var(--bg-gradient, var(--bg));
  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;

  /* mobile comfort */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;

  /* safe areas */
  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));
}

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

/* Utilities */
.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); }
.gap8  { gap: max(6px, 1.5vw); }
.gap12 { gap: max(8px, 2vw); }
.gap24 { gap: max(12px, 3.5vw); }

/* Layout */
main {
  max-width: 760px;
  margin: clamp(16px, 5vw, 28px) auto clamp(28px, 7vw, 44px);
  padding: 0 clamp(12px, 4vw, 16px);
}

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

/* Lamp */
.lamp {
  position: relative;
  width: min(520px, 92vw);
  aspect-ratio: 3/4;
  display: grid;
  place-items: end center;
  /* subtle grounding without shifting layout */
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.06));
  --flame-scale: 0.8;
}

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

/* Single source of truth for flame mount */
.flame-mount {
  position: absolute;
  left: 50%;
  top: 38.5%;
  width: 28%;
  aspect-ratio: 3/4;
  transform: translate(-50%, -50%) scale(var(--flame-scale));
  transform-origin: center;
  will-change: transform; /* optional */

  /* Defaults if no color is set yet */
  --flame-core: #ffb44a;
  --flame-aura: #ffd38a;
}

@media (max-width: 420px) {
  .lamp { --flame-scale: 0.92; }  /* shrink ~8% on small phones */
  .flame-mount { width: 32%; top: 36%; } /* keep your existing nudge */
}

/* Minimal flame styling */
.flame-root {
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 250ms ease;
  will-change: opacity;
}

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

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

/* Controls */
/* Keep controls at 16px+ to prevent iOS zoom */
button, select, label { font-size: 16px; }

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

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

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

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

select { min-width: 120px; }

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

/* Settings gear */
#settingsBtn {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 24px;
  color: var(--muted);
  line-height: 1;
}
#settingsBtn:hover { color: var(--fg); }
#settingsBtn:focus-visible {
  outline: 2px solid #000;
  outline-offset: 2px;
}
/* larger invisible hit area */
#settingsBtn::after {
  content: "";
  position: absolute;
  inset: -8px;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  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.55);   /* simple scrim */
  overflow: auto;                  /* scroll if needed */
  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: var(--bg);           /* match paper */
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  gap: 12px;                       /* internal rhythm */
  -webkit-overflow-scrolling: touch;
}

/* Header row */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;                       /* rely on gap */
  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 button: square, bordered, brutalist */
.close-btn {
  border: none;         
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
}

/* Body text and muted copy */
.modal-head { margin: 0; }
.muted { color: var(--muted); margin: 0; }

/* Control rows inside modal */
.modal-box .row {
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Wrap dropdowns and reset in a column */
.modal-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px; /* spacing between dropdown row and button */
  margin-top: 12px;
}

/* Dropdown row remains inline */
.modal-controls .row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

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

.reset-btn:hover { background: #f4f3f0; }
.reset-btn:active { background: #eeeae6; }
.reset-btn:focus-visible {
  outline: 2px solid #b66;
  outline-offset: 2px;
}

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

.muted,
.muted.small {
  text-align: center;
  display: block; /* ensures labels/paragraphs expand to full width */
}

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

/* Very small devices */
@media (max-width: 420px) {
  .flame-mount { width: 32%; top: 36%; }
  button, select { padding: 10px 10px; }
  select { min-width: 48vw; }
}

/* High-DPR border polish */
@media (min-resolution: 2dppx) {
  :root { --line: rgba(58,58,58,0.7); }
}

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