:root {
  color-scheme: dark;
  --bg: #141412;
  --bg-deep: #080807;
  --engnata-dark: #1e1e1e;
  --engnata-light: #4e7262;
  --engnata-accent-light: #2d9fa3;
  --engnata-accent-dark: #5cc9d0;
  --wine: #7d2535;
  --body: #1e1e1b;
  --body-edge: #0b0b0a;
  --plate: #2a2b27;
  --metal: #c6c9c6;
  --metal-dark: #8e948f;
  --key: #171816;
  --key-top: #343530;
  --key-face: #0d0e0d;
  --key-text: #f3f2ed;
  --gold: #f2c64d;
  --blue: #68c7e5;
  --red: #c84242;
  --lcd: #b4c989;
  --lcd-dark: #26301c;
  --line: rgba(255, 255, 255, 0.18);
  --shadow: rgba(0, 0, 0, 0.48);
  --radius: 28px;
  --register-label-width: 5ch;
  --register-value-width: 17ch;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

@font-face {
  font-family: "DSEG7ClassicMini";
  src: url("./assets/fonts/DSEG7ClassicMini-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(92, 201, 208, 0.2), transparent 34%),
    radial-gradient(circle at 82% 92%, rgba(45, 159, 163, 0.24), transparent 34%),
    linear-gradient(135deg, var(--engnata-dark) 0%, #2f4f45 48%, var(--engnata-light) 100%);
  color: #f5f3ec;
}

button {
  font: inherit;
}

a {
  color: #b9e5f1;
}

.workspace {
  width: fit-content;
  max-width: 100%;
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(680px, 1320px) max-content;
  gap: 24px;
  align-items: center;
  padding: 24px;
}

.calculator-stage {
  min-width: 0;
  position: relative;
}

/* Barra de ferramentas dedicada ACIMA da calculadora (fora do skin dela). Cada
   ferramenta é um botão com ícone + título + descrição do que faz. */
.stage-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: min(100%, 1320px);
  margin: 0 auto 16px;
}

.stage-tool {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.06), transparent 60%),
    rgba(17, 18, 16, 0.72);
  color: #f8f7f1;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.stage-tool:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.34);
}

.stage-tool:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.75);
  outline-offset: 2px;
}

.stage-tool-icon {
  font-size: 1.5rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.stage-tool-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.stage-tool-title {
  font-weight: 700;
  font-size: 0.95rem;
}

/* Modo Segurar ativo: borda/halo dourado no botão. */
.hold-tool[aria-pressed="true"] {
  border-color: rgba(242, 198, 77, 0.9);
  background:
    linear-gradient(160deg, rgba(242, 198, 77, 0.18), transparent 60%),
    rgba(17, 18, 16, 0.82);
  box-shadow: 0 0 0 1px rgba(242, 198, 77, 0.5), 0 10px 22px rgba(0, 0, 0, 0.28);
}

.hold-tool[aria-pressed="true"] .stage-tool-icon {
  filter: drop-shadow(0 0 6px rgba(242, 198, 77, 0.85));
}

.utility-button,
.mode-switch button {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(17, 18, 16, 0.72);
  color: #f8f7f1;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.utility-button {
  color: #ffd9d9;
  border-color: rgba(224, 91, 91, 0.58);
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  touch-action: manipulation;
}

.mode-switch button {
  min-width: 72px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.mode-switch button[aria-pressed="true"] {
  background: linear-gradient(#ecefec, #aeb5af);
  color: #10110f;
}

.calculator {
  min-width: 0;
  width: min(100%, 1320px);
  aspect-ratio: 3313 / 2030;
  margin: 0 auto;
  padding: 22px;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.08), transparent 32%),
    linear-gradient(#30312d, #121311);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 26px 80px rgba(0, 0, 0, 0.46),
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    inset 0 -10px 20px rgba(0, 0, 0, 0.42);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.faceplate {
  min-width: 0;
  width: 100%;
  height: 100%;
  border-radius: 22px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07), transparent 26%, rgba(0, 0, 0, 0.24) 100%),
    var(--plate);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4.2% 4.6% 4.7%;
  display: grid;
  grid-template-rows: 31% 1fr;
  gap: 4.4%;
  overflow: hidden;
}

.display-strip {
  min-width: 0;
  display: grid;
  grid-template-columns: 41% 1fr;
  align-items: center;
  gap: 3.6%;
  min-height: 0;
}

.brand-block {
  min-width: 0;
  align-self: stretch;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  column-gap: 10px;
  padding: 2.8% 0;
  color: var(--metal);
}

.hp-mark {
  grid-row: 1 / 3;
  width: 54px;
  height: 54px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(#e7e9e7, #9da49f);
  color: #161715;
  font-weight: 900;
  font-style: italic;
  font-size: 1.2rem;
  line-height: 1;
  box-shadow: inset 0 1px 0 #fff, 0 8px 16px rgba(0, 0, 0, 0.24);
}

.model-name {
  align-self: end;
  font-size: 1.6rem;
  font-weight: 650;
  line-height: 1;
  text-transform: lowercase;
}

.model-kind {
  align-self: start;
  margin-top: 4px;
  color: #aeb5b0;
  font-size: 0.8rem;
  text-transform: lowercase;
}

.lcd {
  min-width: 0;
  height: 78%;
  min-height: 96px;
  align-self: center;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 12px 18px 10px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.03) 22%, rgba(0, 0, 0, 0.16)),
    var(--lcd);
  border: 4px solid #0d100c;
  box-shadow:
    inset 0 2px 12px rgba(0, 0, 0, 0.32),
    0 8px 0 rgba(0, 0, 0, 0.26);
  color: var(--lcd-dark);
}

