:root {
  --color-forest-deep: #173f2a;
  --color-forest-night: #0f2c20;
  --color-forest: #2f6b45;
  --color-moss: #7fa66a;
  --color-leaf-light: #d9e8b6;
  --color-bark: #7a4f2a;
  --color-bark-dark: #4d2f18;
  --color-birch: #f6efd9;
  --color-birch-warm: #fff8e4;
  --color-feather-blue: #4d7c8a;
  --color-berry: #b64b3b;
  --color-sun: #f0c766;
  --shadow-soft: 0 24px 54px rgba(15, 44, 32, 0.36);
  --radius-card: 28px;
  --radius-button: 17px;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="enchanted-night"] {
  --color-bg-night: #07140F;
  --color-bg-deep: #02070A;
  --color-surface: #10241C;
  --color-surface-raised: #173126;
  --color-border: #2B4A3D;
  --color-text-primary: #F3F7EA;
  --color-text-secondary: #B9CDBB;
  --color-text-disabled: #6E806F;
  --color-accent-primary: #8FE388;
  --color-accent-primary-hover: #A9F5A1;
  --color-accent-secondary: #9DC7FF;
  --color-accent-secondary-hover: #B9D8FF;
  --color-danger: #FF8F8F;
  --color-danger-soft: #FFB3B3;
  --color-equals: #D6B86A;
  --color-equals-hover: #E8CC7B;
  --shadow-soft: 0 16px 40px rgba(0, 0, 0, 0.45), inset 0 0 24px rgba(143, 227, 136, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--color-forest-night);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--font-ui);
  color: var(--color-bark-dark);
  background:
    radial-gradient(circle at 20% 16%, rgba(240, 199, 102, 0.28), transparent 28%),
    radial-gradient(circle at 76% 22%, rgba(217, 232, 182, 0.24), transparent 25%),
    linear-gradient(150deg, var(--color-forest-night) 0%, var(--color-forest-deep) 42%, #426f42 100%);
  overflow-x: hidden;
  transition: background-color 180ms ease, color 180ms ease;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto 0 0;
  height: 27vh;
  pointer-events: none;
  background-repeat: repeat-x;
  opacity: 0.34;
}

body::before {
  background-image:
    linear-gradient(135deg, transparent 0 42%, rgba(8, 34, 22, 0.75) 43% 57%, transparent 58%),
    linear-gradient(45deg, transparent 0 42%, rgba(8, 34, 22, 0.75) 43% 57%, transparent 58%);
  background-size: 104px 180px, 104px 180px;
  background-position: 0 100%, 52px 100%;
}

body::after {
  height: 18vh;
  background-image: linear-gradient(180deg, transparent 0 20%, rgba(9, 40, 25, 0.74) 21% 100%);
}

.app-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px 16px;
}

.forest-glow {
  position: fixed;
  inset: 8% auto auto 50%;
  width: min(74vw, 620px);
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 999px;
  background: radial-gradient(circle, rgba(217, 232, 182, 0.22), transparent 62%);
  pointer-events: none;
}

.calculator-layout {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 22px;
  width: min(96vw, 820px);
}

.calculator-card {
  position: relative;
  width: min(94vw, 430px);
  flex: 0 0 min(94vw, 430px);
  padding: 24px;
  border: 1px solid rgba(255, 248, 228, 0.45);
  border-radius: var(--radius-card);
  background:
    radial-gradient(circle at 9% 7%, rgba(240, 199, 102, 0.28), transparent 22%),
    linear-gradient(145deg, rgba(255, 248, 228, 0.98), rgba(246, 239, 217, 0.95));
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(77, 47, 24, 0.06);
  overflow: hidden;
}

.calculator-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(102deg, rgba(122, 79, 42, 0.035) 0 2px, transparent 2px 11px),
    radial-gradient(circle at 88% 82%, rgba(127, 166, 106, 0.24), transparent 28%);
  pointer-events: none;
}

.app-header,
.mode-switcher,
.mode-panel,
.display-panel,
.button-grid,
.hint,
.converter-panel,
.tree-line {
  position: relative;
  z-index: 1;
}

