.calculator-layout {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  min-height: 0;
  position: relative;
  isolation: isolate;
}

.calculator-layout::after {
  content: "";
  position: absolute;
  top: var(--theme-mascot-top);
  right: var(--theme-mascot-right);
  width: var(--theme-mascot-width);
  height: var(--theme-mascot-height);
  background: var(--theme-mascot-image) center / contain no-repeat;
  opacity: var(--theme-mascot-opacity);
  filter: var(--theme-mascot-filter);
  pointer-events: none;
  z-index: 2;
}

.calculator-toolbar {
  display: flex;
  justify-content: flex-start;
  padding: 0 14px 2px;
}

.scientific-toolbar {
  padding: 0 14px 8px;
}

.display-panel {
  padding: 0 14px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  min-height: clamp(126px, 24vh, 236px);
  overflow: hidden;
  position: relative;
  background: var(--theme-display-background);
  border: var(--theme-display-border);
  border-radius: var(--theme-display-radius);
  box-shadow: var(--theme-display-shadow);
}

.display-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--theme-display-overlay);
  background-size: var(--theme-display-overlay-size);
  background-position: var(--theme-display-overlay-position);
  opacity: var(--theme-display-overlay-opacity);
  border-radius: inherit;
}

.display-expression,
.display-value {
  position: relative;
  z-index: 1;
}

.programmer-toolbar,
.inline-toolbar,
.form-toolbar,
.base-toolbar,
.graph-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 6px 6px;
}

.scientific-operator-strip {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 0 6px;
  position: relative;
  border-top: 1px solid var(--border-subtle);
}

.scientific-operator-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 10px;
  min-height: 44px;
}

.scientific-operator-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 0.45rem;
  padding: 0.2rem 0.45rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 0.94rem;
  justify-content: flex-start;
}

.scientific-operator-button:hover,
.scientific-operator-button:focus-visible,
.scientific-operator-button.active,
.scientific-menu-toggle:hover,
.scientific-menu-toggle:focus-visible,
.scientific-menu-toggle.active,
.scientific-menu-item:hover,
.scientific-menu-item:focus-visible {
  background: var(--button-default-hover-bg);
}

.scientific-operator-caret {
  color: var(--text-soft);
  font-size: 0.9em;
}

.scientific-operator-icon {
  display: inline-flex;
  width: 15px;
  height: 15px;
  color: var(--text);
}

.scientific-operator-icon svg {
  width: 100%;
  height: 100%;
}

.scientific-operator-menu {
  position: absolute;
  top: calc(100% - 2px);
  left: 10px;
  z-index: 4;
  display: grid;
  gap: 2px;
  padding: 2px;
  background: color-mix(in srgb, var(--window-bg) 94%, #111);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: var(--shadow-menu);
}

.scientific-operator-menu-trig {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(424px, calc(100vw - 24px));
}

.scientific-operator-menu-function {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(316px, calc(100vw - 24px));
}

.scientific-menu-toggle,
.scientific-menu-item {
  min-height: 60px;
  padding: 0.72rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border-faint);
  background: var(--button-default-bg);
  color: var(--text);
  font-size: 0.92rem;
}

.scientific-menu-toggle {
  font-size: 0.88rem;
}
.converter-swap {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.memory-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(1rem, 2.2vw, 1.8rem);
  padding: 0 14px 8px;
}

.memory-toolbar button,
.inline-toolbar button,
.converter-swap button,
.memory-action,
.history-clear,
.memory-clear {
  min-height: 28px;
  padding: 0.2rem 0.3rem;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
}

.memory-toolbar button.disabled,
.memory-toolbar button:disabled {
  color: var(--text-faint);
}

.memory-caret {
  margin-left: 1px;
}

.display-expression {
  min-height: 1.1rem;
  width: 100%;
  text-align: right;
  color: var(--text-faint);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.15;
}

