:root {
  --page-bg: radial-gradient(circle at 50% 10%, #f1eee8 0%, #dfdbd2 55%, #d3cec4 100%);
  --shell-top: #f5f3ec;
  --shell-mid: #ebe8df;
  --shell-bot: #d9d4c9;
  --shell-edge: #9a9389;

  --lcd-bezel-top: #cbc8c6;
  --lcd-bezel-bot: #aaa8a6;
  --lcd-bg: #d7dfd2;
  --lcd-seg-off: #c0c8bc;
  --lcd-seg-on: #3f4b44;

  --key-dark-top: #61656a;
  --key-dark-bot: #2f3338;
  --key-dark-edge: #181b1f;
  --key-dark-lip: #23272c;

  --key-red-top: #bd5962;
  --key-red-bot: #8f313a;
  --key-red-edge: #5d1d24;
  --key-red-lip: #6f222b;

  --key-teal-top: #5d8c8d;
  --key-teal-bot: #386368;
  --key-teal-edge: #203b3f;
  --key-teal-lip: #2b4d50;

  --text-main: #1b1f23;
  --focus: #5aa9d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Arial Narrow", "Trebuchet MS", "Verdana", sans-serif;
  background: var(--page-bg);
  color: var(--text-main);
}

.page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.calc-stage {
  position: relative;
  width: min(100%, 380px);
}

.calculator {
  position: relative;
  width: 100%;
  border-radius: 1rem;
  background: linear-gradient(180deg, var(--shell-top) 0%, var(--shell-mid) 58%, var(--shell-bot) 100%);
  border: 2px solid var(--shell-edge);
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 -1px 0 rgba(148, 141, 129, 0.45);
  padding: 1rem 0.9rem 0.9rem;
  transform-origin: 50% 50%;
  transition: transform 380ms cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow 220ms ease;
}

.calculator.is-flipped {
  transform: rotate(180deg);
}

.calc-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.65rem;
  padding: 0 0.1rem;
}

.brand,
.model {
  margin: 0;
  letter-spacing: 0.04em;
}

.brand {
  font-size: 1.55rem;
  font-weight: 800;
}

.model {
  font-size: 0.92rem;
  font-weight: 700;
}

.lcd-wrap {
  border-radius: 0.38rem;
  padding: 0.52rem;
  background: linear-gradient(180deg, var(--lcd-bezel-top) 0%, var(--lcd-bezel-bot) 100%);
  margin: 0 0.15rem 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(92, 92, 92, 0.23);
}