.history-panel {
  position: relative;
  flex: 0 1 320px;
  width: min(92vw, 320px);
  max-height: min(70vh, 620px);
  padding: 20px;
  border: 1px solid rgba(255, 248, 228, 0.46);
  border-radius: var(--radius-card);
  background:
    radial-gradient(circle at 12% 8%, rgba(240, 199, 102, 0.22), transparent 26%),
    linear-gradient(145deg, rgba(255, 248, 228, 0.97), rgba(246, 239, 217, 0.94));
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(77, 47, 24, 0.06);
  overflow: hidden;
}

.history-panel[hidden] {
  display: none;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.header-actions {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: end;
  gap: 10px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  color: #fff8e6;
  background: linear-gradient(145deg, #68814f, #3d6746);
  box-shadow: 0 4px 0 rgba(77, 47, 24, 0.16);
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

.theme-toggle-icon {
  font-size: 1.08rem;
  line-height: 1;
}

.history-toggle,
.history-close {
  border: 0;
  border-radius: 999px;
  color: #fff8e6;
  background: linear-gradient(145deg, #68814f, #3d6746);
  box-shadow: 0 4px 0 rgba(77, 47, 24, 0.16);
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

.history-toggle {
  margin-top: 12px;
  padding: 0.56rem 0.86rem;
}

.history-close {
  padding: 0.5rem 0.76rem;
}

.theme-toggle:hover,
.history-toggle:hover,
.history-close:hover {
  filter: brightness(1.05) saturate(1.08);
  transform: translateY(-1px);
}

.theme-toggle:active,
.history-toggle:active,
.history-close:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(77, 47, 24, 0.18);
}

.theme-toggle:focus-visible,
.history-toggle:focus-visible,
.history-close:focus-visible {
  outline: 3px solid var(--color-sun);
  outline-offset: 3px;
}

.mode-switcher {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
  padding: 6px;
  border: 1px solid rgba(77, 47, 24, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 245, 0.45);
}

.mode-tab {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  color: var(--color-bark-dark);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 850;
  transition: transform 130ms ease, box-shadow 130ms ease, background 130ms ease;
}

.mode-tab[aria-selected="true"] {
  color: #fff8e6;
  background: linear-gradient(145deg, #68814f, #3d6746);
  box-shadow: 0 4px 0 rgba(77, 47, 24, 0.16);
}

.mode-tab:hover {
  transform: translateY(-1px);
}

.mode-tab:focus-visible,
.converter-input:focus-visible,
.converter-select:focus-visible {
  outline: 3px solid var(--color-sun);
  outline-offset: 3px;
}

.mode-panel[hidden],
.converter-panel[hidden] {
  display: none;
}

.converter-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 2px solid rgba(77, 47, 24, 0.13);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 245, 0.95), rgba(217, 232, 182, 0.72)),
    repeating-linear-gradient(90deg, transparent 0 14px, rgba(122, 79, 42, 0.05) 15px 16px);
  box-shadow: inset 0 3px 8px rgba(77, 47, 24, 0.10);
}

.converter-panel h2 {
  margin: 0;
  color: var(--color-forest-deep);
  font-size: 1.35rem;
  line-height: 1.1;
}

.converter-grid {
  display: grid;
  gap: 12px;
}

.converter-field {
  display: grid;
  gap: 6px;
  color: rgba(77, 47, 24, 0.78);
  font-size: 0.88rem;
  font-weight: 850;
}

.converter-input,
.converter-select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(77, 47, 24, 0.18);
  border-radius: 14px;
  color: var(--color-bark-dark);
  background: rgba(255, 255, 245, 0.94);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
}

.converter-input {
  padding: 0 12px;
}

.converter-select {
  padding: 0 10px;
}

.converter-input[aria-invalid="true"] {
  border-color: var(--color-berry);
  box-shadow: 0 0 0 3px rgba(182, 75, 59, 0.18);
}

.converter-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(182, 75, 59, 0.25);
  border-radius: 14px;
  color: #84372d;
  background: rgba(255, 238, 224, 0.78);
  font-size: 0.9rem;
  font-weight: 800;
}

