* {
  box-sizing: border-box;
}

:root {
  --ink: #171717;
  --gold: #c69a45;
  --muted: #777;
  --line: #302b23;
}

body {
  margin: 0;
  background: #101010;
  color: #eee;
  font-family: Inter, Arial, sans-serif;
}

/* CABEÇALHO */

.topbar {
  height: 72px;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  color: white;
  border-bottom: 1px solid #ffe5e5;
  position: relative;
  z-index: 60;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand b {
  font-size: 13px;
  letter-spacing: 2px;
}

.brand small {
  display: block;
  color: #a9a9a9;
  font-size: 9px;
  letter-spacing: 1.5px;
  margin-top: 4px;
}

.mark {
  width: 34px;
  height: 34px;
  border: 1px solid var(--gold);
  color: var(--gold);
  display: grid;
  place-items: center;
  font-family: Georgia;
  font-size: 22px;
}

.top-actions {
  display: flex;
  gap: 22px;
  align-items: center;
}

.live {
  font-size: 10px;
  letter-spacing: 1.3px;
  color: #ddd;
}

.live i {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #6ab58b;
  border-radius: 50%;
  margin-right: 7px;
}

.ghost {
  background: transparent;
  border: 1px solid #76613e;
  color: #e3c88e;
  padding: 9px 13px;
  border-radius: 4px;
  cursor: pointer;
}

/* LAYOUT PRINCIPAL */

.layout {
  display: block;
  width: 100%;
  max-width: 1600px;
  padding: 22px;
  margin: auto;
}

.viewer-panel {
  width: 100%;
  background: #171717;
  border: 1px solid #8a6b3a;
  border-radius: 8px;
  overflow: hidden;
  color: #f1eee8;
}

/* CABEÇALHO DO VISUALIZADOR */

.viewer-head {
  min-height: 92px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #302b23;
}

.eyebrow {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.8px;
  color: #a17b37;
}

.viewer-head h1 {
  font-size: 20px;
  margin: 6px 0 0;
  font-weight: 600;
  color: #f5f1e9;
}

/* ABAS DE VISUALIZAÇÃO */

.view-tabs {
  display: flex;
  gap: 4px;
  background: #24211c;
  padding: 4px;
  border-radius: 5px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 9px 12px;
  font-size: 9px;
  letter-spacing: .7px;
  color: #b8b1a5;
  cursor: pointer;
  border-radius: 3px;
}

.tab.active {
  background: #c49a4c;
  color: #15120d;
}

/* VISUALIZADOR 3D */

#stage {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  min-height: 0;
  max-height: none;
  position: relative;
  overflow: hidden;
  background: #fff;
}

.stage-grid {
  position: absolute;
  inset: 0;

  background-image:
    linear-gradient(#eeeeec 1px, transparent 1px),
    linear-gradient(90deg, #eeeeec 1px, transparent 1px);

  background-size: 54px 54px;
  opacity: .25;
  pointer-events: none;
}

#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Desktop: visualizador quadrado com tamanho limitado pela altura da janela.
   Evita que o palco 3D se expanda até ocupar toda a largura da página. */
@media (min-width: 801px) {
  #stage {
    width: min(100%, 70vh, 820px);
    height: auto;
    aspect-ratio: 1 / 1;
    margin-inline: auto;
  }
}

.stage-hint {
  position: absolute;
  bottom: 14px;
  left: 18px;
  color: #777;
  font-size: 9px;
  letter-spacing: 1px;
  z-index: 2;
  pointer-events: none;
}

#loading {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8c713e;
  font-size: 11px;
  letter-spacing: 2px;
  background: #fff;
}

#loading.hidden {
  display: none;
}

/* CONTROLES DO VISUALIZADOR */

.viewer-controls {
  min-height: 62px;
  border-top: 1px solid #302b23;
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 30px;
}

.switchline,
.speed {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  color: #b8b1a5;
}

.switchline input {
  display: none;
}

.switch {
  width: 30px;
  height: 16px;
  background: #ccc;
  border-radius: 20px;
  position: relative;
  cursor: pointer;
}

.switch:after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  left: 2px;
  top: 2px;
  transition: .2s;
}

.switchline input:checked + .switch {
  background: var(--gold);
}

.switchline input:checked + .switch:after {
  left: 16px;
}

