:root {
  color-scheme: dark;
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --shell: #4e4e4e;
  --display: #474747;
  --key: #797979;
  --key-hover: #858585;
  --line: #505050;
  --text: #f7f7f7;
  --muted: #d0d0d0;
  --orange: #ff9900;
  --mint: #c3ebd8;
}

* { box-sizing: border-box; }

html { min-width: 280px; min-height: 100%; background: #202020; }

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  margin: 0;
  background: #202020;
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid #ffd07a; outline-offset: 2px; }
[hidden] { display: none !important; }

.page {
  flex: 1 0 auto;
  min-height: calc(100vh - 46px);
  min-height: calc(100svh - 46px);
  display: grid;
  place-items: center;
  padding: 12px 8px;
}

.site-footer {
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  padding: 8px 12px;
  color: #aaa;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.site-footer a {
  color: #d0d0d0;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--orange);
  text-decoration: underline;
}

.page-content { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.calculator {
  width: min(364px, calc(100vw - 16px));
  height: min(539px, calc(100svh - 34px));
  min-height: 455px;
  display: grid;
  grid-template-rows: 48px 157px 60px minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--shell);
  border: 1px solid #5a5a5a;
  box-shadow: 0 16px 46px #0008;
}

.calculator-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding: 0 9px 0 10px;
}

.brand { min-width: 0; display: flex; align-items: center; gap: 7px; }
.brand img { width: 26px; height: 26px; flex: 0 0 auto; object-fit: contain; }
.brand h1 { margin: 0; overflow: hidden; color: var(--text); font-size: 15px; font-weight: 700; letter-spacing: -.35px; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }

