:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --paper: #12151d;
  --body: #2f3040;
  --body-edge: #171924;
  --bezel: #202332;
  --lcd: #cfe1da;
  --lcd-dark: #263333;
  --ink: #0f1b1b;
  --text: #edf1f7;
  --muted: #aeb5c4;
  --key: #c7c9d2;
  --key-text: #262a34;
  --key-dark: #353848;
  --key-blue: #173c59;
  --shift: #f2cf62;
  --alpha: #df76ac;
  --danger: #c87682;
  --accent: #dd8792;
  --equals: #d4dde5;
  --ring: #73d7ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, .42);
  --radius: 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #edf2f6;
  --paper: #f8fafc;
  --body: #4d5263;
  --body-edge: #2f3443;
  --bezel: #d9dee7;
  --text: #121722;
  --muted: #526071;
  --shadow: 0 22px 60px rgba(36, 51, 69, .22);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(110deg, rgba(115, 215, 255, .11) 0 1px, transparent 1px 120px),
    linear-gradient(25deg, rgba(242, 207, 98, .08) 0 1px, transparent 1px 96px),
    radial-gradient(ellipse at top, #1b2230 0, var(--bg) 62%);
}

body::before {
  content: "∫   ∑   λ   Δ   ∂   E=mc²   F=ma   π";
  position: fixed;
  inset: 8% 0 auto 0;
  z-index: -1;
  color: rgba(255, 255, 255, .055);
  font-family: Georgia, serif;
  font-size: 42px;
  letter-spacing: 22px;
  text-align: center;
  white-space: nowrap;
  transform: rotate(-4deg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 24px));
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(340px, 500px) minmax(300px, 390px);
  gap: 24px;
  align-items: center;
  justify-content: center;
  padding: 18px 0 44px;
  transition: grid-template-columns 180ms ease;
}

.app-shell.panel-collapsed {
  grid-template-columns: minmax(340px, 500px);
}

.calculator {
  width: min(100%, 500px);
  max-height: calc(100dvh - 24px);
  padding: 24px 24px 28px;
  border-radius: var(--radius) var(--radius) 22px 22px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .16), transparent 22%),
    linear-gradient(180deg, var(--body), var(--body-edge));
  box-shadow: var(--shadow), inset 0 2px 0 rgba(255, 255, 255, .12), inset 0 -10px 20px rgba(0, 0, 0, .18);
  border: 1px solid rgba(255, 255, 255, .12);
  position: relative;
  transform: perspective(1100px) rotateX(1deg);
}

.calc-head {
  min-height: 78px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.calc-head h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1.6px;
  font-weight: 800;
}

.calc-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .5px;
}

.brand-logo-button {
  width: 70px;
  height: 70px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease;
}

.brand-logo-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.07);
}

.brand-logo-button:active {
  transform: translateY(1px) scale(.98);
}

.brand-logo-button:focus-visible {
  outline: 3px solid rgba(253, 218, 99, .92);
  outline-offset: 4px;
}

.brand-logo {
  width: 70px;
  height: 70px;
  display: block;
  object-fit: contain;
  padding: 0;
  border-radius: 50%;
  background: #f4f8fa;
  border: 2px solid rgba(255, 255, 255, .72);
  box-shadow: inset 0 0 0 1px rgba(14, 23, 35, .12), 0 7px 14px rgba(0, 0, 0, .34);
  filter: contrast(1.12) saturate(1.06);
}

.lcd {
  min-height: 128px;
  margin: 0 8px 18px;
  padding: 14px 16px;
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .35), transparent 35%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .035) 0 1px, transparent 1px 4px),
    var(--lcd);
  box-shadow:
    inset 0 0 0 3px #171923,
    inset 0 0 22px rgba(48, 72, 67, .34),
    0 12px 22px rgba(0, 0, 0, .25);
  animation: lcdPower 1100ms ease-out both;
}

.lcd-top {
  height: 18px;
  display: grid;
  grid-template-columns: auto 28px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .5px;
}