.speed {
  font-size: 9px;
  letter-spacing: 1px;
  margin-left: auto;
}

.speed input {
  width: 110px;
  accent-color: var(--gold);
}

.speed b {
  font-size: 10px;
  letter-spacing: 0;
  color: #eee;
  width: 30px;
}

.control-buttons {
  display: flex;
  gap: 6px;
}

.iconbtn {
  width: 30px;
  height: 30px;
  border: 1px solid #494033;
  background: #211f1b;
  border-radius: 4px;
  font-size: 18px;
  cursor: pointer;
  color: #e0d0ad;
}

/* EXPORTAÇÃO */

.export-row {
  border-top: 1px solid #302b23;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.gold-btn,
.outline-btn {
  height: 39px;
  padding: 0 16px;
  border-radius: 4px;
  font-size: 9px;
  letter-spacing: 1px;
  font-weight: 700;
  cursor: pointer;
}

.gold-btn {
  background: #c49a4c;
  color: #17120a;
  border: 1px solid #c49a4c;
}

.outline-btn {
  background: #211f1b;
  border: 1px solid #78613b;
  color: #e6d6b4;
}

.gold-btn:hover {
  background: #d5ad65;
}

.outline-btn:hover {
  border-color: #d0a653;
}

#exportStatus {
  font-size: 10px;
  color: #d0aa62;
  margin-left: auto;
}

/* =========================================
   PAINEL LATERAL FLUTUANTE
   ========================================= */

.editor {
  position: fixed;

  top: 88px;
  right: 0;
  bottom: 14px;

  width: min(410px, calc(100vw - 12px));
  max-height: calc(100vh - 102px);

  z-index: 50;

  padding: 22px 20px 22px 62px;

  display: flex;
  flex-direction: column;

  background: #171717;
  color: #f1eee8;

  border: 1px solid #302b23;
  border-right: 0;
  border-radius: 9px 0 0 9px;

  overflow-x: hidden;
  overflow-y: auto;

  box-shadow: -8px 0 28px rgba(0, 0, 0, .30);

  transform: translateX(calc(100% - 46px));
  transition: transform .35s ease;
}

/* ABA DE ABERTURA */

.editor-handle {
  position: absolute;

  top: 0;
  left: 0;
  bottom: 0;

  width: 46px;

  border: 0;
  border-right: 1px solid #66502e;

  background: #211d16;
  color: #d3aa60;

  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;

  writing-mode: vertical-rl;

  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;

  z-index: 5;
}

.editor-handle:hover {
  background: #302719;
  color: #f0cf8e;
}

.handle-arrow {
  font-size: 17px;
  transition: transform .35s ease;
}

/* ABERTURA COM O MOUSE */

@media (hover: hover) and (pointer: fine) {
  .editor:hover,
  .editor:focus-within {
    transform: translateX(0);
  }
}

/* ABERTURA POR TOQUE OU CLIQUE */

.editor.is-open {
  transform: translateX(0);
}

.editor.is-open .handle-arrow {
  transform: rotate(180deg);
}

/* BARRA DE ROLAGEM DO PAINEL */

.editor::-webkit-scrollbar {
  width: 6px;
}

.editor::-webkit-scrollbar-track {
  background: #171717;
}

.editor::-webkit-scrollbar-thumb {
  background: #66502e;
  border-radius: 10px;
}

/* TÍTULO DO EDITOR */

.editor-title h2 {
  font-size: 20px;
  margin: 6px 0;
  color: #f5f1e9;
}

.editor-title p {
  font-size: 11px;
  color: #b8b1a5;
  margin: 0 0 17px;
}

.region-list {
  display: grid;
  gap: 9px;
  min-width: 0;
}

/* REGIÕES */

.region {
  border: 1px solid #393329;
  border-radius: 5px;
  padding: 12px;
  background: #1d1b18;
}

.region-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.region-top b {
  font-size: 10px;
  letter-spacing: 1px;
  color: #eee;
}

.region-top small {
  display: block;
  color: #aaa;
  font-size: 9px;
  margin-top: 4px;
}

.region-icon {
  font-size: 20px;
  color: #b18a49;
}

/* SELETOR DE COR */

.color-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0;
}

.color-line label {
  font-size: 10px;
  color: #b8b1a5;
}