.lcd-indicators {
  min-height: 19px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(38, 48, 28, 0.78);
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  font-size: 0.76rem;
  font-weight: 800;
}

/* Anunciadores vazios não ocupam espaço (a 12C só acende os ativos). */
.lcd-indicators span:empty {
  display: none;
}

#cIndicator {
  color: #0e6278;
}

#shiftIndicator.shift-f {
  color: #785a00;
}

#shiftIndicator.shift-g {
  color: #0e6278;
}

#display {
  align-self: center;
  justify-self: start;
  max-width: 100%;
  /* line-height + padding dão folga vertical para o rabinho da vírgula (descendente
     da fonte DSEG7) não ser cortado pelo recorte horizontal de números longos. */
  overflow: hidden;
  color: #151b11;
  font-family: "DSEG7ClassicMini", "Consolas", "Lucida Console", ui-monospace, monospace;
  font-size: clamp(0.82rem, var(--display-font-size, 2.95rem), 2.95rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1.18;
  padding-bottom: 0.1em;
  text-align: left;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.24);
  white-space: nowrap;
}

.keyboard {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 2.1%;
  min-height: 0;
  touch-action: manipulation;
}

.key {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: 23% 1fr 23%;
  align-items: center;
  justify-items: center;
  border: 0;
  border-radius: 8px;
  padding: 5px 3px 4px;
  background:
    linear-gradient(#53554f 0 7%, transparent 7%),
    linear-gradient(#2b2d29, #111210 55%, #070807);
  color: var(--key-text);
  box-shadow:
    0 8px 0 #050605,
    0 12px 18px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.key::after {
  content: "";
  position: absolute;
  inset: 9% 10% auto;
  height: 16%;
  border-radius: 999px;
  background: linear-gradient(rgba(255, 255, 255, 0.22), transparent);
  opacity: 0.75;
  pointer-events: none;
}

.key:active,
.key.is-pressed,
.key.is-held {
  transform: translateY(5px);
  box-shadow:
    0 3px 0 #050605,
    0 8px 12px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.key:focus-visible,
.utility-button:focus-visible,
.mode-switch button:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.75);
  outline-offset: 3px;
}

.key .shift-top,
.key .shift-bottom {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: 0.55rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.key .shift-top {
  color: var(--gold);
}

.key .shift-bottom {
  color: var(--blue);
}

.key .main-label {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: 1.28rem;
  font-weight: 780;
  line-height: 1;
  white-space: nowrap;
}

.key[data-tone="number"] {
  background:
    linear-gradient(#f0f1ed 0 9%, transparent 9%),
    linear-gradient(#d8dad5, #8f9691 56%, #4a4f4b);
  color: #111310;
  box-shadow:
    0 8px 0 #3b3f3c,
    0 12px 18px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 #fff;
}

.key[data-tone="operator"] .main-label {
  color: #ffffff;
}

.key[data-tone="gold"] {
  color: #211a05;
  background:
    linear-gradient(#fff4bf 0 9%, transparent 9%),
    linear-gradient(#f5cc55, #b88620 58%, #6a4b0f);
  box-shadow:
    0 8px 0 #493508,
    0 12px 18px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.74);
}

.key[data-tone="blue"] {
  color: #06212a;
  background:
    linear-gradient(#daf6ff 0 9%, transparent 9%),
    linear-gradient(#80d8ef, #23819b 58%, #0f4758);
  box-shadow:
    0 8px 0 #0a303c,
    0 12px 18px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.68);
}

.key[data-tone="danger"] {
  background:
    linear-gradient(#ffb8b8 0 9%, transparent 9%),
    linear-gradient(#c94b4b, #7a1f26 58%, #421013);
}

.register-panel {
  min-width: 0;
  width: max-content;
  display: grid;
  gap: 16px;
  align-content: center;
  justify-self: start;
}

.panel-block {
  min-width: 0;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(14, 15, 13, 0.68);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(12px);
}

.panel-block {
  padding: 14px;
}

.panel-title {
  margin-bottom: 10px;
  color: #dfe2dc;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.register-grid {
  display: grid;
  gap: 8px;
  margin: 0;
}

.register-grid div {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(var(--register-label-width), max-content) minmax(
      var(--register-value-width),
      max-content
    );
  align-items: center;
  gap: 10px;
  min-height: 34px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.register-grid div:last-child {
  border-bottom: 0;
}

.register-grid dt,
.register-grid dd {
  margin: 0;
}

.register-grid dt {
  color: #adb5ae;
  font-weight: 850;
}

.register-grid dd {
  min-width: var(--register-value-width);
  overflow: visible;
  color: #f5f3ec;
  font-family: "Consolas", "Lucida Console", ui-monospace, monospace;
  font-size: 0.95rem;
  text-align: right;
  text-overflow: clip;
  white-space: nowrap;
}

@media (max-width: 1080px) {
  .workspace {
    width: 100%;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .register-panel {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    justify-self: stretch;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 12px;
    gap: 16px;
    overflow-x: hidden;
  }

  .calculator-stage,
  .stage-controls,
  .calculator,
  .register-panel {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }

  .stage-controls {
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
  }

  .mode-switch button {
    min-width: 58px;
  }

  .calculator {
    padding: 10px;
    border-radius: 18px;
  }

  .faceplate {
    border-radius: 14px;
    padding: 3.6% 3.8% 4.4%;
    gap: 3.6%;
  }

  .display-strip {
    grid-template-columns: 38% 1fr;
  }

  .hp-mark {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
  }

  .model-name {
    font-size: 0.86rem;
  }

  .model-kind {
    display: none;
  }

  .lcd {
    min-height: 58px;
    padding: 6px 8px;
    border-width: 2px;
  }

  .lcd-indicators {
    min-height: 13px;
    gap: 5px;
    font-size: 0.56rem;
  }

  #display {
    font-size: 1.55rem;
  }

  .keyboard {
    gap: 1.5%;
  }

  .key {
    border-radius: 5px;
    padding: 2px 1px;
    box-shadow:
      0 4px 0 #050605,
      0 8px 12px rgba(0, 0, 0, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .key:active,
  .key.is-pressed,
  .key.is-held {
    transform: translateY(3px);
    box-shadow:
      0 1px 0 #050605,
      0 5px 8px rgba(0, 0, 0, 0.24),
      inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .key .shift-top,
  .key .shift-bottom {
    font-size: 0.38rem;
  }

  .key .main-label {
    font-size: 0.74rem;
  }

  .register-panel {
    grid-template-columns: 1fr;
  }

  .utility-button,
  .mode-switch button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.8rem;
  }
}

@media (max-width: 520px) {
  .key .shift-top,
  .key .shift-bottom {
    font-size: 0.34rem;
  }

  .key .main-label {
    font-size: 0.6rem;
  }
}

@media (orientation: landscape) and (max-height: 540px) and (max-width: 980px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .workspace {
    width: 100vw;
    height: 100svh;
    min-height: 100svh;
    padding: 8px;
    grid-template-columns: 1fr;
    place-items: center;
    gap: 0;
    overflow: hidden;
  }

  .calculator-stage {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
  }

  /* Em paisagem de celular o espaço vertical é curto: a barra de ferramentas
     vai para a LATERAL ESQUERDA da calculadora (coluna de ícones, sem rótulos),
     liberando altura para ver a calculadora inteira sem rolagem. */
  .calculator-stage {
    grid-template-columns: auto 1fr;
    grid-template-rows: 1fr;
    align-content: center;
    gap: 8px;
  }

  .stage-controls {
    display: flex;
    flex-direction: column;
    width: auto;
    margin: 0;
    gap: 8px;
  }

  .stage-tool {
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 8px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  /* Em paisagem só o ícone aparece; o título vira tooltip via aria-label. */
  .stage-tool-text {
    display: none;
  }

  .stage-tool-icon {
    font-size: 1.2rem;
  }

  .mode-switch {
    opacity: 0.94;
  }

  .mode-switch button {
    min-width: 52px;
    min-height: 30px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .calculator {
    width: var(--phone-landscape-calc-width, min(100%, 680px));
    max-width: calc(100vw - 16px);
    max-height: calc(100svh - 62px);
    padding: 8px;
    border-radius: 14px;
  }

  .faceplate {
    border-radius: 10px;
    padding: 3.2% 3.5% 4%;
    gap: 3.5%;
  }

  .display-strip {
    grid-template-columns: 39% 1fr;
  }

  .hp-mark {
    width: 32px;
    height: 32px;
    font-size: 0.78rem;
  }

  .model-name {
    font-size: 0.82rem;
  }

  .model-kind {
    display: none;
  }

  .lcd {
    min-height: 52px;
    padding: 5px 8px;
    border-width: 2px;
  }

  .lcd-indicators {
    min-height: 13px;
    gap: 5px;
    font-size: 0.56rem;
  }

  #display {
    font-size: clamp(1.2rem, 5svh, 1.9rem);
  }

  .keyboard {
    gap: 1.35%;
  }

  .key {
    border-radius: 5px;
    padding: 2px 1px;
    box-shadow:
      0 4px 0 #050605,
      0 8px 12px rgba(0, 0, 0, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .key:active,
  .key.is-pressed,
  .key.is-held {
    transform: translateY(3px);
    box-shadow:
      0 1px 0 #050605,
      0 5px 8px rgba(0, 0, 0, 0.24),
      inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .key .shift-top,
  .key .shift-bottom {
    font-size: clamp(0.28rem, 1.6svh, 0.44rem);
  }

  .key .main-label {
    font-size: clamp(0.52rem, 3svh, 0.9rem);
  }

  .register-panel {
    display: none;
  }
}

/* ---- Modo tela cheia ----
   Vale para a Fullscreen API real (body.is-fullscreen) E para o fallback CSS
   (body.fake-fullscreen, quando o navegador bloqueia a API). Esconde os painéis
   laterais e dá toda a viewport para a calculadora. */
body.is-fullscreen .register-panel,
body.fake-fullscreen .register-panel {
  display: none !important;
}

body.fake-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #1c2620;
  overflow: hidden;
}

body.is-fullscreen .workspace,
body.fake-fullscreen .workspace {
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  max-width: none;
  grid-template-columns: 1fr;
  padding: 8px;
}

/* Botão "Tela cheia" ganha destaque enquanto ativo (mesmo padrão do Segurar). */
.fullscreen-tool[aria-pressed="true"] {
  border-color: rgba(104, 199, 229, 0.8);
  background:
    linear-gradient(160deg, rgba(104, 199, 229, 0.18), transparent 60%),
    rgba(17, 18, 16, 0.82);
}

@media (max-width: 420px) {
  .workspace {
    padding: 8px;
  }

  .calculator-stage,
  .stage-controls,
  .calculator,
  .register-panel {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
  }

  .display-strip {
    gap: 2.2%;
  }

  .brand-block {
    column-gap: 5px;
  }

  .hp-mark {
    width: 28px;
    height: 28px;
    font-size: 0.72rem;
  }

  .model-name {
    font-size: 0.68rem;
  }

  #display {
    font-size: 1.22rem;
  }

  .key .shift-top,
  .key .shift-bottom {
    font-size: 0.31rem;
  }

  .key .main-label {
    font-size: 0.58rem;
  }
}

/* Photo skin based on the local "imagem calculadora.png" asset. */
.calculator {
  position: relative;
  container-type: inline-size;
  aspect-ratio: 1604 / 981;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.1), transparent 22%),
    url("./imagem calculadora.png") center / contain no-repeat;
  box-shadow:
    0 26px 80px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.faceplate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  overflow: hidden;
}

.display-strip {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
}

.brand-block {
  display: none;
}

.lcd {
  position: absolute;
  left: 17.832%;
  top: 7.695%;
  width: 47.459%;
  height: 16.636%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 26% 1fr;
  padding: 1.05% 2.15% 0.85%;
  border: 0;
  border-radius: 7px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 18%, rgba(0, 0, 0, 0.08)),
    #adbaa0;
  box-shadow:
    inset 0 2px 7px rgba(0, 0, 0, 0.28),
    inset 0 -1px 0 rgba(255, 255, 255, 0.32);
  color: #050805;
  pointer-events: none;
}

.lcd-indicators {
  min-height: 0;
  gap: 0.9cqw;
  font-size: clamp(0.42rem, 1.08cqw, 0.95rem);
  font-weight: 800;
  color: rgba(10, 24, 12, 0.8);
}

#display {
  color: #030503;
  font-family: "DSEG7ClassicMini", "Consolas", "Lucida Console", ui-monospace, monospace;
  font-size: clamp(0.82rem, var(--display-font-size, 4.85cqw), 3.95rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  /* folga vertical para o rabinho da vírgula (descendente da DSEG7) não ser cortado */
  line-height: 1.08;
  padding-bottom: 0.12em;
  letter-spacing: 0.01em;
  justify-self: start;
  text-align: left;
  text-shadow: none;
}

.keyboard {
  position: absolute;
  inset: 0;
  display: block;
  min-width: 0;
  min-height: 0;
}

.keyboard .key,
.keyboard .key[data-tone],
.keyboard .key[data-tone="gold"],
.keyboard .key[data-tone="blue"],
.keyboard .key[data-tone="danger"],
.keyboard .key[data-tone="number"] {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  height: calc(var(--h) * 1%);
  display: block;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: rgba(104, 199, 229, 0);
  box-shadow: none;
  color: transparent;
  transform: none;
}

.keyboard .key::after {
  display: none;
}

.keyboard .key span {
  display: none;
}

.keyboard .key:active,
.keyboard .key.is-pressed,
.keyboard .key.is-held {
  transform: none;
  background: rgba(104, 199, 229, 0.22);
  box-shadow:
    inset 0 0 0 2px rgba(219, 246, 255, 0.6),
    0 0 16px rgba(104, 199, 229, 0.22);
}

.keyboard .key.is-held {
  background: rgba(104, 199, 229, 0.3);
  box-shadow:
    inset 0 0 0 2px rgba(219, 246, 255, 0.78),
    0 0 20px rgba(104, 199, 229, 0.3);
}

.keyboard .key:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.8);
  outline-offset: 2px;
}

@media (orientation: landscape) and (max-height: 540px) and (max-width: 980px) {
  .calculator {
    width: var(--phone-landscape-calc-width, min(100%, 680px));
    max-width: calc(100vw - 16px);
    max-height: calc(100svh - 16px);
    padding: 0;
    border-radius: 6px;
  }
}

/* ---- Ícones sobre a calculadora: manual (📖) e Segurar (🔒) ---- */
/* Apenas o ícone, sem caixa/borda, fixados nos cantos superiores da calc. */
/* (Os antigos ícones flutuantes .stage-icon sobre a calculadora foram
   substituídos pela barra de ferramentas .stage-tool acima dela.) */

/* Enquanto o modo Segurar está ligado, realça o teclado (toque p/ travar). */
body.latch-mode .keyboard {
  outline: 2px dashed rgba(242, 198, 77, 0.6);
  outline-offset: 6px;
  border-radius: 8px;
}

/* ---- Visualizador do guia do usuário (PDF) ---- */

/* O guia abre DOCADO, sem cobrir a calculadora (dá pra ler enquanto opera).
   Padrão (telas pequenas): ocupa a tela inteira; docagem por orientação abaixo. */
.guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
}

.guide-overlay[hidden] {
  display: none;
}

.guide-modal {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--plate);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.guide-modal-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: linear-gradient(#30312d, #121311);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.guide-modal-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 800;
}

.guide-modal-open {
  flex: none;
  white-space: nowrap;
  color: #b9e5f1;
  font-size: 0.82rem;
  text-decoration: none;
}

.guide-modal-open:hover {
  text-decoration: underline;
}

.guide-modal-close {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(17, 18, 16, 0.72);
  color: #ffd9d9;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.guide-modal-close:hover {
  background: rgba(200, 66, 66, 0.32);
}

.guide-modal-body {
  flex: 1;
  min-height: 0;
  background: #20211d;
}

.guide-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.guide-button:focus-visible,
.guide-modal-open:focus-visible,
.guide-modal-close:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.75);
  outline-offset: 2px;
}

/* Divisória arrastável entre a calculadora e o guia. Escondida na tela cheia
   (celular); posicionada por orientação nas media queries abaixo. */
.guide-resizer {
  display: none;
  position: absolute;
  z-index: 3;
  background: transparent;
  touch-action: none;
}

.guide-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
}

.guide-resizer:hover,
.guide-resizer:focus-visible {
  background: rgba(104, 199, 229, 0.28);
  outline: none;
}

body.guide-resizing {
  user-select: none;
}

/* durante o arraste, o iframe não pode capturar o ponteiro */
body.guide-resizing .guide-frame {
  pointer-events: none;
}

/* PC LARGO (paisagem): guia DOCADO À DIREITA; a calculadora fica à esquerda.
   Largura do guia e padding da calc seguem --guide-w (divisória horizontal). */
@media (min-width: 900px) and (min-height: 560px) and (orientation: landscape) {
  .guide-overlay {
    inset: 0 0 0 auto;
    width: var(--guide-w, clamp(340px, calc(100vw - 600px), 86vw));
    border-left: 1px solid rgba(255, 255, 255, 0.18);
  }

  body.guide-open {
    padding-right: var(--guide-w, clamp(340px, calc(100vw - 600px), 86vw));
  }

  /* área da esquerda em coluna única (calc + painéis empilhados), preenchendo
     a largura definida pela divisória. */
  body.guide-open .workspace {
    grid-template-columns: 1fr;
    width: 100%;
    justify-items: center;
    align-content: start;
  }

  body.guide-open .calculator-stage,
  body.guide-open .register-panel {
    width: 100%;
    max-width: 100%;
  }

  body.guide-open .register-panel {
    grid-template-columns: 1fr;
    justify-self: stretch;
  }

  .guide-resizer {
    display: block;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 14px;
    cursor: col-resize;
  }

  .guide-resizer::before {
    width: 4px;
    height: 46px;
  }

  body.guide-resizing {
    cursor: col-resize;
  }
}

/* PC ALTO (retrato): guia DOCADO EMBAIXO; a calculadora fica em cima.
   Altura do guia e padding da calc seguem --guide-h (divisória vertical). */
@media (min-width: 700px) and (min-height: 760px) and (orientation: portrait) {
  .guide-overlay {
    inset: auto 0 0 0;
    height: var(--guide-h, 46vh);
    border-top: 1px solid rgba(255, 255, 255, 0.18);
  }

  body.guide-open {
    padding-bottom: var(--guide-h, 46vh);
  }

  .guide-resizer {
    display: block;
    top: -4px;
    left: 0;
    right: 0;
    height: 14px;
    cursor: row-resize;
  }

  .guide-resizer::before {
    width: 46px;
    height: 4px;
  }

  body.guide-resizing {
    cursor: row-resize;
  }
}

/* ---- Painéis colapsáveis (TVM, Estado) ---- */
.panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #dfe2dc;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}

.panel-chevron {
  flex: none;
  font-size: 0.7rem;
  opacity: 0.75;
  transition: transform 0.18s ease;
}

.panel-block.is-collapsed .panel-toggle {
  margin-bottom: 0;
}

.panel-block.is-collapsed .panel-chevron {
  transform: rotate(-90deg);
}

.panel-block.is-collapsed .register-grid {
  display: none;
}

.panel-toggle:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.75);
  outline-offset: 2px;
}

/* ====================================================================== */
/* MOLDURA DO PORTFÓLIO — idioma (PT/IT), tema (claro/escuro), rodapé/home  */
/* Aparece só no desktop/tablet; os blocos MOBILE abaixo ocultam tudo isto  */
/* para a calculadora ocupar a tela inteira no celular.                    */
/* ====================================================================== */

/* Coluna: barra de idioma no topo, calculadora no meio, rodapé embaixo —
   cabe em 100svh sem rolagem no desktop. */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.workspace {
  flex: 1 1 auto;
  min-height: 0;
}

/* Seletor de idioma + botão de tema (mesmo visual dos demais apps) */
.language-selector {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 12px auto 4px;
  width: fit-content;
  max-width: calc(100vw - 16px);
  z-index: 1400;
}

.lang-btn,
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-width: 60px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
  color: #f5f3ec;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  touch-action: manipulation;
}

.lang-btn:hover,
.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.lang-btn:focus-visible,
.theme-toggle-btn:focus-visible {
  outline: 3px solid rgba(104, 199, 229, 0.8);
  outline-offset: 2px;
}

.lang-btn.active {
  background: #f5f3ec;
  color: #1e2a23;
  border-color: #f5f3ec;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.lang-btn .flag {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.lang-btn .flag svg {
  display: block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.lang-btn .lang-text {
  font-weight: 600;
}

/* Rodapé com botão home (substitui o botão flutuante padrão do portfólio) */
.br12c-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom, 10px));
  color: rgba(245, 243, 236, 0.78);
  font-size: 0.82rem;
}