.converter-result {
  display: grid;
  gap: 5px;
  padding: 14px;
  border-radius: 18px;
  color: var(--color-forest-deep);
  background: rgba(255, 248, 228, 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.converter-result span {
  color: rgba(77, 47, 24, 0.68);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.converter-result output {
  font-size: clamp(1.35rem, 6vw, 2rem);
  font-weight: 850;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--color-forest);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--color-forest-deep);
  font-size: clamp(2rem, 11vw, 3rem);
  line-height: 0.94;
  letter-spacing: -0.06em;
}

.tagline {
  max-width: 19rem;
  margin: 8px 0 0;
  color: rgba(77, 47, 24, 0.78);
  font-size: 0.95rem;
  line-height: 1.35;
}

.bird-mark {
  width: 118px;
  min-width: 96px;
  filter: drop-shadow(0 8px 9px rgba(77, 47, 24, 0.18));
}

.branch,
.twig,
.feet {
  fill: none;
  stroke: var(--color-bark-dark);
  stroke-width: 5;
  stroke-linecap: round;
}

.twig,
.feet { stroke-width: 3; }
.leaf-a, .leaf-b { fill: var(--color-moss); }
.bird-body { fill: var(--color-feather-blue); }
.bird-head { fill: #638f71; }
.bird-wing { fill: #315f55; opacity: 0.92; }
.bird-tail { fill: #315f55; }
.beak { fill: var(--color-sun); }
.eye { fill: #1d231d; }

.display-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 2px solid rgba(77, 47, 24, 0.13);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 245, 0.98), rgba(217, 232, 182, 0.78)),
    repeating-linear-gradient(90deg, transparent 0 14px, rgba(122, 79, 42, 0.06) 15px 16px);
  box-shadow: inset 0 3px 8px rgba(77, 47, 24, 0.12);
}

.expression-preview {
  min-height: 1.25rem;
  margin-bottom: 5px;
  color: rgba(77, 47, 24, 0.67);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.display {
  display: block;
  width: 100%;
  min-height: 3.6rem;
  color: var(--color-forest-deep);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.15rem, 11vw, 3.3rem);
  font-weight: 800;
  line-height: 1.08;
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
}

.display.error {
  color: var(--color-berry);
  font-size: clamp(1.2rem, 6vw, 1.75rem);
  white-space: normal;
}

.history-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.history-panel h2 {
  margin: 0;
  color: var(--color-forest-deep);
  font-size: clamp(1.5rem, 6vw, 2rem);
  line-height: 1;
}

.history-empty {
  margin: 14px 0 0;
  padding: 14px;
  border: 2px dashed rgba(77, 47, 24, 0.18);
  border-radius: 18px;
  color: rgba(77, 47, 24, 0.72);
  background: rgba(255, 255, 245, 0.54);
  font-size: 0.95rem;
  line-height: 1.4;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: min(54vh, 500px);
  margin: 0;
  padding: 2px 4px 2px 0;
  list-style: none;
  overflow-y: auto;
}

.history-entry {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid rgba(77, 47, 24, 0.13);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 245, 0.94), rgba(217, 232, 182, 0.66));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  overflow-wrap: anywhere;
}

.history-entry-expression {
  color: rgba(77, 47, 24, 0.72);
  font-size: 0.9rem;
  font-weight: 750;
}

