/* ================================================================ base */
:root {
  --bg: #121418;
  --panel: rgba(22, 24, 29, 0.94);
  --panel2: rgba(255, 255, 255, 0.035);
  --line: rgba(255, 255, 255, 0.075);
  --btn: #23262d;
  --btn-h: #2e323b;
  --field: #1b1e24;
  --fg: #e9eaee;
  --mut: #8c929e;
  --dim: #646a76;
  --acc: #e8b64c;        /* dourado: ferramenta ativa, ação principal, destaque */
  --acc-fg: #1c1505;
  --acc-soft: rgba(232, 182, 76, 0.15);
  --acc2: #4c8dff;
  --bad: #ef5a5a;
  --ok: #3ccf8e;
  --r: 12px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.38), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --top-h: calc(56px + var(--safe-t));
  --status-h: calc(30px + var(--safe-b));
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; touch-action: none; }
#c { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.hidden { display: none !important; }
svg.ui { width: 20px; height: 20px; flex: none; display: block; }

/* ================================================================ botões */
button {
  font: inherit; color: var(--fg); background: var(--btn); border: 1px solid transparent; border-radius: 10px;
  min-height: 42px; min-width: 42px; padding: 0 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
button:hover { background: var(--btn-h); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.35; pointer-events: none; }
button.primary { background: var(--acc); color: var(--acc-fg); font-weight: 600; }
button.primary:hover { background: #f0c463; }
button.danger { background: transparent; color: var(--bad); border-color: rgba(239, 90, 90, 0.45); }
button.danger:hover { background: rgba(239, 90, 90, 0.12); }
button.subtle { background: transparent; color: var(--mut); border-color: var(--line); }
button.subtle:hover { color: var(--fg); background: var(--panel2); }

/* ================================================================ barra de cima */
#top {
  position: absolute; top: 0; left: 0; right: 0; height: var(--top-h); z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: var(--safe-t) 12px 0 calc(12px + var(--safe-l));
  background: var(--panel); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  overflow-x: auto; scrollbar-width: none;
}
#top::-webkit-scrollbar { display: none; }
#top .grow { flex: 1; }
.brand { display: flex; align-items: center; gap: 8px; padding: 0 6px 0 2px; flex: none; color: var(--acc); }
.brand svg.ui { width: 22px; height: 22px; }
.brand b { color: var(--fg); font-size: 15px; font-weight: 650; letter-spacing: 0.01em; }
.tgroup {
  display: flex; align-items: center; gap: 2px; padding: 3px; flex: none;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
}
.tb {
  min-height: 38px; min-width: 38px; padding: 0 11px; background: transparent; border-radius: 9px;
  font-size: 13px; white-space: nowrap; color: #d4d7de;
}
.tb.ico { padding: 0; }
.tb:hover { background: var(--btn-h); color: var(--fg); }
.tb.on { background: var(--acc-soft); color: var(--acc); }

/* ================================================================ ferramentas (esquerda) */
#tools {
  position: absolute; left: calc(12px + var(--safe-l)); top: 50%; transform: translateY(-50%); z-index: 5;
  display: flex; flex-direction: column; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.tool {
  width: 64px; height: 62px; padding: 0; flex-direction: column; gap: 4px;
  background: transparent; border-radius: 13px; font-size: 11px; font-weight: 500; color: #c3c7cf;
}
.tool svg.ui { width: 25px; height: 25px; }
.tool:hover { background: var(--btn-h); color: var(--fg); }
.tool.active { background: var(--acc); color: var(--acc-fg); }
.tool[data-tool="erase"]:not(.active) svg.ui { color: #f08a8a; }
.tsep { height: 1px; margin: 2px 10px; background: var(--line); }

/* ================================================================ barra da pedra selecionada */
#stoneHud {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--top-h) + 12px); z-index: 7;
  display: flex; align-items: center; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.hb { min-width: 46px; min-height: 46px; padding: 0; background: transparent; border-radius: 11px; }
.hb svg.ui { width: 22px; height: 22px; }
.hb.wide { padding: 0 14px 0 12px; background: var(--acc); color: var(--acc-fg); font-weight: 600; }
.hb.wide:hover { background: #f0c463; }
.hb.bad { color: var(--bad); }
.hb.ok { color: var(--ok); }
.hsep { width: 1px; height: 26px; background: var(--line); margin: 0 3px; }
#hSize { min-width: 76px; text-align: center; font: 600 14px ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ================================================================ painéis (estilo comum) */
#panel, #exportMenu, #pavePanel, #stonePanel, #outliner {
  position: absolute; z-index: 6; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
#panel, #exportMenu { right: 12px; top: calc(var(--top-h) + 10px); width: 310px; padding: 16px; gap: 12px; }
#exportMenu { gap: 6px; padding: 8px; width: 290px; }
#exportMenu button { justify-content: flex-start; background: transparent; min-height: 44px; }
#exportMenu button:hover { background: var(--btn-h); }
#pavePanel {
  right: 12px; top: calc(var(--top-h) + 10px); bottom: calc(var(--status-h) + 10px); width: 350px;
  padding: 14px; gap: 12px; overflow-y: auto;
}
#stonePanel {
  left: calc(98px + var(--safe-l)); bottom: calc(var(--status-h) + 10px); width: 320px; padding: 14px; gap: 10px;
  max-height: calc(100% - var(--top-h) - var(--status-h) - 20px); overflow-y: auto;
}
#outliner {
  right: 12px; top: calc(var(--top-h) + 10px); bottom: calc(var(--status-h) + 10px); width: 350px; padding: 12px; gap: 8px;
}
#panel h3, #pavePanel h3, #stonePanel h3, #outliner h3 { margin: 0; font-size: 15px; font-weight: 650; }