.color {
  width: 36px;
  height: 24px;
  border: 1px solid #ddd;
  background: white;
  padding: 2px;
  cursor: pointer;
}

/* UPLOAD DE ESTAMPA */

.upload {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border: 1px dashed #6e5938;
  color: #d1aa62;
  font-size: 9px;
  letter-spacing: .7px;
  cursor: pointer;
  border-radius: 3px;
}

.upload:hover {
  background: #292319;
}

.file-name {
  font-size: 9px;
  color: #aaa;
  margin-top: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* CONTROLES INDIVIDUAIS DA ESTAMPA */

.art-controls {
  border-top: 1px solid #393329;
  margin-top: 10px;
  padding-top: 9px;
}

.controls-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 8px;
  letter-spacing: 1px;
  color: #d3aa60;
  margin-bottom: 8px;
}

.controls-heading span {
  color: #9e927e;
  letter-spacing: 0;
}

.art-controls > label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  font-size: 9px;
  color: #c5bdae;
  margin: 7px 0;
}

.art-controls output {
  color: #e1c58e;
  font-variant-numeric: tabular-nums;
}

.art-controls input[type="range"] {
  grid-column: 1 / 3;
  width: 100%;
  accent-color: #c49a4c;
  height: 13px;
}

/* ESPELHAMENTO */

.flip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.flip-row label {
  font-size: 9px;
  color: #c5bdae;
  display: flex;
  align-items: center;
  gap: 5px;
}

.flip-row input {
  accent-color: #c49a4c;
}

/* BOTÕES DE RESTAURAR E REMOVER */

.clear-art,
.reset-settings {
  border: 0;
  background: none;
  color: #b8a98c;
  font-size: 9px;
  padding: 7px 0 0;
  cursor: pointer;
}

.clear-art:hover,
.reset-settings:hover {
  color: #e2bd76;
}

.reset-settings {
  border: 1px solid #51432d;
  border-radius: 3px;
  padding: 6px 8px;
  margin-top: 9px;
}

/* GOLA */

.collar-region {
  border-color: #78613b;
  background: #211e18;
}

.collar-region .region-icon {
  color: #d2a95f;
}

/* NOTA DO TECIDO */

.note {
  background: #242016;
  border-left: 2px solid #c49a4c;
  padding: 11px 13px;
  margin-top: 14px;
}

.note b {
  font-size: 9px;
  letter-spacing: 1.3px;
  color: #d3aa60;
}

.note p {
  font-size: 10px;
  line-height: 1.5;
  color: #bdb5a7;
  margin: 5px 0 0;
}

/* RODAPÉ */

.editor-foot {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 17px;
  color: #847c70;
  font-size: 8px;
  letter-spacing: 1.3px;
}

/* =========================================
   TABLETS
   ========================================= */

@media (max-width: 1050px) {

  .layout {
    display: block;
    padding: 12px;
  }

  .editor {
    position: fixed;
    top: 78px;
    bottom: 10px;
    max-height: calc(100vh - 88px);
    z-index: 50;
  }

  #stage {
    aspect-ratio: 1 / 1;
    height: auto;
  }

}

/* =========================================
   CELULARES
   ========================================= */

@media (max-width: 650px) {

  .topbar {
    padding: 0 14px;
  }

  .layout {
    padding: 10px;
    gap: 10px;
  }

  .viewer-head {
    height: auto;
    display: block;
    padding: 15px;
  }

  .view-tabs {
    margin-top: 13px;
    overflow: auto;
  }

  .tab {
    white-space: nowrap;
    padding: 9px 10px;
  }

  #stage {
    min-height: 0;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .viewer-controls {
    padding: 10px 12px;
    gap: 10px;
    flex-wrap: wrap;
    height: auto;
    min-height: 65px;
  }

  .speed input {
    width: 70px;
  }

  .export-row {
    padding: 12px;
    flex-wrap: wrap;
  }

  .gold-btn,
  .outline-btn {
    flex: 1;
    padding: 0 7px;
    font-size: 8px;
  }

  .editor {
    width: min(390px, calc(100vw - 8px));
    padding: 16px 12px 16px 58px;

    top: 74px;
    bottom: 8px;
    max-height: calc(100vh - 82px);
  }

  .editor-handle {
    width: 44px;
    font-size: 9px;
  }

}

