:root {
  color-scheme: dark;
  --bg: #101216;
  --device: #252932;
  --key: #363c49;
  --screen: #dceac0;
  --screen-ink: #1b2b18;
  --text: #f7f1e5;
  --line: rgba(255, 255, 255, 0.16);
  --danger: #ff6258;
  --amber: #ffd166;
  --teal: #49d3c7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background:
    radial-gradient(circle at 18% 10%, rgba(73, 211, 199, 0.18), transparent 28rem),
    radial-gradient(circle at 88% 92%, rgba(255, 98, 88, 0.12), transparent 30rem),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

.app {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
  touch-action: none;
}

.calculator {
  width: min(420px, calc(100vw - 16px));
  height: min(690px, calc(100dvh - 16px));
  min-height: 520px;
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: clamp(8px, 1.5dvh, 14px);
  padding: clamp(14px, 2.8dvh, 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 34%),
    var(--device);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.42), inset 0 -9px 0 rgba(0, 0, 0, 0.2);
  overflow: hidden;
  touch-action: none;
}

.calculator::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  pointer-events: none;
}

.device-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 26px;
}

.device-top h1 {
  margin: 0;
  color: rgba(247, 241, 229, 0.86);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(0.72rem, 2.6vw, 0.86rem);
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

.solar-strip {
  width: clamp(92px, 29vw, 118px);
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 18px),
    linear-gradient(180deg, #14181d, #0c0f13);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.08);
}

.display-wrap {
  display: block;
  width: 100%;
  border: 6px solid #0b0d10;
  border-radius: 8px;
  overflow: hidden;
  background: var(--screen);
}

.display {
  display: grid;
  place-items: center end;
  height: clamp(82px, 16dvh, 118px);
  padding: 10px 18px;
  overflow: hidden;
  background:
    repeating-linear-gradient(0deg, rgba(27, 43, 24, 0.08), rgba(27, 43, 24, 0.08) 1px, transparent 1px, transparent 5px),
    var(--screen);
  color: var(--screen-ink);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(2.7rem, 16vw, 5.1rem);
  font-weight: 900;
  line-height: 1;
  text-align: right;
  text-shadow: 2px 2px 0 rgba(27, 43, 24, 0.12);
}

.display.is-art {
  place-items: center;
  font-size: clamp(2.5rem, 13.5vw, 4.55rem);
  letter-spacing: 0;
  text-align: center;
  animation: reveal 420ms cubic-bezier(.16, 1, .3, 1);
}

.display.is-broken {
  animation: glitch 360ms ease-in-out;
}

.status {
  height: clamp(28px, 5dvh, 42px);
  margin: 0;
  overflow: hidden;
  color: var(--amber);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(0.68rem, 2.5vw, 0.84rem);
  line-height: 1.35;
  text-transform: uppercase;
}

.keys {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(7px, 1.3dvh, 10px);
}

.key {
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  background: var(--key);
  color: var(--text);
  cursor: pointer;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.28), 0 5px 0 rgba(0, 0, 0, 0.15);
  font-size: clamp(1.05rem, 4vw, 1.28rem);
  font-weight: 900;
  transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
  touch-action: manipulation;
}

.key:hover {
  filter: brightness(1.08);
}

.key:active {
  transform: translateY(3px);
}

.key.operator {
  background: #2f7778;
}

.key.utility {
  background: #626977;
}

.key.equals {
  background: var(--danger);
  color: #21110f;
}

.key.wide {
  grid-column: span 2;
}

.calculator.is-revealed {
  animation: guilty 700ms ease both;
}

.calculator.is-locked .keys {
  pointer-events: none;
}

.calculator.is-locked .key {
  cursor: default;
  filter: saturate(0.75);
}

@keyframes glitch {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-5px) skewX(-5deg); }
  48% { transform: translateX(4px) skewX(3deg); }
  72% { transform: translateX(-2px); }
}

@keyframes reveal {
  from { transform: scale(0.88); filter: blur(2px); }
  to { transform: scale(1); filter: blur(0); }
}

@keyframes guilty {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-1.2deg); }
  65% { transform: rotate(0.9deg); }
}

@media (max-height: 590px) {
  .calculator {
    min-height: 0;
  }

  .device-top {
    min-height: 22px;
  }

  .solar-strip {
    height: 20px;
  }

  .display {
    height: 72px;
  }

  .status {
    height: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