/* campos */
#panel label, #pavePanel label, #stonePanel label {
  display: flex; flex-direction: column; gap: 5px; color: var(--mut); font-size: 12.5px; position: relative;
}
#panel label.chk, #pavePanel label.chk, #stonePanel label.chk {
  flex-direction: row; align-items: center; gap: 9px; color: var(--fg); font-size: 13.5px;
}
input[type=number], select {
  font: inherit; font-size: 14px; height: 38px; width: 100%; padding: 0 10px; color: var(--fg);
  background: var(--field); border: 1px solid var(--line); border-radius: 9px; outline: none;
  -webkit-user-select: text; user-select: text; -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238c929e' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
}
input[type=number]:focus, select:focus { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-soft); }
input:disabled { opacity: 0.4; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; margin: 0; accent-color: var(--acc); flex: none; }
input[type=range] { width: 100%; height: 28px; accent-color: var(--acc); }
#panel label output { position: absolute; right: 0; top: 0; color: var(--fg); font-variant-numeric: tabular-nums; }

.note { color: var(--dim); font-size: 12px; display: block; line-height: 1.45; }
.note b { color: var(--mut); }

/* segmentado Manual / Automático */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; flex: none;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 12px;
}
.seg button { min-height: 36px; background: transparent; font-size: 13px; font-weight: 500; color: var(--mut); border-radius: 9px; }
.seg button:hover { color: var(--fg); background: var(--panel2); }
.seg button.active { background: var(--acc); color: var(--acc-fg); font-weight: 600; }

/* ================================================================ painel Cravação (automático) */
#pavePanel .row { display: flex; gap: 8px; align-items: center; }
#pavePanel .row .grow { flex: 1; }
#pavePanel .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#pavePanel .row3, #pavePanel .row3n { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
#pavePanel .row3 label.chk { font-size: 13px; gap: 6px; }
#pavePanel .lbl, #stonePanel .lbl {
  color: var(--mut); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; margin: 4px 0 6px;
}
#pavePanel .lbl small { color: var(--dim); text-transform: none; letter-spacing: 0; font-weight: 400; }
#pavePanel .ptabs {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 3px; padding: 3px; flex: none;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 12px;
}
#pavePanel .ptab { min-height: 38px; padding: 0 4px; font-size: 13px; background: transparent; color: var(--mut); border-radius: 9px; }
#pavePanel .ptab:hover { color: var(--fg); }
#pavePanel .ptab.active { background: var(--btn-h); color: var(--fg); }
#pavePanel .ptab.active .tico { color: var(--acc); }
#pavePanel .tabc { display: flex; flex-direction: column; gap: 12px; }
#pavePanel .tabc.hidden { display: none; }
#pavePanel details.sec { background: var(--panel2); border-radius: 10px; padding: 0 10px; }
#pavePanel details.sec[open] { padding-bottom: 10px; }
#pavePanel details.sec > summary { cursor: pointer; font-weight: 600; padding: 12px 2px; min-height: 44px; list-style-position: inside; }
#pavePanel details.sec > * + * { margin-top: 8px; }

#sizeList { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-bottom: 8px; }
.size-item { display: flex; align-items: center; gap: 6px; font-size: 13.5px; padding: 2px 0; }
.size-item .sw { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.size-item .x { margin-left: auto; min-height: 28px; min-width: 28px; padding: 0; background: transparent; color: var(--mut); }
#pStats {
  margin: 0; padding: 10px 12px; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--line); border-radius: 10px;
  font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; color: #cfd2d8;
  -webkit-user-select: text; user-select: text; flex: none;
}

/* ================================================================ painel Pedra (manual) */
#stonePanel .row { display: flex; gap: 6px; }
#stonePanel .row button { flex: 1; padding: 0 6px; }
#stonePanel .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#stonePanel .nudge { display: flex; align-items: center; gap: 6px; }
#stonePanel .nudge-v { display: flex; flex-direction: column; gap: 4px; }
#stonePanel .nudge button { min-width: 46px; padding: 0; font-size: 14px; }
#stonePanel .nudge-v button { min-height: 36px; }
#stonePanel .nudge label { flex: 1; margin-left: 6px; }

