.calc-layout-wrapper {
  display: flex;
  gap: 0;
  align-items: stretch;
  width: 100%;
  transition: gap 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-container.sci-open .calc-layout-wrapper {
  gap: 18px;
}

.calc-card {
  flex: 1;
  width: 100%;
  min-width: 0;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--panel-shadow);
  padding: 20px 20px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
}

/* --------------------------------------------------------------------------
   Right-side Expandable Scientific Calculation Guide Panel
   -------------------------------------------------------------------------- */
.sci-guide-panel {
  width: 0;
  max-width: 0;
  opacity: 0;
  transform: translateX(30px);
  pointer-events: none;
  visibility: hidden;
  overflow: hidden;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0;
  border-radius: var(--radius-xl);
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition:
    max-width 0.38s cubic-bezier(0.16, 1, 0.3, 1),
    width 0.38s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.28s ease,
    transform 0.38s cubic-bezier(0.16, 1, 0.3, 1),
    border-color 0.28s ease,
    padding 0.38s ease;
  padding: 0;
  margin: 0;
}

.sci-guide-panel.open {
  width: 580px;
  max-width: 600px;
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  visibility: visible;
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
  padding: 24px 26px;
}

.sci-guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 14px;
}

.sci-guide-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sci-guide-title svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-accent);
}

.sci-guide-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  max-height: 560px;
  padding-right: 8px;
}

.sci-guide-body::-webkit-scrollbar {
  width: 6px;
}
.sci-guide-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-full);
}

/* Guide Section Cards */
.guide-card {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.guide-card:hover {
  border-color: rgba(99, 102, 241, 0.45);
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

.guide-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.guide-badge-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.guide-key-badge {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--btn-fn-bg);
  border: 1px solid var(--btn-fn-border);
  color: var(--text-accent);
  padding: 4px 11px;
  border-radius: var(--radius-sm);
}

.guide-cat-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.guide-desc {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.guide-chip-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.guide-example-chip {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.28);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all var(--transition-fast);
}

.guide-example-chip:hover {
  background: rgba(99, 102, 241, 0.28);
  border-color: var(--text-accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.guide-example-chip:active {
  transform: translateY(1px);
}

.guide-example-chip .chip-arrow {
  color: var(--text-accent);
  font-weight: 700;
}

.guide-tip-box {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.guide-tip-icon {
  font-size: 1.1rem;
  color: #10b981;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Subtle corner highlight */
.calc-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Display Screen (Retro Digital Calculator / VFD / LCD Glass Look)
   -------------------------------------------------------------------------- */
.calc-display {
  background: var(--lcd-bg, #050d07);
  background-image: radial-gradient(ellipse at 50% 0%, #0a180e 0%, #040805 100%);
  border: 1px solid var(--lcd-border, rgba(0, 255, 102, 0.22));
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 125px;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 4px 14px rgba(0, 0, 0, 0.95),
    inset 0 0 0 1px rgba(0, 255, 102, 0.12),
    inset 0 1px 1px rgba(255, 255, 255, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.35);
  transition: all var(--transition-fast);
}

/* Subtle top reflection glare */
.calc-display::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 102, 0.4), transparent);
  pointer-events: none;
  z-index: 3;
}

/* Subtle digital scanline / LCD glass texture */
.calc-display::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.25) 3px,
    transparent 4px
  );
  pointer-events: none;
  opacity: 0.5;
  z-index: 1;
}

.display-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.75rem;
  color: var(--lcd-green-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: relative;
  z-index: 2;
}

.meta-badges {
  display: flex;
  gap: 6px;
}

.mode-badge {
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: rgba(0, 255, 102, 0.08);
  border: 1px solid rgba(0, 255, 102, 0.18);
  color: var(--lcd-green-dim);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
  font-family: var(--font-mono);
}

.mode-badge:hover {
  background: rgba(0, 255, 102, 0.16);
  color: var(--lcd-green-bright);
}

.mode-badge.active {
  background: rgba(0, 255, 102, 0.22);
  color: var(--lcd-green-bright);
  border-color: rgba(0, 255, 102, 0.5);
  box-shadow: 0 0 8px rgba(0, 255, 102, 0.25);
}

/* Formula & Result typography using REGISTER.TTF */
.display-formula {
  font-family: var(--font-calc);
  font-size: 1.15rem;
  color: var(--lcd-green-dim);
  text-shadow: 0 0 6px var(--lcd-green-glow);
  letter-spacing: 0.04em;
  text-align: right;
  word-break: break-all;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  min-height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  z-index: 2;
  transition: color var(--transition-fast);
}

.display-formula::-webkit-scrollbar {
  display: none;
}

.display-preview {
  font-family: var(--font-calc);
  font-size: 1rem;
  color: var(--lcd-green-faint);
  text-shadow: 0 0 4px rgba(0, 255, 102, 0.25);
  letter-spacing: 0.03em;
  text-align: right;
  min-height: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  z-index: 2;
  font-weight: 500;
  opacity: 0.85;
}

.display-preview.has-preview::before {
  content: '= ';
  opacity: 0.6;
}

/* Number Display Row with Left/Right Scroll Buttons */
.display-main-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  position: relative;
  z-index: 2;
  margin-top: 2px;
}

.display-main {
  flex: 1;
  min-width: 0;
  font-family: var(--font-calc);
  font-size: 2.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--lcd-green-bright);
  text-shadow:
    0 0 10px var(--lcd-green-glow),
    0 0 22px rgba(0, 255, 102, 0.25);
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  line-height: 1.25;
  scroll-behavior: smooth;
  cursor: text;
}

.display-main::-webkit-scrollbar {
  display: none;
}