.display-value {
  min-height: 4rem;
  width: 100%;
  text-align: right;
  font-size: clamp(3rem, 7vw, 4.85rem);
  font-weight: 300;
  letter-spacing: -0.045em;
  line-height: 0.95;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow-wrap: anywhere;
}

.display-value.display-error {
  min-height: 0;
  font-size: clamp(1.5rem, 6.2vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.06;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.display-expression.compact {
  font-size: 0.78rem;
}

.display-expression.dense {
  font-size: 0.72rem;
}

.display-value.compact {
  font-size: clamp(2.75rem, 6vw, 4.4rem);
  letter-spacing: -0.035em;
}

.display-value.dense {
  font-size: clamp(2rem, 4.6vw, 3.2rem);
  letter-spacing: -0.025em;
}

.display-value.ultra-dense {
  font-size: clamp(1.65rem, 3.8vw, 2.6rem);
  letter-spacing: -0.015em;
}

@media (max-height: 460px) {
  .main-panel {
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
}

.mode-banner,
.currency-banner,
.info-banner {
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: var(--accent-surface);
  border: 1px solid var(--accent-border);
  color: var(--text-soft);
}

.button-grid {
  display: grid;
  gap: 2px;
  flex: 1;
  padding: 0 6px 6px;
  min-height: 0;
}

.button-grid.standard {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
}

.button-grid.scientific,
.button-grid.programmer {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.button-grid.scientific {
  grid-template-rows: repeat(7, minmax(0, 1fr));
}

.button-grid.programmer {
  grid-template-rows: repeat(6, minmax(0, 1fr));
}

.programmer-shell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  height: 100%;
  min-height: 0;
}

.calculator-layout.programmer {
  gap: 0;
}

.calculator-layout.programmer .button-grid.programmer {
  flex: 1;
  padding: 0 4px 4px;
}

.calculator-layout.programmer .calc-button {
  font-size: 0.98rem;
}

.calculator-layout.programmer .calc-button.equals {
  color: var(--button-equals-text);
}

.calculator-layout.programmer .calc-button.disabled {
  opacity: 1;
  color: var(--text-faint);
  background: var(--button-function-bg);
  filter: none;
}

.calc-button {
  min-height: 0;
  height: 100%;
  border-radius: var(--theme-button-radius);
  border: 1px solid var(--border-faint);
  background: var(--button-default-bg);
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 400;
  transition: background 100ms ease, transform 100ms ease;
  box-shadow: var(--theme-button-shadow);
}

.calc-button:hover,
.calc-button:focus-visible {
  background: var(--button-default-hover-bg);
}

.calc-button:active {
  transform: scale(0.99);
}

.calc-button.function {
  background: var(--button-function-bg);
}

.calc-button.function:hover,
.calc-button.function:focus-visible {
  background: var(--button-function-hover-bg);
}

.calc-button.digit {
  background: var(--button-digit-bg);
}

.calc-button.digit:hover,
.calc-button.digit:focus-visible {
  background: var(--button-digit-hover-bg);
}

.calc-button.operator {
  background: var(--button-operator-bg);
}

.calc-button.operator:hover,
.calc-button.operator:focus-visible {
  background: var(--button-operator-hover-bg);
}

.calc-button.equals {
  background: linear-gradient(180deg, var(--button-equals-bg-start), var(--button-equals-bg-end));
  color: var(--button-equals-text);
  font-weight: 500;
}

.calc-button.equals:hover,
.calc-button.equals:focus-visible {
  background: linear-gradient(180deg, var(--button-equals-hover-bg-start), var(--button-equals-hover-bg-end));
}

.calc-button.disabled,
.base-button.disabled,
.angle-toggle.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: saturate(0.6);
}

.readout-card,
.stat-card,
.result-card {
  background: var(--panel-alt);
  border-radius: var(--radius-sm);
  padding: 0.95rem 1rem;
  border: 1px solid var(--border-subtle);
}

.readout-card strong,
.stat-card strong,
.result-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.1rem;
  color: var(--text);
  word-break: break-word;
}
