/* ===== TASCHENRECHNER — TI-30X Pro MathPrint Style ===== */

:root {
  --body-bg:      #1c1c1e;
  --display-bg:   #b8c8a8;
  --display-text: #1a2a10;
  --btn-num:      #2d2d2d;
  --btn-sci:      #242424;
  --btn-2nd:      #4a90d9;
  --btn-eq:       #2c3e5a;
  --label-2nd:    #5a9fd4;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #08080f;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

/* ---- Wrapper ---- */
.calc-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100dvh;
  padding: 8px;
}

/* ---- Body ---- */
.calc-body {
  font-size: clamp(12px, 1.6vmin, 19px);
  width: 27em;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  scrollbar-width: none;

  background: var(--body-bg);
  border: 1px solid #2e2e2e;
  border-radius: 1.2em 1.2em 2em 2em;
  box-shadow:
    0 0 0 3px #0a0a0a,
    0 0.6em 3em rgba(0,0,0,0.6);
  padding: 0.7em 0.9em 1.2em;
  user-select: none;
}
.calc-body::-webkit-scrollbar { display: none; }

/* ---- Solar Panel ---- */
.calc-solar {
  display: flex;
  gap: 0.2em;
  padding-bottom: 0.45em;
}
.solar-cell {
  flex: 1;
  height: 0.7em;
  background: #1a1a2e;
  border-radius: 0.1em;
  border: 1px solid #0d0d1e;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}

/* ---- Brand ---- */
.calc-brand {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  padding-bottom: 0.4em;
  border-bottom: 1px solid #2a2a2a;
  margin-bottom: 0.4em;
}
.brand-name {
  font-size: 1em;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #d0d0d0;
  text-transform: uppercase;
}
.brand-sub {
  font-size: 0.7em;
  color: #888;
  letter-spacing: 0.04em;
}

/* ---- Display ---- */
.calc-display {
  background: var(--display-bg);
  border: 2px solid #8a9878;
  border-radius: 0.4em;
  box-shadow:
    inset 0 0.12em 0.5em rgba(0,0,0,0.2),
    inset 0 0 1em rgba(80,100,60,0.12);
  padding: 0.35em 0.65em 0.5em;
  margin-bottom: 0.85em;
  min-height: 8em;
  display: flex;
  flex-direction: column;
  gap: 0.12em;
}

/* ---- Status Row (inside display) ---- */
.display-status-row {
  display: flex;
  gap: 0.6em;
  font-family: 'Courier New', monospace;
  font-size: 0.62em;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--display-text);
  min-height: 1em;
}
.display-status-row #status2nd { color: #1e5a9a; font-weight: 700; }
.display-status-row .status-scroll {
  margin-left: auto;
  letter-spacing: 0.08em;
}

/* ---- History ---- */
.display-history {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.1em;
  min-height: 1.8em;
}
.history-entry {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4em;
  opacity: 0.42;
  font-size: 0.78em;
  color: var(--display-text);
  overflow: hidden;
}
.history-entry .h-expr { flex: 1; text-align: right; overflow: hidden; }
.history-entry .h-res  { color: var(--display-text); white-space: nowrap; font-family: 'Courier New', monospace; }

/* ---- Expression ---- */
.display-expr {
  min-height: 1.8em;
  color: var(--display-text);
  font-size: 1.3em;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  flex-wrap: wrap;
  gap: 1px;
}
.display-expr::-webkit-scrollbar { display: none; }
.display-expr .katex            { color: var(--display-text) !important; font-size: 1em; }
.display-expr .katex-html       { color: var(--display-text) !important; }
.display-expr .katex-display    { display: inline; margin: 0; }

/* ---- Result ---- */
.display-result {
  color: var(--display-text);
  font-size: 1.65em;
  font-weight: 400;
  text-align: right;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.02em;
  word-break: break-all;
}

/* ---- KaTeX overrides (dark ink on LCD) ---- */
.katex .mfrac .frac-line { border-color: var(--display-text) !important; }
.katex .mord, .katex .mbin, .katex .mrel,
.katex .mopen, .katex .mclose, .katex .minner,
.katex .mpunct, .katex .mop { color: var(--display-text) !important; }
.katex .sqrt > .sqrt-sign        { color: var(--display-text) !important; }
.katex .overline .overline-line  { border-color: var(--display-text) !important; }

/* ---- Blinking Cursor ---- */
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.calc-cursor {
  display: inline-block;
  width: 0.06em;
  height: 1em;
  background: var(--display-text);
  animation: blink 1s step-end infinite;
  vertical-align: middle;
  margin-left: 1px;
}