.br12c-footer .home-button-fixed {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e6f6f7 0%, #c2e7e9 100%);
  border: 1px solid rgba(45, 159, 163, 0.35);
  box-shadow: 0 6px 16px rgba(45, 159, 163, 0.28);
  color: #1e7e82;
  text-decoration: none;
  transition: transform 0.2s ease;
}

.br12c-footer .home-button-fixed:hover {
  transform: scale(1.08);
}

.br12c-footer .home-button-fixed svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.br12c-footer-text {
  margin: 0;
}

/* ---- Tema ESCURO (data-theme="dark" no <html>) ---- */
html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 18% 8%, rgba(45, 90, 90, 0.18), transparent 40%),
    radial-gradient(circle at 82% 92%, rgba(30, 70, 70, 0.18), transparent 40%),
    linear-gradient(135deg, #0c0f0e 0%, #11201a 55%, #0a0d0c 100%);
}

html[data-theme="dark"] .lang-btn,
html[data-theme="dark"] .theme-toggle-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #e6e6e6;
}

html[data-theme="dark"] .lang-btn.active {
  background: #5cc9d0;
  color: #06212a;
  border-color: #5cc9d0;
}

html[data-theme="dark"] .br12c-footer .home-button-fixed {
  background: linear-gradient(135deg, #1b3b3d 0%, #14282a 100%);
  border-color: rgba(92, 201, 208, 0.4);
  color: #9fe7ec;
}

/* Skin ESCURO da calculadora (paisagem/desktop): troca a foto pela versão dark
   e escurece o vidro do LCD para casar com ela. Os dígitos seguem escuros, como
   na própria foto. O data-theme é definido por theme.js a partir da preferência
   salva do portfólio (engnata_theme_mode) — vale também no celular, onde não há
   botão: a calculadora respeita o tema escolhido na home ou em outros apps. */
html[data-theme="dark"] .calculator {
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.05), transparent 22%),
    url("./imagem calculadora dark mode.png") center / contain no-repeat;
}