/* =========================================
   ATUALIZAÇÃO MOBILE — VISUALIZAÇÃO FIXA + PAINÉIS EXPANSÍVEIS
   ========================================= */
.region {
  padding: 0;
  overflow: hidden;
}

.region > .region-top {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  min-height: 54px;
}

.region > .region-top::-webkit-details-marker { display: none; }
.region > .region-top::marker { content: ""; }
.region > .region-top::after {
  content: "+";
  color: #d3aa60;
  font-size: 20px;
  line-height: 1;
  margin-left: 12px;
}
.region[open] > .region-top::after { content: "−"; }
.region > .region-top .region-icon { margin-left: auto; }
.region > .color-line,
.region > .upload,
.region > .file-name,
.region > .art-controls,
.region > .clear-art {
  margin-left: 12px;
  margin-right: 12px;
}
.region > .color-line { margin-top: 8px; }
.region > .clear-art { margin-bottom: 12px; }
.region:not([open]) > :not(summary) { display: none !important; }

@media (max-width: 650px) {
  html, body { min-height: 100%; }
  body { overflow-x: hidden; }

  .topbar {
    position: relative;
    z-index: 30;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 0 16px;
    overflow: visible;
  }

  /* O visualizador permanece no topo enquanto os controles passam abaixo. */
  .viewer-panel {
    position: sticky;
    top: 0;
    z-index: 25;
    width: 100%;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 7px 18px rgba(0,0,0,.28);
  }

  .viewer-head {
    padding: 9px 12px;
  }
  .viewer-head .eyebrow { font-size: 8px; }
  .viewer-head h1 { font-size: 14px; margin-top: 3px; }
  .view-tabs { margin-top: 7px; padding: 3px; }
  .tab { padding: 7px 9px; font-size: 8px; }

  #stage {
    height: auto;
    min-height: 0;
    max-height: none;
    aspect-ratio: 1 / 1;
  }

  .stage-hint { bottom: 6px; left: 9px; font-size: 7px; }

  .viewer-controls {
    min-height: 48px;
    padding: 7px 10px;
    gap: 9px;
    flex-wrap: nowrap;
  }
  .switchline, .speed { font-size: 9px; gap: 5px; white-space: nowrap; }
  .speed { margin-left: auto; }
  .speed input { width: 48px; }
  .speed b { width: auto; font-size: 9px; }
  .control-buttons { display: none; }

  .editor {
    position: relative;
    inset: auto;
    transform: none;
    width: 100%;
    max-height: none;
    min-height: 0;
    margin: 0;
    padding: 15px 11px 12px;
    border: 0;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    background: #101010;
    z-index: 1;
  }

  .editor-handle { display: none; }
  .editor-title { padding: 0 2px 8px; }
  .editor-title h2 { font-size: 17px; }
  .editor-title p { margin-bottom: 5px; }
  .region-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .region { border-radius: 7px; background: #1d1b18; }
  .region-top { display: flex; align-items: center; }

  .export-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 14px 0 8px;
    border-top: 1px solid #302b23;
    margin-top: 14px;
  }
  .export-row .gold-btn,
  .export-row .outline-btn {
    width: 100%;
    min-height: 44px;
    height: auto;
    font-size: 9px;
  }
  #exportStatus {
    display: block;
    min-height: 18px;
    margin: 0;
    line-height: 1.4;
  }
  .editor-foot { padding-top: 10px; }
}

@media (max-width: 360px) {
  .viewer-controls { gap: 6px; }
  .speed input { width: 38px; }
}

/* VISUALIZADOR QUADRADO EM TELAS TOUCH */
@media (max-width: 800px) {
  /* A largura disponível define a altura: área 3D em proporção 1:1. */
  #stage {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    min-height: 0;
    max-height: none;
  }
}


/* =========================================
   PAINEL RETRÁTIL DE CORES — LADO ESQUERDO
   ========================================= */
