:root {
  --red: #E52521;
  --red-dark: #B81A17;
  --blue: #049CD8;
  --blue-dark: #0277A6;
  --yellow: #FBD000;
  --yellow-dark: #C9A600;
  --green: #43B047;
  --green-dark: #2F8033;
  --brown: #6B3F1D;
  --brown-light: #B97A3D;
  --cream: #FFF6E0;
  --ink: #0E0E12;
  --shadow: 0 6px 0 rgba(0,0,0,0.18), 0 14px 30px rgba(8,12,40,0.18);
  --press-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 10px rgba(8,12,40,0.16);
  --pixel: "Press Start 2P", system-ui, sans-serif;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--ui);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, #6BA8FF 0%, #A6D2FF 60%, #DCEBFF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 32px;
  position: relative;
}

/* --- sky / clouds --- */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.cloud {
  position: absolute;
  width: 120px; height: 36px;
  background: #fff;
  border-radius: 30px;
  box-shadow:
    20px -16px 0 -4px #fff,
    -20px -10px 0 -6px #fff,
    44px -8px 0 -10px #fff;
  opacity: 0.9;
}
.cloud::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 30px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.06);
}
.cloud-a { top: 8%; left: 6%; animation: drift 60s linear infinite; }
.cloud-b { top: 22%; right: 8%; transform: scale(0.8); animation: drift 80s linear infinite reverse; }
.cloud-c { top: 60%; left: 12%; transform: scale(1.2); animation: drift 100s linear infinite; }
@keyframes drift {
  0% { transform: translateX(0) scale(var(--s, 1)); }
  100% { transform: translateX(40px) scale(var(--s, 1)); }
}

/* --- cabinet --- */
.cabinet {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

/* --- header --- */
.cab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.title { display: flex; align-items: center; gap: 10px; }
.title h1 {
  margin: 0;
  font-family: var(--pixel);
  font-size: 14px;
  letter-spacing: 0.5px;
  color: var(--red);
  text-shadow: 2px 2px 0 var(--ink);
}

/* CSS-drawn mushroom icon */
.mush { position: relative; width: 36px; height: 36px; display: inline-block; }
.mush-cap {
  position: absolute; top: 0; left: 0;
  width: 36px; height: 22px;
  background: var(--red);
  border: 2px solid var(--ink);
  border-radius: 18px 18px 4px 4px;
}
.mush-cap .dot {
  position: absolute;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  width: 7px; height: 7px;
}
.dot.d1 { top: 4px; left: 6px; }
.dot.d2 { top: 8px; left: 16px; width: 9px; height: 9px; }
.dot.d3 { top: 4px; right: 5px; }
.mush-stem {
  position: absolute; bottom: 0; left: 6px;
  width: 24px; height: 18px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-top: none;
  border-radius: 0 0 6px 6px;
  display: flex;
  justify-content: space-around;
  padding-top: 4px;
}
.mush-stem .eye {
  width: 4px; height: 6px;
  background: var(--ink);
  border-radius: 2px;
}

.header-right { display: flex; align-items: center; gap: 8px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--yellow);
  border: 2px solid var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
  font-family: var(--pixel);
  font-size: 8px;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}