.lcd-expression,
.lcd-result,
.lcd-fraction {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.lcd-expression {
  min-height: 32px;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.25;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lcd-result {
  width: 100%;
  min-height: 42px;
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 33px;
  font-weight: 800;
  line-height: 1.15;
  text-align: right;
  background: transparent;
  border: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lcd-fraction {
  min-height: 16px;
  font-size: 13px;
  text-align: right;
}

.cursor {
  display: inline-block;
  width: 9px;
  height: 24px;
  margin-left: 2px;
  vertical-align: -4px;
  background: rgba(12, 30, 30, .76);
  animation: blink 900ms steps(2) infinite;
}

.top-controls {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 9px;
}

.calculator-actions {
  margin: 14px 8px 0;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .1);
  display: flex;
  justify-content: center;
  gap: 9px;
  flex-wrap: wrap;
}

.calc-action-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  color: rgba(241, 245, 250, .92);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, 0) 38%),
    linear-gradient(180deg, #565b6c 0%, #363a49 58%, #272b38 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .18),
    inset 0 -2px 0 rgba(0, 0, 0, .26),
    0 5px 10px rgba(0, 0, 0, .26);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.calc-action-link:hover,
.calc-action-link:focus-visible {
  color: #ffffff;
  border-color: rgba(255, 255, 255, .24);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 38%),
    linear-gradient(180deg, #626879 0%, #3d4252 58%, #2c3040 100%);
  transform: translateY(-1px);
}

.calc-action-link:focus-visible {
  outline: 3px solid rgba(253, 218, 99, .86);
  outline-offset: 3px;
}

.action-icon {
  width: 17px;
  height: 17px;
  fill: rgba(216, 232, 242, .95);
  flex: 0 0 auto;
}

.key {
  min-width: 0;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: var(--key-text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .62), rgba(255, 255, 255, .08)),
    linear-gradient(180deg, var(--key), #858998);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .55),
    inset 0 -3px 0 rgba(0, 0, 0, .22),
    0 5px 8px rgba(0, 0, 0, .32);
  font-weight: 800;
  line-height: 1;
  text-align: center;
  transition: transform 90ms ease, filter 120ms ease, box-shadow 120ms ease;
  user-select: none;
  touch-action: manipulation;
}

.key small {
  display: block;
  min-height: 12px;
  margin-bottom: 3px;
  color: var(--shift);
  font-size: 10px;
  line-height: 1;
}

.key:hover {
  filter: brightness(1.08);
}

.key:active,
.key.pressed {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .25),
    inset 0 -1px 0 rgba(0, 0, 0, .2),
    0 2px 4px rgba(0, 0, 0, .28);
}