/* ---- History view mode ---- */
.mode-histview .calc-display {
  border-color: #7a9068;
}
.mode-histview .display-expr .calc-cursor { display: none; }
.history-pos {
  text-align: center;
  font-size: 0.75em;
  color: var(--display-text);
  opacity: 0.65;
  letter-spacing: 0.08em;
}

/* ---- Button Grid ---- */
.calc-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35em;
}

/* ---- Nav Pad (compound element, spans rows 1–2 cols 4–5) ---- */
.btn-nav-pad {
  grid-column: 4 / 6;
  grid-row: 1 / 3;
  background: #303030;
  border-radius: 2.2em;
  overflow: hidden;
  display: grid;
  grid-template-areas:
    ". up ."
    "left mid right"
    ". down .";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  border: 1px solid #404040;
  box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}
.nav-btn {
  background: transparent;
  border: none;
  color: #a0a0a0;
  cursor: pointer;
  font-size: 0.7em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.1s, transform 0.08s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: 0;
  height: 100%;
  width: 100%;
  border-radius: 0;
  box-shadow: none;
  position: static;
  font-weight: 600;
}
.nav-btn:active {
  transform: scale(0.85);
  filter: brightness(1.6);
  background: rgba(255,255,255,0.08);
}
.nav-up    { grid-area: up; }
.nav-left  { grid-area: left; }
.nav-center {
  grid-area: mid;
  background: #3e3e3e;
  border-radius: 50%;
  pointer-events: none;
  cursor: default;
}
.nav-right { grid-area: right; }
.nav-down  { grid-area: down; }

/* ---- Base Button ---- */
.calc-buttons button {
  position: relative;
  border: none;
  border-radius: 0.42em;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 600;
  padding: 0;
  height: 2.7em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.1s, transform 0.08s;
  outline: none;
  letter-spacing: 0.02px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}
.calc-buttons button:active {
  transform: scale(0.93);
  filter: brightness(1.3);
}

/* secondary label (top of button) */
.calc-buttons button[data-2nd]:not(.no-2nd-label)::before {
  content: attr(data-2nd);
  position: absolute;
  top: 0.18em;
  left: 0; right: 0;
  font-size: 0.58em;
  font-weight: 500;
  color: var(--label-2nd);
  text-align: center;
  letter-spacing: 0.01em;
  pointer-events: none;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.2em;
}
/* push main label toward bottom so it doesn't overlap the secondary */
.calc-buttons button[data-2nd]:not(.no-2nd-label) {
  align-items: flex-end;
  padding-bottom: 0.32em;
}

/* ---- Button Color Classes ---- */
.btn-num {
  background: var(--btn-num);
  color: #d4d4d4;
}
.btn-num:hover { background: #383838; }

.btn-op {
  background: #20284a;
  color: #90aad0;
  font-size: 1.05em;
}
.btn-op:hover { background: #283260; }

.btn-eq {
  background: var(--btn-eq);
  color: #c8d4e8;
  font-size: 1.15em;
  font-weight: 700;
}
.btn-eq:hover { background: #384e72; }

.btn-2nd {
  background: var(--btn-2nd);
  color: #fff;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.btn-2nd:hover { background: #5aa2e8; }

.btn-sci {
  background: var(--btn-sci);
  color: #b0b0b0;
}
.btn-sci:hover { background: #303030; }

/* ---- 2nd Mode Highlight ---- */
.calc-body.mode-2nd .btn-2nd {
  background: #3870c0;
  color: #fff;
  box-shadow: 0 0 0.5em rgba(74,144,217,0.45), 0 2px 0 rgba(0,0,0,0.5);
}
.calc-body.mode-2nd button[data-2nd]::before {
  color: #6ab4ec;
  font-weight: 700;
  font-size: 0.65em;
}
.calc-body.mode-2nd button[data-2nd] {
  border-top: 1.5px solid rgba(74,144,217,0.35);
}

/* ---- Mobile: short screens ---- */
@media (max-height: 580px) {
  .calc-body { font-size: clamp(9px, 1.4vh, 13px); }
  .calc-brand { padding-bottom: 0.3em; margin-bottom: 0.3em; }
  .calc-display { min-height: 6em; margin-bottom: 0.5em; }
}

@media (max-width: 360px) {
  .calc-body { font-size: clamp(10px, 3.8vw, 13px); border-radius: 0.8em; }
}