.status-pill.offline { background: #ffd0a8; }
.status-pill .star { color: #c47900; }

.icon-btn {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  width: 34px; height: 34px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }

/* --- display --- */
.display {
  background: linear-gradient(180deg, #1c1f2c, #0e1018);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 14px 16px 12px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.display::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    180deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 3px
  );
  pointer-events: none;
}
.expr {
  min-height: 14px;
  font-family: var(--pixel);
  font-size: 10px;
  color: #ffd966;
  opacity: 0.85;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result {
  font-weight: 800;
  font-size: clamp(28px, 8vw, 40px);
  text-align: right;
  letter-spacing: 0.5px;
  word-break: break-all;
  color: #fff;
  text-shadow: 0 0 10px rgba(255,255,255,0.15);
}
.result.error { color: #ff6b6b; animation: shake 0.3s; }
.transcript {
  margin-top: 6px;
  font-size: 12px;
  color: #9bd1ff;
  text-align: right;
  font-style: italic;
  min-height: 14px;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* --- mode tabs --- */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tab {
  background: #fff;
  border: 2px solid var(--ink);
  padding: 10px;
  border-radius: 10px;
  font-family: var(--pixel);
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.18);
  transition: transform 0.05s ease;
}
.tab.active {
  background: var(--yellow);
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.18);
}

/* --- keypad --- */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.key {
  position: relative;
  appearance: none;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 14px 0;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
  transition: transform 0.04s ease, box-shadow 0.04s ease, background 0.15s;
  font-family: var(--ui);
}
.key:hover { background: #FFF1B0; }
.key:active, .key.is-active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.18);
}
.key.num { background: #fff; }
.key.fn {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 0 var(--blue-dark);
}
.key.fn:hover { background: #2BB0E8; }
.key.op {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 0 var(--red-dark);
  font-size: 24px;
}
.key.op:hover { background: #F23A36; }
.key.op.is-pending {
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--yellow-dark);
}
.key.eq {
  grid-column: span 1;
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 0 var(--green-dark);
  padding: 0;
}
.key.eq:hover { background: #58CC5C; }
.key.zero { grid-column: span 1; }

/* green pipe styling on equals */
.pipe {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; width: 100%; padding: 6px 0;
}
.pipe-top {
  width: 80%; height: 8px;
  background: var(--green);
  border: 2px solid var(--ink);
  border-radius: 4px;
  margin-bottom: 1px;
}
.pipe-body {
  width: 70%;
  background: var(--green-dark);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 4px 0;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

/* --- convert panel --- */
.convert-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--ink);
}
.field.grow { flex: 1; }
.field input,
.field select {
  font-family: var(--ui);
  font-size: 16px;
  padding: 10px 12px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  outline: none;
  width: 100%;
}
.field input:focus,
.field select:focus { background: #FFF8DC; }
.cv-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.swap-btn {
  background: var(--yellow);
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 3px 0 var(--yellow-dark);
  margin-bottom: 1px;
}
.swap-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--yellow-dark); }
.cv-result {
  font-size: 28px;
  font-weight: 800;
  text-align: right;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
  word-break: break-all;
}
.cv-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #555;
}
.link-btn {
  background: none;
  border: none;
  color: var(--blue-dark);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  font-size: 11px;
  padding: 2px 4px;
}

/* --- talk bar --- */
.talk-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0 0;
}
.talk-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--red);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--ui);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--red-dark);
  width: auto;
  min-width: 140px;
  justify-content: center;
  transition: transform 0.05s ease;
}
.talk-btn .mic { font-size: 16px; }
.talk-btn kbd {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: inherit;
}
.talk-btn:active,
.talk-btn.listening {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--red-dark);
}
.talk-btn.listening {
  animation: pulse 0.9s ease-in-out infinite;
  background: #ff3b36;
}
.talk-btn:disabled { opacity: 0.5; cursor: not-allowed; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 1px 0 var(--red-dark), 0 0 0 0 rgba(229,37,33,0.5); }
  50%      { box-shadow: 0 1px 0 var(--red-dark), 0 0 0 12px rgba(229,37,33,0); }
}
.talk-hint {
  font-size: 11px;
  color: #555;
  text-align: center;
}

/* --- footer ground bricks --- */
.cab-footer {
  margin: 8px -14px 0;
}
.bricks {
  height: 20px;
  background:
    repeating-linear-gradient(90deg,
      var(--brown) 0 30px,
      var(--brown-light) 30px 32px,
      var(--brown) 32px 60px,
      var(--brown-light) 60px 62px),
    var(--brown);
  border-top: 3px solid var(--ink);
}

/* --- responsive --- */
@media (max-width: 480px) {
  body { padding: 12px 8px 20px; }
  .cabinet { border-radius: 14px; padding: 10px 10px 0; gap: 10px; }
  .title h1 { font-size: 12px; }
  .key { font-size: 20px; padding: 12px 0; }
  .key.op { font-size: 22px; }
  .pipe-body { font-size: 20px; }
  .keypad { gap: 6px; }
  .result { font-size: clamp(26px, 9vw, 36px); }
  .status-pill { font-size: 7px; padding: 3px 8px; }
}

@media (max-height: 720px) {
  .cabinet { transform: scale(0.95); transform-origin: top center; }
}