.key-dark,
.key-soft {
  color: #eef3fb;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .02)),
    linear-gradient(180deg, #46495a, var(--key-dark));
}

.key-blue {
  color: #ecf7ff;
  background: linear-gradient(180deg, #285f84, var(--key-blue));
}

.key-shift {
  color: #2d2610;
  background: linear-gradient(180deg, #ffe69a, var(--shift));
}

.key-alpha {
  color: #321421;
  background: linear-gradient(180deg, #f3a8ca, var(--alpha));
}

.key-danger {
  color: #fff;
  background: linear-gradient(180deg, #d8919c, #a64f60);
}

.key-accent {
  color: #fff;
  background: linear-gradient(180deg, #ef9aa4, var(--accent));
}

.key-op,
.key-equals {
  font-size: 22px;
}

.key-equals {
  background: linear-gradient(180deg, #f3f7fb, var(--equals));
}

.key-number {
  font-size: 23px;
}

body[data-shift="on"] .key-shift,
body[data-alpha="on"] .key-alpha {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .45), 0 0 18px rgba(255, 224, 112, .38);
}

.side-panel {
  width: min(100%, 390px);
  max-height: calc(100dvh - 30px);
  overflow: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 18px;
  background: rgba(18, 21, 29, .84);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  backdrop-filter: blur(18px);
  transition: opacity 160ms ease, transform 180ms ease;
}

.side-panel.collapsed {
  display: none;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-section h2 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: .4px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item,
.utility-chip,
.mini-button {
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .07);
}

.history-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.history-item span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  font-family: Consolas, monospace;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

.registers,
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.utility-chip,
.mini-button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
}

.inline-tools,
.converter-grid {
  display: grid;
  gap: 8px;
}

.inline-tools {
  grid-template-columns: 1fr auto auto auto;
}

.converter-grid {
  grid-template-columns: 1fr 1fr;
}

input,
select {
  min-width: 0;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
}

.tool-output {
  display: block;
  min-height: 28px;
  margin-top: 8px;
  color: #d6f2ff;
  font-family: Consolas, monospace;
  line-height: 1.4;
}

.formula-list {
  display: grid;
  gap: 8px;
}

.formula-card {
  display: grid;
  grid-template-columns: 1fr 70px 70px 34px;
  gap: 7px;
  align-items: center;
}

.formula-card strong {
  font-size: 12px;
}

.formula-card output {
  grid-column: 1 / -1;
  color: #d6f2ff;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.formula-card button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-close {
  display: none;
}

.panel-hide {
  display: inline-flex;
  align-items: center;
}

.tour-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: transparent;
}

.tour-spotlight {
  position: fixed;
  z-index: 31;
  border: 3px solid rgba(253, 218, 99, .96);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(2, 7, 15, .74), 0 0 34px rgba(253, 218, 99, .4);
  pointer-events: none;
  transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease;
}

.tour-highlight {
  border-radius: 10px;
}

.tour-card {
  position: fixed;
  z-index: 33;
  width: min(312px, calc(100vw - 28px));
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 10px;
  color: var(--text);
  background: rgba(18, 26, 39, .98);
  box-shadow: 0 22px 48px rgba(0, 0, 0, .46);
}

.tour-card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.tour-card p {
  margin: 0;
  color: rgba(229, 237, 247, .82);
  font-size: 13px;
  line-height: 1.45;
}

.tour-counter {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tour-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.tour-actions button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  font-weight: 800;
  cursor: pointer;
}

.tour-actions button:last-child {
  background: rgba(23, 73, 111, .96);
}

.tour-actions button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.site-footer {
  position: fixed;
  left: 50%;
  bottom: 8px;
  z-index: 6;
  transform: translateX(-50%);
  width: min(100% - 24px, 760px);
  text-align: center;
  font-size: 12px;
}

.site-footer a {
  color: rgba(237, 241, 247, .76);
  text-decoration: none;
}

.site-footer a:hover {
  color: #ffffff;
  text-decoration: underline;
}

.high-contrast {
  --lcd: #e6ffef;
  --ring: #fff000;
}

@keyframes lcdPower {
  0% {
    opacity: 0;
    filter: brightness(.25) blur(2px);
    transform: scaleY(.86);
  }
  48% {
    opacity: 1;
    filter: brightness(1.25);
  }
  100% {
    filter: brightness(1);
    transform: scaleY(1);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@media (max-width: 920px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    width: 100%;
    grid-template-columns: 1fr;
    padding: 10px 10px 46px;
  }

  .calculator {
    justify-self: center;
    padding: 18px 14px;
  }

  .side-panel {
    position: fixed;
    inset: 10px;
    z-index: 5;
    width: auto;
    max-height: none;
    padding-bottom: 80px;
    transform: translateX(calc(100% + 20px));
    transition: transform 180ms ease;
  }

  .side-panel.open {
    transform: translateX(0);
  }

  .panel-close {
    display: inline-flex;
    align-items: center;
  }

  .panel-hide {
    display: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 6px 6px 44px;
  }

  .calculator {
    width: 100%;
    max-height: calc(100dvh - 56px);
    border-radius: 22px;
    padding: 14px 10px 16px;
  }

  .calc-head {
    min-height: 62px;
  }

  .calc-head h1 {
    font-size: 15px;
  }

  .brand-logo-button,
  .brand-logo {
    width: 56px;
    height: 56px;
  }

  .lcd {
    min-height: 116px;
    margin: 0 3px 12px;
    padding: 12px;
  }

  .lcd-expression {
    font-size: 20px;
  }

  .lcd-result {
    font-size: 28px;
  }

  .top-controls,
  .keypad {
    gap: 7px;
  }

  .key {
    min-height: 40px;
    border-radius: 7px;
    font-size: 13px;
  }

  .key-number,
  .key-op,
  .key-equals {
    font-size: 20px;
  }

  .key small {
    font-size: 9px;
  }
}

@media (max-height: 720px) {
  .calculator {
    padding-top: 12px;
    padding-bottom: 14px;
  }

  .calc-head {
    min-height: 54px;
  }

  .lcd {
    min-height: 108px;
    margin-bottom: 10px;
  }

  .key {
    min-height: 36px;
  }
}

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

/* SDLF calculator responsive audit hardening - 2026-05-22 */
html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  overflow-x: hidden;
  overflow-y: auto;
}

*, *::before, *::after {
  min-width: 0;
}

button,
input,
select,
a {
  touch-action: manipulation;
}

.app-shell,
.calculator,
.side-panel,
.lcd,
.top-controls,
.keypad,
.calculator-actions,
.panel-section,
.inline-tools,
.converter-grid,
.formula-card {
  min-width: 0;
}

.app-shell {
  min-height: 100dvh;
  height: auto;
}

.calculator {
  transform: none;
}

.lcd-expression,
.lcd-result,
.lcd-fraction,
.history-item,
.formula-card,
.tool-output {
  overflow-wrap: anywhere;
}

.lcd-expression,
.lcd-result {
  white-space: normal;
}

.key,
.calc-action-link,
.utility-chip,
.mini-button,
.panel-close,
.panel-hide {
  min-height: 44px;
}

.key {
  overflow: hidden;
}

.key small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-panel {
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.tour-card {
  max-height: min(86dvh, 540px);
  overflow: auto;
}

@media (min-width: 1400px) and (min-height: 850px) {
  .app-shell {
    width: min(1280px, calc(100% - 48px));
  }
}

@media (max-width: 920px) {
  .app-shell {
    min-height: 100dvh;
    align-items: start;
  }

  .calculator {
    max-height: none;
  }

  .side-panel {
    overflow-y: auto;
  }
}

@media (max-width: 640px) {
  .top-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .keypad {
    gap: 7px;
  }

  .calculator-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-inline: 2px;
  }

  .calc-action-link {
    justify-content: center;
  }

  .inline-tools,
  .converter-grid,
  .formula-card {
    grid-template-columns: 1fr;
  }

  .formula-card output {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .calculator {
    max-height: none;
  }

  .calc-head {
    align-items: center;
  }

  .lcd {
    min-height: 104px;
  }

  .keypad {
    grid-template-columns: repeat(7, minmax(34px, 1fr));
  }

  .key {
    min-height: clamp(38px, 10.8vw, 46px);
    padding-inline: 2px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    width: 100%;
    padding-inline: 4px;
  }

  .calculator {
    padding-inline: 8px;
  }

  .calc-head h1 {
    font-size: 13px;
  }

  .lcd-expression {
    font-size: 18px;
  }

  .lcd-result {
    font-size: 24px;
  }

  .keypad {
    gap: 5px;
  }

  .key {
    min-height: 36px;
    font-size: 12px;
  }

  .key-number,
  .key-op,
  .key-equals {
    font-size: 17px;
  }

  .calculator-actions {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .app-shell {
    align-items: start;
    padding-block: 8px 40px;
  }

  .calculator {
    width: min(100%, 760px);
  }

  .lcd {
    min-height: 82px;
  }

  .calc-head {
    min-height: 48px;
  }

  .key {
    min-height: 34px;
  }
}