/* LCD escuro "negativo" (mesmas cores da skin vertical dark): fundo quase preto
   e dígitos/anunciadores ciano. Vale para a paisagem (desktop e celular deitado);
   o bloco retrato abaixo repete as mesmas cores. */
html[data-theme="dark"] .lcd {
  background:
    linear-gradient(90deg, rgba(22, 188, 194, 0.06), transparent 20%, rgba(0, 0, 0, 0.32)),
    #06120f;
}

html[data-theme="dark"] #display {
  color: #16bcc2;
  text-shadow: 0 0 6px rgba(22, 188, 194, 0.4);
}

html[data-theme="dark"] .lcd-indicators {
  color: #16bcc2;
}

/* ====================================================================== */
/* SKIN RETRATO — CELULAR NA VERTICAL                                      */
/* Em telas de celular em pé, troca a foto landscape pela vertical         */
/* (imagem calculadora vertical.png), remapeia as áreas de toque para as   */
/* coordenadas retrato (--px/--py/--pw/--ph, geradas em buildSkinKeys) e   */
/* dimensiona a calculadora para preencher a tela (contain-fit) SEM barras  */
/* de rolagem. Oculta as tabelas e TODA a barra de ferramentas (Segurar,   */
/* Guia, Testes e Tela cheia) — ver também o bloco de PAISAGEM abaixo.     */
/* ====================================================================== */
@media (orientation: portrait) and (max-width: 600px) {
  /* trava a rolagem: a calculadora sempre cabe inteira na viewport */
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .workspace {
    grid-template-columns: 1fr;
    width: 100vw;
    max-width: 100vw;
    height: 100svh;
    min-height: 0;
    gap: 0;
    padding: 0;
    place-items: center;
    align-content: center;
    overflow: hidden;
  }

  /* esconde as tabelas (Pilha / TVM / Estado) e a moldura do portfólio
     (idioma, tema e rodapé/home) — calculadora ocupa a tela inteira */
  .register-panel,
  .language-selector,
  .br12c-footer {
    display: none;
  }

  /* esconde a barra inteira: Modo Segurar, Guia, Sistema de testes e Tela cheia */
  .stage-controls {
    display: none;
  }

  .calculator-stage {
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
  }

  /* calculadora: foto vertical em contain-fit. width preenche a largura, mas
     nunca passa da altura disponível (100svh) — sem estouro em nenhum eixo. */
  .calculator {
    aspect-ratio: 910 / 1728;
    width: min(100vw, calc(100svh * 910 / 1728));
    height: auto;
    max-width: 100vw;
    max-height: 100svh;
    border-radius: 0;
    background:
      linear-gradient(140deg, rgba(255, 255, 255, 0.06), transparent 22%),
      url("./imagem calculadora vertical.png") center / contain no-repeat;
  }

  /* LCD: caixa verde no topo da foto vertical (medida sobre a imagem) */
  .lcd {
    left: 7%;
    top: 3.6%;
    width: 85.6%;
    height: 10.2%;
    border-radius: 5px;
    grid-template-rows: 30% 1fr;
    padding: 0.7% 2.4% 0.6%;
  }

  /* Skin ESCURO no retrato: foto vertical dark + LCD "negativo" (fundo quase
     preto, dígitos ciano), como na imagem. Vence as regras dark de paisagem por
     ordem de origem (este bloco vem depois). */
  html[data-theme="dark"] .calculator {
    background:
      linear-gradient(140deg, rgba(255, 255, 255, 0.04), transparent 22%),
      url("./imagem calculadora vertical dark mode.png") center / contain no-repeat;
  }

  html[data-theme="dark"] .lcd {
    background:
      linear-gradient(90deg, rgba(22, 188, 194, 0.06), transparent 20%, rgba(0, 0, 0, 0.32)),
      #06120f;
  }

  html[data-theme="dark"] #display {
    color: #16bcc2;
    text-shadow: 0 0 6px rgba(22, 188, 194, 0.4);
  }

  html[data-theme="dark"] .lcd-indicators {
    color: #16bcc2;
  }

  /* teclas: coordenadas RETRATO. Replica o grupo de seletores da skin foto
     para empatar especificidade e vencer por ordem de origem. */
  .keyboard .key,
  .keyboard .key[data-tone],
  .keyboard .key[data-tone="gold"],
  .keyboard .key[data-tone="blue"],
  .keyboard .key[data-tone="danger"],
  .keyboard .key[data-tone="number"] {
    left: calc(var(--px) * 1%);
    top: calc(var(--py) * 1%);
    width: calc(var(--pw) * 1%);
    height: calc(var(--ph) * 1%);
  }

  /* Alinhamento fino das áreas de toque às fotos retrato. O grid de overlays
     (coordenadas --px/--py em buildSkinKeys, que é fonte de verdade dos testes —
     NÃO mexer lá) é ligeiramente mais ALTO que o teclado desenhado na foto, então
     o realce de toque/foco (a "máscara") fica acima dos botões. Correção apenas
     VISUAL: comprime o teclado no eixo Y ancorando na linha de baixo (que já bate),
     por tema — a foto dark desenha o teclado um pouco menor que a light. */
  .keyboard {
    transform-origin: 50% 93%;
    transform: scaleY(0.978);
  }

  html[data-theme="dark"] .keyboard {
    transform: scaleY(0.957);
  }
}