.header-button {
  min-width: 54px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 6px;
  border: 1px solid #777;
  border-radius: 0;
  background: #555;
  color: #f3f3f3;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.header-button:hover, .history-icon-button:hover { background: #686868; }
.header-button svg { width: 15px; height: 15px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.display {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin: 0 11px;
  padding: 8px 12px 7px;
  overflow: hidden;
  background: var(--display);
  border-bottom: 2px solid #3f3f3f;
}

.expression {
  width: 100%;
  min-width: 0;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: #dedede;
  font-size: 34px;
  font-weight: 400;
  letter-spacing: -.7px;
  line-height: 1.1;
  text-align: right;
  white-space: nowrap;
}

.expression::placeholder { color: #a0a0a0; opacity: .8; }
.expression:focus-visible { outline: 0; }

.result {
  width: 100%;
  min-width: 0;
  min-height: 68px;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
  color: #fff;
  font-size: 43px;
  font-weight: 700;
  letter-spacing: -1.3px;
  line-height: 1.08;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.vat-detail {
  min-height: 17px;
  margin: 1px 0 0;
  color: #d8d8d8;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  text-align: right;
}

.vat-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 7px 11px 6px; }

.vat-button {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 4px;
  border: 1px solid #969696;
  border-radius: 0;
  background: #797979;
  color: #f7f7f7;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.vat-button:hover { background: #858585; }
.vat-button span { color: var(--orange); font-size: 17px; font-weight: 600; }

.keypad {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 4px 11px 10px;
}

.key {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--key);
  color: #f7f7f7;
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
  transition: background-color .12s ease, transform .1s ease;
  user-select: none;
}

.key-clear-group { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(30px, .8fr); gap: 3px; }
.key-clear-group .key-clear { width: 100%; height: 100%; }
.key-backspace { display: grid; font-size: 20px; }

.key:hover { background: var(--key-hover); }
.key:active, .vat-button:active, .header-button:active { transform: scale(.97); }
.key-utility { font-size: 22px; }
.key-clear { color: var(--orange); font-size: 21px; font-weight: 600; }
.key-operation { background: var(--orange); color: #fff; font-size: 30px; font-weight: 400; }
.key-operation:hover, .key-equals:hover { background: #ffab26; }
.key-equals { background: var(--orange); color: #fff; font-size: 29px; font-weight: 600; }
.parentheses { font-size: 19px; letter-spacing: .3px; }

.keyboard-note { min-height: 14px; margin: 0; color: #9a9a9a; font-size: 10px; line-height: 1.3; text-align: center; }

.install-button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid #777;
  border-radius: 0;
  background: var(--shell);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}
.install-button:hover { border-color: var(--orange); }

.history-backdrop { position: fixed; z-index: 10; inset: 0; background: #0009; }

.history-panel {
  position: fixed;
  z-index: 11;
  inset: 50% auto auto 50%;
  width: min(366px, calc(100vw - 24px));
  height: min(560px, calc(100svh - 24px));
  min-height: 330px;
  display: flex;
  flex-direction: column;
  transform: translate(-50%, -50%);
  padding: 15px 16px 12px;
  overflow: hidden;
  background: var(--shell);
  border: 1px solid #707070;
  box-shadow: 0 18px 60px #000a;
}

.history-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 13px; border-bottom: 1px solid #666; }
.history-header h2 { margin: 0 0 3px; font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.history-count { margin: 0; color: #ccc; font-size: 10px; }
.history-tools { display: flex; gap: 5px; }
.history-icon-button { width: 33px; height: 33px; display: grid; place-items: center; padding: 0; border: 1px solid #777; border-radius: 0; background: #555; color: #eee; }
.history-icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

.history-list { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0; overflow: auto; list-style: none; overscroll-behavior: contain; }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 9px; padding: 12px 0 10px; border-bottom: 1px solid #656565; animation: reveal .16s ease both; }
.history-expression { min-width: 0; margin: 0; overflow-wrap: anywhere; color: #e0e0e0; font-size: 12px; line-height: 1.35; }
.history-result { margin: 3px 0 0; color: var(--mint); font-size: 19px; font-weight: 700; letter-spacing: -.2px; line-height: 1.15; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.history-meta { grid-column: 1; margin: 2px 0 0; color: #c0c0c0; font-size: 10px; line-height: 1.4; }
.history-actions { grid-column: 2; grid-row: 1 / span 3; align-self: center; display: flex; flex-direction: column; gap: 5px; }
.history-action { min-width: 66px; height: 29px; padding: 0 6px; border: 1px solid #898989; border-radius: 0; background: #5b5b5b; color: #f4f4f4; font-size: 10px; font-weight: 600; }
.history-action:hover { background: #707070; }
.history-action-insert { border-color: var(--orange); background: var(--orange); color: #fff; }
.history-action-insert:hover { background: #ffab26; }
.history-empty { margin: auto; padding: 20px 6px; color: #dedede; font-size: 13px; text-align: center; }

.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@keyframes reveal { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 340px) {
  .calculator { width: calc(100vw - 10px); height: calc(100svh - 18px); min-height: 430px; grid-template-rows: 45px 145px 55px minmax(0, 1fr) auto; }
  .calculator-header { padding-right: 6px; padding-left: 7px; gap: 3px; }
  .brand { gap: 4px; }
  .brand img { width: 22px; height: 22px; }
  .brand h1 { font-size: 13px; }
  .header-button { min-width: 48px; padding: 0 4px; font-size: 9px; }
  .vat-actions { gap: 4px; padding-right: 8px; padding-left: 8px; }
  .vat-button { gap: 4px; font-size: 11px; }
  .keypad { gap: 3px; padding-right: 8px; padding-left: 8px; }
}

@media (max-height: 510px) and (min-width: 341px) {
  .page { padding-top: 7px; padding-bottom: 7px; }
  .page-content { gap: 3px; }
  .calculator { height: calc(100svh - 24px); min-height: 0; grid-template-rows: 43px minmax(120px, 1fr) 52px minmax(190px, 1.5fr) auto; }
  .keyboard-note { display: none; }
}

@media (max-width: 600px) {
  .key-clear-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(26px, .8fr);
    gap: 3px;
  }
  .key-clear-group .key-backspace { display: grid; font-size: 20px; }
  .key-clear-group .key-clear { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Two saved comparison values revealed by an accordion directly below the keypad. */
.calculator.results-open { z-index: 12; }
.result-memory { min-width: 0; padding: 0 11px 8px; background: var(--shell); }
.result-accordion-toggle {
  width: 100%; height: 38px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; border: 1px solid #969696; border-radius: 0; background: var(--key);
  color: var(--text); font-size: 13px; font-weight: 500; text-align: left;
}
.result-accordion-toggle:hover { background: var(--key-hover); }
.result-accordion-toggle:active { transform: scale(.99); }
.result-accordion-icon { width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: var(--orange); stroke-width: 2; stroke-linecap: square; }
.result-plus-vertical { transition: opacity .2s ease; }
.result-memory.is-open .result-plus-vertical { opacity: 0; }
.result-memory-panel { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .26s ease, opacity .2s ease; }
.result-memory.is-open .result-memory-panel { grid-template-rows: 1fr; opacity: 1; }
.result-memory-inner { min-height: 0; overflow: hidden; }
.result-memory-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding-top: 5px; }
.result-slot { min-width: 0; display: flex; flex-direction: column; padding: 6px; border: 1px solid #969696; background: var(--key); }
.result-slot-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.result-slot-action { min-width: 0; height: 25px; padding: 0 3px; border: 1px solid #9a9a9a; border-radius: 0; background: #686868; color: var(--text); font-size: 10px; font-weight: 600; white-space: nowrap; }
.result-slot-save { border-color: #e89722; background: var(--orange); color: #fff; }
.result-slot-action:hover:not(:disabled) { filter: brightness(1.1); }
.result-slot-insert:disabled { cursor: default; opacity: .55; }
.result-slot-value { display: block; min-width: 0; margin-top: 4px; overflow: hidden; color: #fff; font-size: 22px; font-weight: 700; letter-spacing: -.4px; line-height: 1.1; text-align: center; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.result-slot-expression { display: block; min-width: 0; margin-top: 2px; overflow: hidden; color: #eee; font-size: 10px; line-height: 1.3; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 340px) {
  .calculator.results-open { z-index: 12; }
  .result-memory { padding-right: 8px; padding-left: 8px; }
  .result-memory-grid { gap: 4px; }
  .result-slot { padding: 5px; }
  .result-slot-actions { gap: 3px; }
  .result-slot-action { padding-right: 1px; padding-left: 1px; font-size: 9px; }
}
@media (max-height: 510px) and (min-width: 341px) {
  .calculator.results-open { z-index: 12; }
}
/* The comparison accordion overlays below the calculator without moving its keys. */
.calculator { position: relative; overflow: visible; }
.calculator.results-open { z-index: 12; }
.result-memory { position: relative; z-index: 1; padding-bottom: 0; }
.result-memory.is-open { z-index: 13; }
.result-memory-panel {
  position: absolute; z-index: 14; top: 100%; right: -1px; left: -1px;
  display: block; padding: 0 11px 8px; overflow: hidden;
  border: 1px solid #5a5a5a; border-top: 0; background: var(--shell);
  box-shadow: 0 12px 18px #0007; visibility: hidden; opacity: 0;
  transform: translateY(-6px); pointer-events: none;
  transition: opacity .2s ease, transform .26s ease, visibility .26s ease;
}
.result-memory.is-open .result-memory-panel {
  visibility: visible; opacity: 1; transform: translateY(0); pointer-events: auto;
}
.result-memory-inner { min-height: 0; overflow: visible; }