.lcd {
  min-height: 4.2rem;
  border-radius: 0.18rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.16rem;
  padding: 0.46rem;
  background: linear-gradient(180deg, #dce4d7 0%, var(--lcd-bg) 100%);
  box-shadow: inset 0 0 0 1px rgba(88, 97, 87, 0.26), inset 0 2px 6px rgba(255, 255, 255, 0.16);
}

.lcd-char {
  width: 18px;
  height: 34px;
  position: relative;
  flex: 0 0 auto;
}

.seg {
  position: absolute;
  background: var(--lcd-seg-off);
  opacity: 0.2;
  border-radius: 1px;
}

.seg.on {
  background: var(--lcd-seg-on);
  opacity: 1;
}

.seg.a,
.seg.d,
.seg.g {
  width: 12px;
  height: 3px;
  left: 3px;
}

.seg.a {
  top: 0;
}

.seg.g {
  top: 15px;
}

.seg.d {
  bottom: 0;
}

.seg.b,
.seg.c,
.seg.e,
.seg.f {
  width: 3px;
  height: 13px;
}

.seg.b {
  right: 0;
  top: 2px;
}

.seg.c {
  right: 0;
  bottom: 2px;
}

.seg.e {
  left: 0;
  bottom: 2px;
}

.seg.f {
  left: 0;
  top: 2px;
}

.seg.dot {
  width: 4px;
  height: 4px;
  right: -4px;
  bottom: -2px;
  border-radius: 50%;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0.15rem 0.55rem;
}

.pill-btn {
  border: 1px solid #1f3a3d;
  border-radius: 999px;
  background: linear-gradient(180deg, #6ba1a4 0%, #3b666b 100%);
  color: #eaf4f5;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.3rem 0.8rem;
  box-shadow:
    inset 0 1px 0 rgba(222, 245, 247, 0.25),
    inset 0 -1px 0 rgba(20, 47, 51, 0.45),
    0 1px 0 rgba(14, 33, 36, 0.8),
    0 2px 0 #27494d;
  cursor: pointer;
}

.pill-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.flip-toggle {
  flex: 0 0 auto;
  transition: transform 80ms ease, box-shadow 80ms ease, filter 80ms ease;
}

.flip-toggle:hover {
  filter: brightness(1.05);
}

.flip-toggle:active,
.flip-toggle[aria-pressed="true"] {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(222, 245, 247, 0.2),
    inset 0 -1px 0 rgba(20, 47, 51, 0.35),
    0 1px 0 rgba(14, 33, 36, 0.8),
    0 1px 0 #27494d;
}

.translator-row {
  display: none;
  flex: 1 1 auto;
  gap: 0.4rem;
  align-items: center;
}

.upright-tools {
  display: flex;
  flex: 1 1 auto;
  justify-content: flex-end;
}

.word-input {
  width: 100%;
  border: 1px solid #8e908c;
  border-radius: 0.3rem;
  background: #f4f4ef;
  color: #1f2526;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.36rem 0.45rem;
  text-transform: uppercase;
}

.word-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.translate-btn:active {
  transform: translateY(2px);
}

.translator-status {
  display: none;
  min-height: 1.05rem;
  margin: 0 0.15rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #7d2c36;
}

.calculator.is-flipped .translator-row {
  display: flex;
  transform: rotate(180deg);
  transform-origin: center;
}

.calculator.is-flipped .upright-tools {
  display: none;
}

.calculator.is-flipped .translator-status {
  display: block;
}

.challenge-tape {
  position: absolute;
  top: 0.55rem;
  left: calc(100% + 0.6rem);
  width: 178px;
  height: fit-content;
  background:
    radial-gradient(circle at 1px 1px, rgba(31, 39, 44, 0.07) 1px, transparent 1px) 0 0 / 4px 4px,
    linear-gradient(180deg, #ffffff 0%, #f7f7f4 100%);
  border: 1px solid #d6d7d2;
  border-radius: 0.3rem;
  padding: 0.52rem 0.5rem 0.56rem;
  box-shadow:
    0 8px 14px rgba(39, 31, 18, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  overflow: visible;
}

.challenge-tape::before,
.challenge-tape::after {
  content: "";
  position: absolute;
  left: -1px;
  width: calc(100% + 2px);
  height: 10px;
  pointer-events: none;
  background:
    linear-gradient(-45deg, transparent 6px, var(--page-bg) 0) 0 0 / 12px 10px repeat-x,
    linear-gradient(45deg, transparent 6px, var(--page-bg) 0) 6px 0 / 12px 10px repeat-x;
  z-index: 2;
}

.challenge-tape::before {
  top: -10px;
}

.challenge-tape::after {
  bottom: -10px;
  transform: rotate(180deg);
}

.challenge-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}

.challenge-title {
  margin: 0;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #313238;
}

.challenge-close {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #4b5056;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.challenge-close:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.challenge-subtitle {
  margin: 0.2rem 0 0.4rem;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: #555a5f;
}

.challenge-items {
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 0.79rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.45;
  color: #22272b;
}

.challenge-line {
  margin: 0 0 0.24rem;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.15rem;
}

.key {
  position: relative;
  border: 1px solid var(--key-dark-edge);
  border-radius: 0.42rem;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(180deg, var(--key-dark-top) 0%, var(--key-dark-bot) 100%);
  color: #eef2f6;
  font-size: 1.9rem;
  font-weight: 500;
  line-height: 1;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35),
    0 1px 0 rgba(7, 8, 10, 0.9),
    0 3px 0 var(--key-dark-lip),
    0 5px 7px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 70ms ease, box-shadow 70ms ease, filter 70ms ease;
}

.key::before {
  content: "";
  position: absolute;
  left: 0.3rem;
  right: 0.3rem;
  top: 0.24rem;
  height: 0.08rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  pointer-events: none;
}

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

.key:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.key:active,
.key.is-active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3),
    0 1px 0 rgba(7, 8, 10, 0.85),
    0 1px 0 var(--key-dark-lip),
    0 2px 3px rgba(0, 0, 0, 0.18);
}

.key-util {
  border-color: var(--key-red-edge);
  background: linear-gradient(180deg, var(--key-red-top) 0%, var(--key-red-bot) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 225, 230, 0.26),
    inset 0 -1px 0 rgba(74, 18, 24, 0.4),
    0 1px 0 rgba(42, 9, 14, 0.85),
    0 3px 0 var(--key-red-lip),
    0 5px 7px rgba(0, 0, 0, 0.2);
}

.key-op {
  border-color: var(--key-teal-edge);
  background: linear-gradient(180deg, var(--key-teal-top) 0%, var(--key-teal-bot) 100%);
  box-shadow:
    inset 0 1px 0 rgba(214, 242, 244, 0.24),
    inset 0 -1px 0 rgba(21, 46, 49, 0.4),
    0 1px 0 rgba(12, 29, 31, 0.84),
    0 3px 0 var(--key-teal-lip),
    0 5px 7px rgba(0, 0, 0, 0.2);
}

.key-equals {
  grid-row: span 2;
  aspect-ratio: auto;
  height: 100%;
  font-size: 2.1rem;
}

.key-zero {
  grid-column: span 2;
  aspect-ratio: auto;
  height: 100%;
}

@media (max-width: 860px) {
  .challenge-tape {
    left: auto;
    top: 0.55rem;
    right: 0.45rem;
    z-index: 12;
  }
}

@media (max-width: 380px) {
  .calculator {
    width: min(100%, 355px);
  }

  .brand {
    font-size: 1.35rem;
  }

  .key {
    font-size: 1.75rem;
  }

  .word-input {
    font-size: 0.8rem;
    min-width: 0;
  }

  .challenge-tape {
    right: 0.2rem;
  }
}