/* Left/Right Scroll Indicator Buttons */
.display-scroll-btn {
  width: 26px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(0, 255, 102, 0.04);
  border: 1px solid rgba(0, 255, 102, 0.12);
  color: var(--lcd-green-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
  user-select: none;
}

.display-scroll-btn.can-scroll {
  opacity: 0.78;
  pointer-events: auto;
  background: rgba(0, 255, 102, 0.12);
  border-color: rgba(0, 255, 102, 0.4);
  color: var(--lcd-green-bright);
  box-shadow: 0 0 10px rgba(0, 255, 102, 0.25);
}

.display-scroll-btn.can-scroll:hover {
  opacity: 1;
  background: rgba(0, 255, 102, 0.24);
  border-color: var(--lcd-green-bright);
  box-shadow: 0 0 16px rgba(0, 255, 102, 0.5);
  transform: scale(1.08);
}

.display-scroll-btn.can-scroll:active {
  transform: scale(0.92);
  background: rgba(0, 255, 102, 0.35);
}

/* --------------------------------------------------------------------------
   Keypad & Controls
   -------------------------------------------------------------------------- */
.calc-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px;
}

.sci-toggle-btn {
  background: var(--btn-fn-bg);
  border: 1px solid var(--btn-fn-border);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.sci-toggle-btn .sci-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-accent);
  font-size: 0.85rem;
}

.sci-toggle-btn .sci-btn-text {
  letter-spacing: -0.01em;
}

.sci-toggle-btn .sci-chevron {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  transition: transform var(--transition-normal);
}

.sci-toggle-btn:hover {
  color: var(--text-primary);
  background: var(--btn-fn-hover);
  border-color: var(--text-accent);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
  transform: translateY(-1px);
}

.sci-toggle-btn.active {
  background: var(--btn-op-bg);
  color: var(--text-accent);
  border-color: var(--btn-op-border);
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.35);
}

.sci-toggle-btn.active .sci-chevron {
  transform: rotate(90deg);
}

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

.quick-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.quick-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.quick-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

/* --------------------------------------------------------------------------
   Scientific Row (Expandable - Shadow cutoff fixed with padding & overflow: visible)
   -------------------------------------------------------------------------- */
.scientific-panel {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0 4px;
  margin-top: -10px;
  pointer-events: none;
  transition:
    max-height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.25s ease,
    margin 0.25s ease,
    padding 0.25s ease;
}

.scientific-panel.open {
  max-height: 240px;
  opacity: 1;
  margin-top: 6px;
  margin-bottom: 8px;
  padding: 6px 4px 10px 4px;
  overflow: visible;
  pointer-events: auto;
}

/* --------------------------------------------------------------------------
   Keypad Grid
   -------------------------------------------------------------------------- */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 2px 2px 6px 2px;
}

/* Button Base */
.key-btn {
  position: relative;
  height: 56px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  outline: none;
  border: 1px solid transparent;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
}

.key-btn:active, .key-btn.is-pressed {
  transform: scale(0.94) translateY(2px);
}

/* Key Variants */
.key-num {
  background: var(--btn-num-bg);
  border-color: var(--btn-num-border);
  color: var(--btn-num-color);
}

.key-num:hover {
  background: var(--btn-num-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

.key-fn {
  background: var(--btn-fn-bg);
  border-color: var(--btn-fn-border);
  color: var(--btn-fn-color);
  font-size: 1.1rem;
}

.key-fn:hover {
  background: var(--btn-fn-hover);
  color: var(--text-primary);
}

.key-sci {
  height: 44px;
  font-size: 0.95rem;
  background: var(--btn-fn-bg);
  border: 1px solid var(--btn-fn-border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.key-sci:hover {
  background: var(--btn-fn-hover);
  color: var(--text-accent);
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.25);
  transform: translateY(-1px);
}

.key-sci:active, .key-sci.is-pressed {
  transform: translateY(1px) scale(0.96);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.key-op {
  background: var(--btn-op-bg);
  border-color: var(--btn-op-border);
  color: var(--btn-op-color);
  font-size: 1.4rem;
  font-weight: 500;
}

.key-op:hover {
  background: var(--btn-op-hover);
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
}

.key-clear {
  color: var(--btn-clear-color);
  background: var(--btn-clear-bg);
  border-color: var(--btn-clear-border);
  font-weight: 700;
}

.key-clear:hover {
  background: rgba(239, 68, 68, 0.25);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.25);
}

.key-equal {
  background: var(--btn-equal-bg);
  color: var(--btn-equal-color);
  box-shadow: var(--btn-equal-shadow);
  font-size: 1.5rem;
  font-weight: 700;
  border: none;
}

.key-equal:hover {
  box-shadow: 0 10px 30px -2px rgba(139, 92, 246, 0.7);
  filter: brightness(1.08);
}

/* Span utilities */
.col-span-2 {
  grid-column: span 2;
}

/* Key label subtext (e.g. Rad/Deg) */
.sub-label {
  font-size: 0.65rem;
  position: absolute;
  bottom: 4px;
  right: 6px;
  opacity: 0.6;
}

/* Keyboard hint badges */
.key-hint {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.show-hints .key-hint {
  opacity: 0.7;
}

/* Responsive sizes */
@media (max-width: 980px) {
  .calc-layout-wrapper {
    flex-direction: column;
  }
  .sci-guide-panel.open {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 440px) {
  .calc-card {
    padding: 16px;
    gap: 14px;
  }
  .key-btn {
    height: 50px;
    font-size: 1.15rem;
  }
  .key-sci {
    height: 40px;
    font-size: 0.85rem;
  }
  .display-main {
    font-size: 2.1rem;
  }
}
