:root {
  --bg: #F7F3EE;
  --panel: #FFFCF8;
  --soft: #F3EEE7;
  --charcoal: #2A2622;
  --muted: #6B645C;
  --orange: #F05A28;
  --sage: #5B8F86;
  --line: #E4DCD2;
  --select: #FFE8DE;
}

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

body {
  font-family: "Trebuchet MS", "Segoe UI", Candara, "Gill Sans", sans-serif;
  background: var(--bg);
  color: var(--charcoal);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input { font: inherit; border: 0; background: none; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.top {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 238, 0.95);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.top-right { display: flex; align-items: center; gap: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.chip-ember {
  background: linear-gradient(180deg, #F56B3A, #F05A28);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(240, 90, 40, 0.25);
  font-weight: 750;
}

.app {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  min-height: 0;
  gap: 14px;
  padding: 14px 16px 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(42, 38, 34, 0.05);
  padding: 14px;
  min-height: 0;
  overflow: auto;
}

.tools h2, .side h2 {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tbtn {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--charcoal);
  font-size: 11px;
  font-weight: 650;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.tbtn:hover { border-color: #d4c8ba; }
.tbtn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tbtn.on {
  background: var(--select);
  border-color: #F5C7B2;
  color: var(--orange);
}

.wheel-wrap {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0 10px;
}

.wheel-box {
  position: relative;
  width: 112px;
  height: 112px;
  flex-shrink: 0;
}

.wheel-box canvas {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  cursor: crosshair;
  display: block;
}

.wheel-knob {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #333;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.bright-box {
  position: relative;
  width: 12px;
  height: 112px;
  flex-shrink: 0;
}

.bright-box canvas {
  width: 12px;
  height: 112px;
  border-radius: 99px;
  border: 1px solid var(--line);
  cursor: ns-resize;
  display: block;
}

.bright-knob {
  position: absolute;
  left: -3px;
  width: 16px;
  height: 8px;
  border-radius: 4px;
  background: #fff;
  border: 1px solid #999;
  pointer-events: none;
  transform: translateY(-50%);
}

.color-now {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.color-now .swatch-lg {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  padding: 0;
}
.swatch:hover { transform: scale(1.12); }
.swatch.on { box-shadow: 0 0 0 2px var(--orange); }

.size-row {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.size-row-spaced { margin-top: 12px; }

.slider-wrap { position: relative; height: 18px; display: flex; align-items: center; }

.slider-wrap input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 7px;
  border-radius: 99px;
  background: transparent;
  outline: none;
  cursor: pointer;
  position: relative;
  z-index: 1;
}
.slider-wrap::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
  height: 7px;
  border-radius: 99px;
  background: #E8E0D6;
}

.slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--orange);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.slider-wrap input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--orange);
  cursor: pointer;
}

.slider-wrap input[type="range"]::-moz-range-track {
  height: 7px;
  border-radius: 99px;
  background: transparent;
}

.slider-fill {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 7px;
  border-radius: 99px;
  background: var(--orange);
  pointer-events: none;
  max-width: 100%;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 4px 0;
}

.stage-top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 8px;
  padding: 0 4px;
  gap: 12px;
  flex-shrink: 0;
}

.stage-top h1 { font-size: 16px; font-weight: 750; }
.stage-top p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}
.ghost:hover { background: var(--soft); color: var(--charcoal); }

.canvas-frame {
  flex: 1;
  min-height: 0;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #FFFCF8, #F1EBE3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  container-type: size;
}

.canvas-wrap {
  /* Largest near-square that fits the stage (fills center, not a small card) */
  width: min(100%, 100cqw, 100cqh);
  height: auto;
  aspect-ratio: 1;
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #E8E0D6;
  box-shadow: 0 16px 36px rgba(42, 38, 34, 0.1);
  overflow: hidden;
  position: relative;
  touch-action: none;
}

/* Fallback when container queries unavailable */
@supports not (width: 1cqw) {
  .canvas-wrap {
    width: min(100%, calc(100vh - 140px));
    max-height: 100%;
  }
}

.canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.side { display: flex; flex-direction: column; gap: 14px; }

.label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
  margin-bottom: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage);
}

textarea {
  width: 100%;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--soft);
  padding: 12px;
  color: var(--charcoal);
  resize: none;
  outline: none;
}
textarea:focus { border-color: #c8b8a8; }

.meta {
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

.forge {
  width: 100%;
  margin-top: 12px;
  border-radius: 999px;
  padding: 13px 16px;
  background: linear-gradient(180deg, #F56B3A, #F05A28);
  color: #fff;
  font-weight: 750;
  font-size: 15px;
  box-shadow: 0 10px 22px rgba(240, 90, 40, 0.28);
}
.forge:hover { filter: brightness(1.04); }
.forge:active { transform: translateY(1px); }

.help {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
  line-height: 1.35;
}

.result {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: var(--soft);
  display: flex;
  gap: 10px;
  align-items: center;
}

.thumb {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
  flex-shrink: 0;
}

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

.thumb-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  padding: 4px;
}

.result strong { display: block; font-size: 13px; margin-bottom: 2px; }
.result span { font-size: 12px; color: var(--muted); }

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr) auto;
  }
  .tools { order: 1; }
  .stage { order: 2; min-height: 420px; }
  .side { order: 3; }
  .top-right .chip:not(.chip-ember) { display: none; }
}

@media (max-width: 520px) {
  .top { padding: 0 12px; }
  .app { padding: 10px; gap: 10px; }
  .stage-top { flex-direction: column; align-items: start; }
  .canvas-frame { padding: 8px; }
}

.site-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  text-align: center;
  padding: 10px 16px 14px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.site-footer .footer-muted {
  color: #A39A90;
  font-weight: 500;
}
.site-footer .footer-muted:hover { color: var(--muted); }

/* Offline / unavailable forge CTA — must not look clickable */
button.forge.is-offline,
button.chip.chip-ember.is-offline,
.forge.is-offline,
.chip-ember.is-offline {
  background-color: #E8E0D6 !important;
  background-image: none !important;
  background: #E8E0D6 !important;
  color: #6B645C !important;
  border: 1px solid #E4DCD2 !important;
  box-shadow: none !important;
  filter: none !important;
  opacity: 1 !important;
  cursor: not-allowed !important;
  pointer-events: auto; /* still allow click to reinforce offline message */
}
button.forge.is-offline:hover,
button.chip.chip-ember.is-offline:hover,
.forge.is-offline:hover,
.chip-ember.is-offline:hover,
button.forge.is-offline:active,
button.chip.chip-ember.is-offline:active,
.forge.is-offline:active,
.chip-ember.is-offline:active {
  background: #E8E0D6 !important;
  background-image: none !important;
  filter: none !important;
  transform: none !important;
  box-shadow: none !important;
}
