/* TI-83+ inspired scientific calculator — mobile-first PWA */

:root {
  --body: #3f4750;          /* faceplate gray-blue */
  --body-edge: #2c3138;
  --lcd: #a8b48c;           /* classic greenish LCD */
  --lcd-dark: #2b331f;
  --lcd-faint: #97a37b;
  --key-num: #d9dce1;
  --key-fn: #b9c1cc;
  --key-op: #7f96b4;
  --key-mod: #4d5866;
  --key-enter: #2f6db3;
  --second: #f4b63f;        /* TI 2nd-key yellow */
  --key-text: #14181d;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #22262b;
  font-family: "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

#calc {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bezel {
  width: 100%;
  max-width: 420px;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, var(--body) 0%, var(--body-edge) 100%);
  padding: 10px 12px 12px;
  gap: 8px;
}

@media (min-width: 480px) {
  #calc { padding: 24px; }
  #bezel {
    height: auto;
    max-height: 92dvh;
    border-radius: 28px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.12);
  }
}

#brand {
  color: #cfd6de;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
  flex: none;
}

/* ------------------------------------------------------------- LCD screen */

#screen {
  flex: 1 1 34%;
  min-height: 160px;
  overflow-y: auto;
  background: var(--lcd);
  border-radius: 6px;
  border: 3px solid #23272c;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45);
  color: var(--lcd-dark);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 4px 8px 6px;
  scrollbar-width: thin;
}

#status-bar {
  position: sticky;
  top: -4px;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: rgba(43, 51, 31, 0.75);
  padding: 2px 0;
  background: var(--lcd);
}

#second-indicator { visibility: hidden; color: #8a5a00; }

.hist-expr {
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.35;
}

.hist-result {
  text-align: right;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.35;
  margin-bottom: 4px;
  cursor: pointer;
}

.hist-result:active { background: var(--lcd-faint); }

.hist-error { color: #7a2d12; }

#entry {
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
  min-height: 1.4em;
  border-top: 1px dashed rgba(43, 51, 31, 0.35);
  padding-top: 3px;
}

.caret {
  animation: blink 1.1s steps(1) infinite;
  color: var(--lcd-dark);
}

@keyframes blink {
  0%, 55% { opacity: 1; }
  56%, 100% { opacity: 0; }
}

/* --------------------------------------------------------------- keypad */

#keypad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 52px;
  padding: 3px 2px 5px;
  border: none;
  border-radius: 9px;
  background: var(--key-fn);
  color: var(--key-text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}

.key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  filter: brightness(0.92);
}

.key-second {
  font-size: 0.55rem;
  font-weight: 700;
  color: #7a5200; /* dark amber — readable on light keys; dark keys override below */
  min-height: 0.75rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.key-main { line-height: 1.15; }

.key-num { background: var(--key-num); }
.key-fn  { background: var(--key-fn); }
.key-op  { background: var(--key-op); color: #10141a; }
.key-mod { background: var(--key-mod); color: #e8ecf1; }
.key-mod .key-second { color: var(--second); }
.key-enter { background: var(--key-enter); color: #f2f6fb; }
.key-enter .key-second { color: var(--second); }

/* when 2nd is armed, highlight the whole pad subtly */
.second-armed .key { outline: 2px solid rgba(244, 182, 63, 0.55); }
.second-armed .key-main { opacity: 0.45; }
.second-armed .key-second { font-size: 0.8rem; }

@media (max-height: 620px) {
  .key { min-height: 44px; font-size: 0.95rem; }
  #screen { min-height: 120px; }
}
