:root {
  --bg-top: #0a0d0a;
  --bg-middle: #090d08;
  --bg-bottom: #11150f;
  --card-bg: rgba(6, 8, 6, 0.9);
  --card-border: rgba(138, 255, 124, 0.08);
  --display-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  --text-main: #f5f7f3;
  --text-soft: rgba(245, 247, 243, 0.48);
  --button-bg: #171917;
  --button-border: rgba(255, 255, 255, 0.05);
  --button-hover: #1e211f;
  --accent: #5fc946;
  --accent-strong: #51b53c;
  --operator: #1a1d1a;
  --scientific: #181b18;
  --utility: #181b18;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
  --sheet-shadow: 0 -22px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  position: relative;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top right, rgba(95, 201, 70, 0.09), transparent 24%),
    radial-gradient(circle at bottom left, rgba(95, 201, 70, 0.06), transparent 20%),
    linear-gradient(180deg, var(--bg-top), var(--bg-middle) 45%, var(--bg-bottom));
}

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

.calculator-layout {
  width: min(100%, 980px);
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(300px, 360px);
  gap: 18px;
  align-items: stretch;
}

#calculator,
.history-panel {
  border: 1px solid var(--card-border);
  border-radius: 30px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

#calculator {
  position: relative;
  overflow: visible;
  width: 100%;
  padding: 22px 20px 20px;
}

#calculator::before {
  content: "";
  position: absolute;
  inset: auto -20% 72% auto;
  width: 210px;
  height: 210px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(95, 201, 70, 0.16), transparent 68%);
  pointer-events: none;
}

.hero-copy,
.display-panel,
.button-container {
  position: relative;
  z-index: 1;
}

.hero-copy-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.title {
  margin: 0 0 18px;
  font-size: clamp(1.05rem, 3vw, 1.4rem);
  letter-spacing: -0.03em;
  font-weight: 600;
}

.quick-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.quick-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font: inherit;
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.quick-action-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(95, 201, 70, 0.2);
}

.quick-action-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #081108;
  font-weight: 700;
  min-width: 56px;
}

.quick-action-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}

.menu-shell {
  position: relative;
}

.menu-shell[open] {
  z-index: 30;
}