/* lapidações */
.cutgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cutbtn {
  flex-direction: column; gap: 3px; min-height: 66px; padding: 6px 2px; font-size: 10.5px; line-height: 1.1;
  color: var(--mut); background: var(--field); border: 1px solid var(--line);
}
.cutbtn .cuticon { width: 34px; height: 34px; color: #cfe2f5; }
.cutbtn:hover { border-color: rgba(255, 255, 255, 0.18); }
.cutbtn.active { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.cutbtn.active .cuticon { color: var(--acc); }
.ptab { display: inline-flex; align-items: center; gap: 6px; }
.ptab .tico { width: 19px; height: 19px; flex: none; }
.diag { background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.diag:empty { display: none; }
.pdiag { display: block; width: 100%; height: auto; max-height: 190px; font-family: inherit; }

/* ================================================================ painel Objetos (outliner) */
#outliner .ohead { display: flex; align-items: center; gap: 6px; padding-bottom: 4px; }
#outliner .ohead h3 { flex: 1; }
#outliner .ohead button { min-height: 34px; padding: 0 10px; font-size: 12.5px; }
#outList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.orow { display: flex; align-items: center; gap: 6px; min-height: 42px; border-radius: 9px; padding-right: 2px; }
.orow:hover { background: var(--panel2); }
.orow.active { background: var(--acc-soft); box-shadow: inset 2px 0 0 var(--acc); }
.orow.dim .otx { opacity: 0.42; }
.orow input[type=checkbox] { width: 18px; height: 18px; }
.orow .ock { width: 18px; flex: none; }
.orow .otg { min-width: 28px; min-height: 34px; padding: 0; background: transparent; color: var(--mut); }
.orow .oic { width: 20px; text-align: center; flex: none; }
.orow .otx { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.orow .onm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orow .onm.link { cursor: pointer; }
.orow .onm.link:hover { color: var(--acc); }
.orow .osub { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orow .oeye, .orow .odel { min-width: 38px; min-height: 38px; padding: 0; background: transparent; font-size: 16px; }
.orow .oeye.off { color: var(--dim); }
.orow .odel { color: var(--bad); font-size: 19px; opacity: 0.75; }
.orow .odel:hover { opacity: 1; }
.orow .odel-sp { width: 38px; flex: none; }
.oempty { color: var(--dim); font-size: 12px; padding: 4px 0 6px 50px; }
#outFoot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
#outFoot .ofrow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#outFoot .ofrow b { flex: 1; font-weight: 600; }
#outFoot button { min-height: 36px; padding: 0 10px; font-size: 12.5px; }
#outFoot select { height: 36px; flex: 1; width: auto; font-size: 12.5px; }

/* ================================================================ status, soltar arquivo, carregando */
#status {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; min-height: var(--status-h);
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 0 14px var(--safe-b); font-size: 12px; color: var(--dim);
  background: var(--panel); border-top: 1px solid var(--line);
}
#info { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
#hint { color: #c8ccd4; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }

#errBox {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--status-h) + 12px); z-index: 11;
  max-width: min(640px, 92vw); padding: 10px 14px; border-radius: 12px; font-size: 13px;
  background: #3a1d1f; color: #ffd5d5; border: 1px solid rgba(239, 90, 90, 0.5); box-shadow: var(--shadow);
  -webkit-user-select: text; user-select: text;
}
#drop {
  position: absolute; inset: 20px; border: 2px dashed var(--acc); border-radius: 22px; display: flex;
  align-items: center; justify-content: center; font-size: 20px; background: rgba(232, 182, 76, 0.08); z-index: 9;
  pointer-events: none;
}
#busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center;
  justify-content: center; background: rgba(8, 9, 11, 0.55); z-index: 10; font-size: 15px;
}
.spin {
  width: 38px; height: 38px; border: 3px solid #3a3e47; border-top-color: var(--acc); border-radius: 50%;
  animation: sp 0.8s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

/* ================================================================ telas menores */
@media (max-width: 1260px) {
  .brand b, #bFrame span, #bExport span { display: none; }
}
@media (max-width: 980px) {
  #top { gap: 6px; padding-right: 8px; }
  .tb span { display: none; }
  .tb { padding: 0; }
  #hint { display: none; }
}
@media (max-width: 760px) {
  .tool { width: 54px; height: 54px; font-size: 10px; }
  .tool svg.ui { width: 22px; height: 22px; }
  #stonePanel { left: calc(80px + var(--safe-l)); width: auto; right: 10px; }
  #pavePanel, #outliner { width: auto; left: 80px; }
  .hb.wide span { display: none; }
}