.history-entry-result {
  color: var(--color-forest-deep);
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.key {
  min-height: 62px;
  border: 0;
  border-radius: var(--radius-button);
  color: var(--color-bark-dark);
  background:
    linear-gradient(180deg, rgba(255, 252, 236, 0.96), rgba(217, 232, 182, 0.9));
  box-shadow:
    0 6px 0 rgba(77, 47, 24, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  cursor: pointer;
  font: inherit;
  font-size: 1.38rem;
  font-weight: 850;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

.key:hover {
  filter: brightness(1.035) saturate(1.08);
  transform: translateY(-1px);
}

.key:active,
.key.is-pressed {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 rgba(77, 47, 24, 0.2),
    inset 0 2px 5px rgba(77, 47, 24, 0.14);
}

.key:focus-visible {
  outline: 3px solid var(--color-sun);
  outline-offset: 3px;
}

.operator {
  color: #fff7dc;
  background:
    linear-gradient(145deg, #8b5c31, var(--color-bark-dark)),
    repeating-linear-gradient(110deg, transparent 0 7px, rgba(255,255,255,0.07) 8px 9px);
}

.action {
  color: #fff8e6;
  background: linear-gradient(145deg, #68814f, #3d6746);
}

.action.danger {
  background: linear-gradient(145deg, #c05c49, #84372d);
}

.equals {
  grid-row: span 2;
  color: #2f250d;
  background: linear-gradient(145deg, #f7d982, var(--color-sun));
  font-size: 1.7rem;
}

.zero {
  grid-column: span 2;
}

.hint {
  margin: 15px 3px 0;
  color: rgba(77, 47, 24, 0.76);
  font-size: 0.83rem;
  line-height: 1.45;
}

kbd {
  padding: 0.08rem 0.32rem;
  border: 1px solid rgba(77, 47, 24, 0.25);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.38);
  font: 0.78rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.leaf-cluster {
  position: absolute;
  z-index: 0;
  width: 100px;
  height: 100px;
  pointer-events: none;
  opacity: 0.23;
}

.leaf-cluster-left { left: -28px; top: 34%; transform: rotate(-22deg); }
.leaf-cluster-right { right: -34px; top: 58%; transform: rotate(24deg); }

.leaf-cluster span {
  position: absolute;
  width: 54px;
  height: 25px;
  border-radius: 100% 0 100% 0;
  background: var(--color-moss);
}
.leaf-cluster span:nth-child(1) { left: 16px; top: 8px; transform: rotate(15deg); }
.leaf-cluster span:nth-child(2) { left: 42px; top: 38px; transform: rotate(72deg); }
.leaf-cluster span:nth-child(3) { left: 10px; top: 56px; transform: rotate(-36deg); }

.tree-line {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin-top: 16px;
  opacity: 0.48;
}

.tree-line span {
  width: 0;
  height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-bottom: 42px solid var(--color-forest);
  filter: drop-shadow(0 9px 0 var(--color-bark));
}

.tree-line span:nth-child(even) {
  transform: scale(0.78) translateY(7px);
  border-bottom-color: var(--color-moss);
}

html[data-theme="enchanted-night"] {
  background: var(--color-bg-deep);
}

:root[data-theme="enchanted-night"] body {
  color: var(--color-text-primary);
  background:
    radial-gradient(circle at 20% 14%, rgba(143, 227, 136, 0.10), transparent 29%),
    radial-gradient(circle at 76% 20%, rgba(157, 199, 255, 0.10), transparent 26%),
    linear-gradient(155deg, var(--color-bg-night) 0%, var(--color-surface) 44%, var(--color-bg-deep) 100%);
}

:root[data-theme="enchanted-night"] body::before {
  background-image:
    linear-gradient(135deg, transparent 0 42%, rgba(2, 7, 10, 0.78) 43% 57%, transparent 58%),
    linear-gradient(45deg, transparent 0 42%, rgba(2, 7, 10, 0.78) 43% 57%, transparent 58%);
  opacity: 0.4;
}

:root[data-theme="enchanted-night"] body::after {
  background-image: linear-gradient(180deg, transparent 0 20%, rgba(2, 7, 10, 0.78) 21% 100%);
}

:root[data-theme="enchanted-night"] .forest-glow {
  background:
    radial-gradient(circle at 42% 36%, rgba(143, 227, 136, 0.12), transparent 42%),
    radial-gradient(circle at 62% 58%, rgba(157, 199, 255, 0.10), transparent 56%);
}

:root[data-theme="enchanted-night"] .calculator-card,
:root[data-theme="enchanted-night"] .history-panel {
  border-color: var(--color-border);
  color: var(--color-text-primary);
  background:
    radial-gradient(circle at 10% 7%, rgba(143, 227, 136, 0.08), transparent 24%),
    linear-gradient(145deg, rgba(16, 36, 28, 0.98), rgba(7, 20, 15, 0.96));
  box-shadow: var(--shadow-soft);
}

:root[data-theme="enchanted-night"] .calculator-card::before,
:root[data-theme="enchanted-night"] .history-panel::before {
  background-image:
    repeating-linear-gradient(102deg, rgba(143, 227, 136, 0.035) 0 2px, transparent 2px 11px),
    radial-gradient(circle at 88% 82%, rgba(157, 199, 255, 0.10), transparent 28%);
}

:root[data-theme="enchanted-night"] .eyebrow,
:root[data-theme="enchanted-night"] .expression-preview,
:root[data-theme="enchanted-night"] .history-empty,
:root[data-theme="enchanted-night"] .history-entry-expression,
:root[data-theme="enchanted-night"] .hint {
  color: var(--color-text-secondary);
}

:root[data-theme="enchanted-night"] h1,
:root[data-theme="enchanted-night"] .history-panel h2,
:root[data-theme="enchanted-night"] .history-entry-result,
:root[data-theme="enchanted-night"] .display {
  color: var(--color-text-primary);
}

:root[data-theme="enchanted-night"] .tagline {
  color: var(--color-text-secondary);
}

:root[data-theme="enchanted-night"] .display-panel {
  border-color: var(--color-border);
  background:
    linear-gradient(180deg, rgba(23, 49, 38, 0.98), rgba(16, 36, 28, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 14px, rgba(143, 227, 136, 0.05) 15px 16px);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.22);
}

:root[data-theme="enchanted-night"] .display.error {
  color: var(--color-danger-soft);
}

:root[data-theme="enchanted-night"] .key {
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  background: linear-gradient(180deg, #173126, #10241C);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(243, 247, 234, 0.08);
}

:root[data-theme="enchanted-night"] .key:hover {
  border-color: #3D6754;
  background: linear-gradient(180deg, #1F3E30, #173126);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.24), 0 0 10px rgba(143, 227, 136, 0.12);
}

:root[data-theme="enchanted-night"] .key:active,
:root[data-theme="enchanted-night"] .key.is-pressed {
  background: #244B39;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), inset 0 2px 5px rgba(0, 0, 0, 0.22);
}

:root[data-theme="enchanted-night"] .key:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

:root[data-theme="enchanted-night"] .operator {
  border-color: rgba(157, 199, 255, 0.28);
  color: var(--color-accent-secondary-hover);
  background: linear-gradient(145deg, rgba(157, 199, 255, 0.20), #172A35);
}

:root[data-theme="enchanted-night"] .operator:hover {
  border-color: var(--color-accent-secondary);
  background: linear-gradient(145deg, rgba(157, 199, 255, 0.28), #1b3442);
}

:root[data-theme="enchanted-night"] .operator:focus-visible {
  outline-color: var(--color-accent-secondary);
}

:root[data-theme="enchanted-night"] .action,
:root[data-theme="enchanted-night"] .action.danger {
  border-color: rgba(255, 143, 143, 0.30);
  color: var(--color-danger-soft);
  background: linear-gradient(145deg, rgba(255, 143, 143, 0.20), rgba(255, 143, 143, 0.10));
}

:root[data-theme="enchanted-night"] .action:hover,
:root[data-theme="enchanted-night"] .action.danger:hover {
  border-color: var(--color-danger);
}

:root[data-theme="enchanted-night"] .action:focus-visible,
:root[data-theme="enchanted-night"] .action.danger:focus-visible {
  outline-color: var(--color-danger);
}

:root[data-theme="enchanted-night"] .equals {
  border-color: var(--color-equals-hover);
  color: var(--color-bg-night);
  background: linear-gradient(145deg, var(--color-equals-hover), var(--color-equals));
}

:root[data-theme="enchanted-night"] .equals:hover {
  background: linear-gradient(145deg, #F1D98E, var(--color-equals-hover));
}

:root[data-theme="enchanted-night"] .equals:active,
:root[data-theme="enchanted-night"] .equals.is-pressed {
  background: #C7A95B;
}

:root[data-theme="enchanted-night"] .equals:focus-visible {
  outline-color: var(--color-text-primary);
  box-shadow: 0 0 0 5px rgba(214, 184, 106, 0.35);
}

:root[data-theme="enchanted-night"] .theme-toggle,
:root[data-theme="enchanted-night"] .history-toggle,
:root[data-theme="enchanted-night"] .history-close {
  border: 1px solid var(--color-border);
  color: var(--color-bg-night);
  background: linear-gradient(145deg, var(--color-accent-primary-hover), var(--color-accent-primary));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
}

:root[data-theme="enchanted-night"] .theme-toggle[aria-pressed="true"] {
  color: var(--color-text-primary);
  background: linear-gradient(145deg, rgba(157, 199, 255, 0.24), rgba(143, 227, 136, 0.14));
}

:root[data-theme="enchanted-night"] .theme-toggle:focus-visible,
:root[data-theme="enchanted-night"] .history-toggle:focus-visible,
:root[data-theme="enchanted-night"] .history-close:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

:root[data-theme="enchanted-night"] .mode-switcher {
  border-color: var(--color-border);
  background: rgba(23, 49, 38, 0.68);
}

:root[data-theme="enchanted-night"] .mode-tab {
  color: var(--color-text-secondary);
}

:root[data-theme="enchanted-night"] .mode-tab[aria-selected="true"] {
  color: var(--color-bg-night);
  background: linear-gradient(145deg, var(--color-accent-primary-hover), var(--color-accent-primary));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
}

:root[data-theme="enchanted-night"] .mode-tab:focus-visible,
:root[data-theme="enchanted-night"] .converter-input:focus-visible,
:root[data-theme="enchanted-night"] .converter-select:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

:root[data-theme="enchanted-night"] .converter-panel {
  border-color: var(--color-border);
  background:
    linear-gradient(180deg, rgba(23, 49, 38, 0.98), rgba(16, 36, 28, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 14px, rgba(143, 227, 136, 0.05) 15px 16px);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.22);
}

:root[data-theme="enchanted-night"] .converter-panel h2,
:root[data-theme="enchanted-night"] .converter-result {
  color: var(--color-text-primary);
}

:root[data-theme="enchanted-night"] .converter-field,
:root[data-theme="enchanted-night"] .converter-result span {
  color: var(--color-text-secondary);
}

:root[data-theme="enchanted-night"] .converter-input,
:root[data-theme="enchanted-night"] .converter-select,
:root[data-theme="enchanted-night"] .converter-result {
  border-color: var(--color-border);
  color: var(--color-text-primary);
  background: rgba(23, 49, 38, 0.72);
}

:root[data-theme="enchanted-night"] .converter-input[aria-invalid="true"] {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(255, 143, 143, 0.18);
}

:root[data-theme="enchanted-night"] .converter-error {
  border-color: rgba(255, 143, 143, 0.32);
  color: var(--color-danger-soft);
  background: rgba(255, 143, 143, 0.10);
}

:root[data-theme="enchanted-night"] kbd,
:root[data-theme="enchanted-night"] .history-entry {
  border-color: var(--color-border);
  background: rgba(23, 49, 38, 0.72);
}

:root[data-theme="enchanted-night"] .branch,
:root[data-theme="enchanted-night"] .twig,
:root[data-theme="enchanted-night"] .feet {
  stroke: var(--color-text-secondary);
}

:root[data-theme="enchanted-night"] .leaf-a,
:root[data-theme="enchanted-night"] .leaf-b,
:root[data-theme="enchanted-night"] .leaf-cluster span {
  fill: var(--color-accent-primary);
}

:root[data-theme="enchanted-night"] .bird-body,
:root[data-theme="enchanted-night"] .bird-head {
  fill: var(--color-accent-secondary);
}

:root[data-theme="enchanted-night"] .bird-wing,
:root[data-theme="enchanted-night"] .bird-tail {
  fill: #28485A;
}

:root[data-theme="enchanted-night"] .beak,
:root[data-theme="enchanted-night"] .tree-line span {
  fill: var(--color-equals);
  border-bottom-color: var(--color-accent-primary);
}

:root[data-theme="enchanted-night"] .eye {
  fill: var(--color-bg-night);
}

@media (max-width: 760px) {
  .calculator-layout {
    display: grid;
    justify-items: center;
    width: min(94vw, 430px);
  }

  .calculator-card,
  .history-panel {
    width: 100%;
    flex-basis: auto;
  }

  .history-panel {
    max-height: none;
  }

  .history-list {
    max-height: 42vh;
  }
}

@media (max-width: 420px) {
  .app-shell { padding: 18px 10px; }
  .calculator-card { padding: 18px; border-radius: 23px; }
  .app-header { align-items: flex-start; }
  .bird-mark { width: 88px; min-width: 82px; }
  .tagline { font-size: 0.86rem; }
  .button-grid { gap: 8px; }
  .key { min-height: 56px; border-radius: 14px; font-size: 1.18rem; }
  .display-panel { padding: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