.color-editor {
  position: fixed;
  top: 88px;
  left: 0;
  bottom: 14px;
  width: min(330px, calc(100vw - 12px));
  max-height: calc(100vh - 102px);
  z-index: 49;
  padding: 22px 62px 22px 20px;
  display: flex;
  flex-direction: column;
  background: #171717;
  color: #f1eee8;
  border: 1px solid #302b23;
  border-left: 0;
  border-radius: 0 9px 9px 0;
  overflow: hidden;
  box-shadow: 8px 0 28px rgba(0,0,0,.30);
  transform: translateX(calc(-100% + 46px));
  transition: transform .35s ease;
}
.color-editor-handle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 46px;
  border: 0;
  border-left: 1px solid #66502e;
  background: #211d16;
  color: #d3aa60;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  writing-mode: vertical-rl;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  z-index: 5;
}
.color-editor-handle:hover { background: #302719; color: #f0cf8e; }
.color-handle-arrow { font-size: 17px; transition: transform .35s ease; }
.color-editor.is-open { transform: translateX(0); }
.color-editor.is-open .color-handle-arrow { transform: rotate(180deg); }
@media (hover:hover) and (pointer:fine) {
  .color-editor:hover,
  .color-editor:focus-within { transform: translateX(0); }
}
.color-editor-content {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  padding-right: 2px;
}
.color-editor-content::-webkit-scrollbar { width: 6px; }
.color-editor-content::-webkit-scrollbar-thumb { background: #66502e; border-radius: 10px; }
.color-editor-title h2 { margin: 6px 0; color: #f5f1e9; font-size: 19px; }
.color-editor-title p { margin: 0 0 16px; color: #b8b1a5; font-size: 11px; line-height: 1.45; }
.color-global {
  border-color: #806326 !important;
  background: #242016 !important;
  margin-bottom: 11px;
}
.color-entry {
  min-height: 58px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0,1fr) 38px 30px;
  align-items: center;
  gap: 8px;
  border: 1px solid #393329;
  border-radius: 6px;
  background: #1d1b18;
}
.color-region-list { display: grid; gap: 8px; }
.color-entry-label { min-width: 0; }
.color-entry-label b { display: block; color: #eee; font-size: 10px; letter-spacing: .8px; }
.color-entry-label small { display: block; color: #aaa; font-size: 9px; margin-top: 4px; }
.color-entry input[type="color"] {
  width: 36px;
  height: 27px;
  padding: 2px;
  border: 1px solid #79633e;
  border-radius: 4px;
  background: #111;
  cursor: pointer;
}
.eyedropper {
  width: 30px;
  height: 30px;
  border: 1px solid #51432d;
  border-radius: 4px;
  background: #211f1b;
  color: #d3aa60;
  font-size: 19px;
  cursor: pointer;
}
.eyedropper:hover { border-color: #c49a4c; background: #302719; }
.color-hint {
  margin: 12px 2px 0;
  color: #938875;
  font-size: 9px;
  line-height: 1.5;
}
#stage.is-picking-color,
#stage.is-picking-color canvas { cursor: crosshair !important; }

@media (max-width: 650px) {
  .color-editor {
    position: relative;
    inset: auto;
    transform: none;
    width: 100%;
    max-height: none;
    min-height: 0;
    margin: 0;
    padding: 0 11px;
    display: block;
    border: 0;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    background: #101010;
    z-index: 2;
  }
  .color-editor-handle {
    position: relative;
    inset: auto;
    width: 100%;
    height: 38px;
    border: 1px solid #66502e;
    border-radius: 6px;
    writing-mode: horizontal-tb;
    flex-direction: row;
    gap: 9px;
    margin: 10px 0 0;
    font-size: 9px;
  }
  .color-handle-arrow { transform: rotate(90deg); }
  .color-editor.is-open .color-handle-arrow { transform: rotate(-90deg); }
  .color-editor-content {
    display: none;
    height: auto;
    max-height: 48vh;
    overflow-y: auto;
    padding: 13px 0 10px;
  }
  .color-editor.is-open .color-editor-content { display: block; }
  .color-editor-title h2 { font-size: 16px; }
  .color-global { margin-bottom: 8px; }
  .color-entry { min-height: 54px; }
}


/* Histórico de edição */
.history-btn:disabled { opacity: .35; cursor: not-allowed; }
.history-btn:not(:disabled):hover { background: #2b2418; border-color: var(--gold); }
@media (max-width: 700px) {
  .top-actions { gap: 6px; }
  .history-btn { padding: 8px 7px; font-size: 10px; }
}