.menu-toggle {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.menu-toggle::-webkit-details-marker {
  display: none;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(16, 19, 17, 0.98);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.menu-link {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text-main);
  text-decoration: none;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.menu-link:hover {
  background: rgba(95, 201, 70, 0.1);
  color: var(--accent);
}

.display-panel {
  margin-bottom: 16px;
  padding: 14px 4px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: var(--display-bg);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-toggle,
.history-toggle,
.status-pill {
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mode-toggle,
.history-toggle {
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 13px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.mode-toggle:hover,
.history-toggle:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(95, 201, 70, 0.2);
}

.history-toggle {
  display: none;
}

.status-pill {
  padding: 7px 10px;
  color: rgba(95, 201, 70, 0.9);
  background: rgba(95, 201, 70, 0.08);
  font-weight: 700;
}

.expression {
  min-height: 30px;
  margin-bottom: 10px;
  color: var(--text-main);
  text-align: right;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  word-break: break-all;
}

#display {
  width: 100%;
  border: none;
  padding: 0;
  background: transparent;
  color: rgba(245, 247, 243, 0.42);
  text-align: right;
  font-size: clamp(1.4rem, 5vw, 2.3rem);
  font-weight: 500;
  outline: none;
  box-shadow: none;
}

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

.button {
  min-height: 64px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text-main);
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 500;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease;
  touch-action: manipulation;
}

.button:hover {
  transform: translateY(-1px);
  background: var(--button-hover);
  border-color: rgba(95, 201, 70, 0.15);
}

.button:active {
  transform: scale(0.97);
}

.button-operator,
.button-scientific,
.button-utility {
  color: var(--accent);
}

.button-equals {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #081108;
  font-size: 1.5rem;
  font-weight: 700;
}

.button-zero {
  grid-column: span 2;
}

.mode-rad {
  color: #081108;
  background: linear-gradient(180deg, #b6f88f, #6fda51);
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-height: 760px;
  padding: 20px 18px;
}

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

.history-label {
  margin: 0 0 4px;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.history-title {
  margin: 0;
  font-size: 1.12rem;
}

.clear-history-button {
  border: none;
  border-radius: 999px;
  min-height: 46px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #081108;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.clear-history-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.history-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
  scroll-behavior: smooth;
}

.history-list::-webkit-scrollbar {
  width: 7px;
}

.history-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.history-item,
.history-empty {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 22px;
  padding: 14px 15px;
  background: #131613;
  color: var(--text-main);
}

.history-item {
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  background: #171b17;
  border-color: rgba(95, 201, 70, 0.16);
}

.history-item-expression {
  display: block;
  margin-bottom: 6px;
  color: rgba(245, 247, 243, 0.8);
  font-size: 0.92rem;
}

.history-item-result {
  display: block;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
}

.history-empty {
  color: var(--text-soft);
  text-align: center;
}

.pdf-export-sheet {
  position: fixed;
  left: -99999px;
  top: 0;
  width: 210mm;
  padding: 0;
  pointer-events: none;
  z-index: -1;
  background: #f4f6f8;
  color: #14202b;
  box-sizing: border-box;
}

.pdf-export-sheet.is-exporting {
  left: -10000px;
  top: 0;
  opacity: 1;
  z-index: -1;
}

body.printing-history .pdf-export-sheet {
  left: -10000px;
  top: 0;
  opacity: 1;
  z-index: -1;
}

.pdf-export-card {
  width: 100%;
  min-height: auto;
  padding: 18mm 16mm 18mm;
  background: #ffffff;
  box-sizing: border-box;
}

.pdf-export-header {
  margin-bottom: 30px;
  text-align: center;
}

.pdf-export-logo {
  display: block;
  width: 50px;
  height: 50px;
  margin: 0 auto 14px;
  object-fit: contain;
}

.pdf-export-rule {
  height: 2px;
  margin: 18px auto 0;
  background: linear-gradient(90deg, rgba(20, 32, 43, 0.1), rgba(20, 32, 43, 0.4), rgba(20, 32, 43, 0.1));
}

.pdf-export-title {
  margin: 0;
  color: #14202b;
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.pdf-export-subtitle,
.pdf-export-summary,
.pdf-export-datetime {
  margin: 8px 0 0;
  color: #607080;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}

.pdf-export-summary {
  color: #223240;
  font-size: 15px;
  font-weight: 600;
}

.pdf-export-list {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin-top: 26px;
}

.pdf-export-group {
  display: grid;
  gap: 12px;
}

.pdf-export-group-title {
  margin: 0;
  color: #223240;
  font-size: 17px;
  font-weight: 700;
}

.pdf-export-group-items {
  display: grid;
  gap: 14px;
}

.pdf-export-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 16px 18px;
  border: 1px solid rgba(20, 32, 43, 0.08);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 28px rgba(20, 32, 43, 0.06);
  break-inside: avoid;
  page-break-inside: avoid;
}

.pdf-export-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 999px;
  background: rgba(95, 201, 70, 0.12);
  color: #24711a;
  font-size: 14px;
  font-weight: 700;
}

.pdf-export-item-content {
  min-width: 0;
}

.pdf-export-item-date,
.pdf-export-expression,
.pdf-export-result,
.pdf-export-empty,
.pdf-export-footer {
  margin: 0;
}

.pdf-export-item-date {
  color: #7f8b96;
  font-size: 12px;
  font-weight: 500;
}

.pdf-export-expression {
  margin-top: 6px;
  color: #223240;
  font-size: 16px;
  line-height: 1.55;
  word-break: break-word;
}

.pdf-export-result {
  margin-top: 8px;
  color: #24711a;
  font-size: 18px;
  font-weight: 700;
}

.pdf-export-empty {
  padding: 34px 28px;
  border: 1px dashed rgba(20, 32, 43, 0.16);
  border-radius: 20px;
  color: #607080;
  text-align: center;
  background: rgba(255, 255, 255, 0.84);
}

.pdf-export-footer {
  margin-top: 24px;
  color: #7f8b96;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
}

.info-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.info-shell {
  width: min(100%, 760px);
}

.info-card {
  padding: 28px 24px;
  border: 1px solid var(--card-border);
  border-radius: 30px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.info-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  text-decoration: none;
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.back-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
}

.info-title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.info-subtitle {
  margin: 0 0 18px;
  color: var(--text-soft);
  font-size: 0.98rem;
}

.info-content {
  display: grid;
  gap: 14px;
  color: rgba(245, 247, 243, 0.9);
  line-height: 1.7;
}

.info-content p,
.info-content li {
  margin: 0;
}

.info-content ul {
  margin: 0;
  padding-left: 20px;
}

.info-highlight {
  padding: 16px 18px;
  border: 1px solid rgba(95, 201, 70, 0.12);
  border-radius: 20px;
  background: rgba(95, 201, 70, 0.06);
}

.mobile-toolbar,
.mobile-stage {
  display: none;
}

@media (max-width: 768px) {
  .app-shell {
    display: block;
    padding: 10px 10px 28px;
  }

  .calculator-layout {
    grid-template-columns: 1fr;
    width: min(100%, 390px);
    gap: 0;
    margin: 0 auto;
  }

  #calculator {
    min-width: 0;
    min-height: calc(100vh - 38px);
    padding: 16px 14px 20px;
    border-radius: 28px;
  }

  #calculator::before {
    display: none;
  }

  .title {
    margin-bottom: 14px;
    font-size: 1rem;
    color: rgba(245, 247, 243, 0.8);
  }

  .quick-actions {
    gap: 8px;
  }

  .quick-action-button {
    min-height: 32px;
    padding: 7px 11px;
    font-size: 0.72rem;
  }

  .menu-toggle {
    min-width: 32px;
    min-height: 32px;
  }

  .menu-dropdown {
    position: fixed;
    top: 58px;
    right: 14px;
    min-width: 170px;
  }

  .display-panel {
    margin-bottom: 14px;
    padding: 8px 2px 16px;
  }

  .status-row {
    margin-bottom: 16px;
  }

  .status-pill {
    display: none;
  }

  .history-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .expression {
    min-height: 56px;
    margin-bottom: 10px;
    font-size: clamp(2rem, 9vw, 3.3rem);
  }

  #display {
    font-size: clamp(1.3rem, 6vw, 2rem);
  }

  .button-container,
  .history-panel,
  .title,
  .status-row .history-toggle {
    display: none;
  }

  .mobile-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    padding: 2px 0 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  }

  .mobile-tool-button {
    min-height: 40px;
    border: none;
    border-radius: 999px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.04);
    color: rgba(245, 247, 243, 0.84);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
  }

  .mobile-tool-button.history-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
  }

  .mobile-stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 78px;
    gap: 12px;
    align-items: stretch;
    min-height: 420px;
  }

  .mobile-panels {
    position: relative;
    border-right: 1px solid rgba(255, 255, 255, 0.09);
    min-width: 0;
    overflow: hidden;
  }

  .mobile-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    min-width: 0;
    padding-right: 12px;
    transition: transform 0.32s ease, opacity 0.24s ease;
  }

  .mobile-keypad-wrapper {
    display: grid;
    grid-template-columns: 0 minmax(0, 1fr);
    gap: 12px;
    transition: grid-template-columns 0.3s ease;
  }

  body.mobile-scientific-open .mobile-keypad-wrapper {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .mobile-scientific-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-18px);
    transition: transform 0.28s ease, opacity 0.22s ease;
    overflow: hidden;
  }

  body.mobile-scientific-open .mobile-scientific-grid {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

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

  .mobile-calc-button,
  .mobile-rail-button {
    min-height: 74px;
    font-size: 1.5rem;
    border-radius: 999px;
  }

  .mobile-calc-button.button-utility {
    color: #ff6b6b;
  }

  .mobile-history-panel {
    display: flex;
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
  }

  .mobile-history-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100%;
    padding: 6px 0 0;
  }

  .mobile-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 6px;
    max-height: 360px;
  }

  .mobile-history-list::-webkit-scrollbar {
    width: 6px;
  }

  .mobile-history-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
  }

  .mobile-history-list .history-item,
  .mobile-history-list .history-empty {
    padding: 8px 0;
    border: none;
    border-radius: 0;
    background: transparent;
  }

  .mobile-history-list .history-item {
    text-align: right;
  }

  .mobile-history-list .history-item-expression {
    margin-bottom: 4px;
    font-size: 0.82rem;
  }

  .mobile-history-list .history-item-result {
    font-size: 0.95rem;
  }

  .mobile-clear-history-button {
    align-self: flex-start;
    min-width: 180px;
    margin-top: 14px;
  }

  body.mobile-history-open .mobile-keypad-panel {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
  }

  body.mobile-history-open .mobile-history-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-operator-rail {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-rail-button {
    width: 100%;
  }

  .mobile-rail-button.button-operator {
    color: var(--accent);
  }

  .mobile-rail-button.button-equals {
    font-size: 2rem;
  }

  body.mobile-history-open #history-toggle,
  body.mobile-history-open #mobile-history-toggle {
    color: #081108;
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  }

  body.mobile-scientific-open #mobile-scientific-toggle {
    color: #081108;
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  }
}

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

  #calculator {
    min-height: calc(100vh - 32px);
    padding: 15px 12px 18px;
    border-radius: 24px;
  }

  .status-actions {
    gap: 8px;
  }

  .mode-toggle,
  .history-toggle {
    padding: 8px 11px;
    font-size: 0.66rem;
  }

  .hero-copy-top {
    gap: 12px;
  }

  .mobile-tool-button {
    min-height: 38px;
    padding-inline: 12px;
    font-size: 0.72rem;
  }

  .mobile-stage {
    grid-template-columns: minmax(0, 1fr) 72px;
    gap: 10px;
  }

  .mobile-keypad-grid,
  .mobile-operator-rail,
  .mobile-scientific-grid {
    gap: 10px;
  }

  .mobile-calc-button,
  .mobile-rail-button {
    min-height: 68px;
    font-size: 1.35rem;
  }

  .info-page {
    padding: 14px;
  }

  .info-card {
    padding: 22px 18px;
    border-radius: 24px;
  }

  .info-topbar {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 18px;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-shell,
  script {
    display: none !important;
  }

  .pdf-export-sheet,
  .pdf-export-sheet.is-exporting {
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: auto !important;
    opacity: 1 !important;
    z-index: auto !important;
    pointer-events: auto !important;
    background: #ffffff !important;
  }

  .pdf-export-card {
    min-height: auto;
    padding: 0;
    background: #ffffff;
    box-shadow: none;
  }
}