/* ====================================================================== */
/* PAISAGEM MOBILE — calculadora preenchendo a tela, sem barra nem tabelas */
/* Mesma skin landscape, mas: oculta TODA a barra de ferramentas (Segurar, */
/* Guia, Testes, Tela cheia) e as tabelas, e faz a calculadora redimensionar*/
/* em contain-fit ocupando o máximo possível SEM rolagem (nenhum eixo).    */
/* Vem por último para vencer os blocos de paisagem anteriores (707/1094). */
/* ====================================================================== */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 980px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .workspace {
    grid-template-columns: 1fr;
    width: 100vw;
    height: 100svh;
    min-height: 0;
    gap: 0;
    padding: 0;
    place-items: center;
    overflow: hidden;
  }

  /* esconde as tabelas (Pilha / TVM / Estado) e a moldura do portfólio
     (idioma, tema e rodapé/home) — calculadora ocupa a tela inteira */
  .register-panel,
  .language-selector,
  .br12c-footer {
    display: none;
  }

  /* esconde a barra inteira: Modo Segurar, Guia, Sistema de testes e Tela cheia */
  .stage-controls {
    display: none;
  }

  /* sem a barra lateral, a calculadora usa o palco inteiro */
  .calculator-stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    width: 100%;
    height: 100%;
    gap: 0;
    place-items: center;
  }

  /* contain-fit: em paisagem a altura é o limite — preenche 100svh e fica
     centralizada na largura, sem estourar em nenhum eixo. */
  .calculator {
    aspect-ratio: 1604 / 981;
    width: min(100vw, calc(100svh * 1604 / 981));
    height: auto;
    max-width: 100vw;
    max-height: 100svh;
    padding: 0;
    border-radius: 0;
  }
}
