:root {
  --bg-outer: #15171a;
  --chassis-top: #35383f;
  --chassis-bottom: #222429;
  --chassis-border: #4a4e58;
  --lcd-bezel: #17191c;
  --lcd-bg-top: #c7d2b8;
  --lcd-bg-bottom: #b5c3a3;
  --lcd-ink: #1a2417;
  --lcd-ink-muted: rgba(26, 36, 23, 0.62);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 15%, #23262c 0%, var(--bg-outer) 75%);
  color: #f0f2f5;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.app-shell {
  width: 100%;
  max-width: 380px;
}

.calculator {
  background: linear-gradient(180deg, var(--chassis-top) 0%, var(--chassis-bottom) 100%);
  border: 1px solid var(--chassis-border);
  border-radius: 24px;
  padding: 18px 16px 20px;
  box-shadow:
    0 22px 48px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -3px 6px rgba(0, 0, 0, 0.45);
}

/* Header: Brand & decorative solar cell strip */
.chassis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-name {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.12em;
  color: #e6e8ec;
}

.brand-model {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #9ba1ad;
}

.solar-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  width: 72px;
  height: 20px;
  padding: 2px;
  background: #141619;
  border-radius: 4px;
  border: 1px solid #444850;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
}

.solar-panel span {
  background: linear-gradient(180deg, #3c322f 0%, #2a2220 100%);
  border-radius: 1px;
}

/* LCD Screen */
.lcd-bezel {
  background: var(--lcd-bezel);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid #0e1012;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.85),
    0 1px 0 rgba(255, 255, 255, 0.08);
  margin-bottom: 10px;
}

.lcd-screen {
  background: linear-gradient(180deg, var(--lcd-bg-top) 0%, var(--lcd-bg-bottom) 100%);
  color: var(--lcd-ink);
  border-radius: 7px;
  padding: 8px 12px 10px;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow:
    inset 0 2px 5px rgba(20, 32, 16, 0.28),
    inset 0 0 0 1px rgba(26, 36, 23, 0.18);
  font-family: var(--font-mono);
  overflow: hidden;
}

.lcd-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 18px;
  gap: 8px;
}

.memory-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 3px;
  border: 1px solid var(--lcd-ink);
  color: var(--lcd-ink);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.memory-indicator[hidden] {
  display: none;
}

.expression-line {
  margin-left: auto;
  text-align: right;
  font-size: 0.78rem;
  color: var(--lcd-ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lcd-value {
  text-align: right;
  font-size: clamp(1.65rem, 7vw, 2.25rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* History / Tape Strip */
.tape-panel {
  background: #1b1d21;
  border: 1px solid #353841;
  border-radius: 10px;
  padding: 7px 10px;
  margin-bottom: 14px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

.tape-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.tape-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #8f96a3;
}

.tape-clear-btn {
  background: #2b2f37;
  color: #cfd5df;
  border: 1px solid #444954;
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, transform 80ms ease;
}

.tape-clear-btn:hover {
  background: #383d47;
}

.tape-clear-btn:active {
  transform: translateY(1px);
}

.tape-clear-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.tape-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 82px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.tape-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 4px;
  color: #cfd6c6;
  cursor: pointer;
}

.tape-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.tape-expr {
  color: #9ba394;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tape-result {
  color: #d6e4c5;
  font-weight: 700;
  flex-shrink: 0;
}

.tape-empty {
  color: #707784;
  font-size: 0.72rem;
  padding: 2px 0;
  text-align: center;
}

/* CSS Grid Keypad */
.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: minmax(46px, auto);
  gap: 9px;
}

.key {
  position: relative;
  min-width: 44px;
  min-height: 46px;
  padding: 8px 4px;
  border: 0;
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 70ms ease, box-shadow 70ms ease, filter 90ms ease;
}

.key:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* Digits (Light Casio keys) */
.key-digit {
  background: linear-gradient(180deg, #f1f3f5 0%, #dcdfe4 100%);
  color: #1c1f24;
  box-shadow:
    0 4px 0 #9ea4ae,
    0 5px 8px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

/* Operators (Grey Casio keys) */
.key-operator {
  background: linear-gradient(180deg, #5c626d 0%, #444952 100%);
  color: #f4f6f8;
  box-shadow:
    0 4px 0 #2b2e34,
    0 5px 8px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Equals key */
.key-equals {
  background: linear-gradient(180deg, #4b5563 0%, #374151 100%);
  color: #ffffff;
  font-size: 1.2rem;
  box-shadow:
    0 4px 0 #1f252e,
    0 5px 8px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

/* AC / C (Orange/Red Casio clear keys) */
.key-clear {
  background: linear-gradient(180deg, #e7633f 0%, #cc4826 100%);
  color: #ffffff;
  font-size: 0.92rem;
  box-shadow:
    0 4px 0 #8a2c14,
    0 5px 8px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.key-clear-entry {
  background: linear-gradient(180deg, #d86d4f 0%, #b85134 100%);
  color: #ffffff;
  font-size: 0.95rem;
  box-shadow:
    0 4px 0 #7b321d,
    0 5px 8px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* Memory keys (Dark green Casio keys) */
.key-memory {
  min-height: 44px;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #2f6048 0%, #214634 100%);
  color: #eef5f0;
  box-shadow:
    0 4px 0 #142c20,
    0 5px 8px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Spans for Casio-style tall + / = and wide 0 */
.key-wide {
  grid-column: span 2;
}

.key-tall {
  grid-row: span 2;
  min-height: 101px;
}

/* Raised 3D press animation (pointer + keyboard highlight) */
.key:active,
.key.is-pressed {
  transform: translateY(3px);
  filter: brightness(1.06);
}

.key-digit:active,
.key-digit.is-pressed {
  box-shadow:
    0 1px 0 #9ea4ae,
    0 2px 3px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.key-operator:active,
.key-operator.is-pressed {
  box-shadow:
    0 1px 0 #2b2e34,
    0 2px 3px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.key-equals:active,
.key-equals.is-pressed {
  box-shadow:
    0 1px 0 #1f252e,
    0 2px 3px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.key-clear:active,
.key-clear.is-pressed {
  box-shadow:
    0 1px 0 #8a2c14,
    0 2px 3px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.key-clear-entry:active,
.key-clear-entry.is-pressed {
  box-shadow:
    0 1px 0 #7b321d,
    0 2px 3px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.key-memory:active,
.key-memory.is-pressed {
  box-shadow:
    0 1px 0 #142c20,
    0 2px 3px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

@media (max-width: 360px) {
  .calculator {
    padding: 14px 10px 16px;
    border-radius: 20px;
  }

  .keypad {
    gap: 6px;
  }

  .key {
    font-size: 0.94rem;
    border-radius: 8px;
  }

  .key-memory {
    font-size: 0.76rem;
  }
}
