*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0c;
  --panel:     #16161d;
  --border:    #2a2a35;
  --amber:     #f5a623;
  --amber-dim: #7a4f0d;
  --red:       #e05050;
  --green:     #4ecca3;
  --btn-bg:    #1c1c26;
  --btn-hover: #252532;
  --btn-press: #0f0f18;
  --text-muted:#55556a;
}

/* ── Base ─────────────────────────────────────── */
html, body {
  height: 100%;
  width: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport for mobile browsers */
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Rajdhani', sans-serif;
  overflow: hidden;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Grid background */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(245,166,35,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245,166,35,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* Radial glow */
body::after {
  content: '';
  position: fixed;
  width: 600px; height: 600px;
  background: radial-gradient(ellipse, rgba(245,166,35,0.06) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  pointer-events: none;
}

/* ── Wrapper ──────────────────────────────────── */
.calc-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
}

/* ── Brand ────────────────────────────────────── */
.brand {
  text-align: center;
  margin-bottom: 14px;
  letter-spacing: 0.4em;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Orbitron', monospace;
  text-transform: uppercase;
}
.brand span { color: var(--amber); }

/* ── Calc Card ────────────────────────────────── */
.calc {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 20px 16px 16px;
  box-shadow:
    0 0 0 1px rgba(245,166,35,0.05),
    0 40px 80px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.04);
  position: relative;
}

/* ── Screws ───────────────────────────────────── */
.screw {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2e2e3a, #111116);
  border: 1px solid #2a2a35;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.8);
}
.screw::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%) rotate(45deg);
  width: 6px; height: 1px;
  background: var(--text-muted); opacity: 0.4;
}
.screw.tl { top: 12px; left: 12px; }
.screw.tr { top: 12px; right: 12px; }
.screw.bl { bottom: 12px; left: 12px; }
.screw.br { bottom: 12px; right: 12px; }

/* ── Display ──────────────────────────────────── */
.display {
  background: #06060a;
  border-radius: 12px;
  border: 1px solid #1e1e28;
  padding: 14px 18px 12px;
  margin-bottom: 16px;
  box-shadow:
    inset 0 4px 16px rgba(0,0,0,0.7),
    inset 0 0 0 1px rgba(245,166,35,0.04),
    0 0 20px rgba(245,166,35,0.03);
  position: relative;
  overflow: hidden;
  min-height: 80px;
}

/* Scanlines */
.display::before {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,0,0,0.15) 3px, rgba(0,0,0,0.15) 4px
  );
  pointer-events: none; z-index: 2;
}

.display-expression {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--amber-dim);
  letter-spacing: 0.08em;
  min-height: 18px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 6px;
  opacity: 0.8;
  position: relative; z-index: 3;
}

.display-main {
  font-family: 'Orbitron', monospace;
  font-size: 38px;
  font-weight: 700;
  color: var(--amber);
  text-align: right;
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow:
    0 0 10px rgba(245,166,35,0.6),
    0 0 30px rgba(245,166,35,0.2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.1s, font-size 0.1s;
  position: relative; z-index: 3;
  animation: flicker 3s infinite;
}
.display-main.error {
  color: var(--red);
  text-shadow: 0 0 10px rgba(224,80,80,0.6);
  font-size: 22px;
}
.display-main.result-flash {
  color: var(--green);
  text-shadow: 0 0 10px rgba(78,204,163,0.6), 0 0 30px rgba(78,204,163,0.2);
}

/* ── Button Grid ──────────────────────────────── */
.buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* ── Base Button ──────────────────────────────── */
.btn {
  /* Use aspect-ratio so buttons are always square-ish on any screen */
  aspect-ratio: 1 / 1;
  min-height: 56px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: #c8c8d8;
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.08s, transform 0.08s, box-shadow 0.08s, border-color 0.08s;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.04);
  position: relative;
  overflow: hidden;
  outline: none;
  user-select: none;
  letter-spacing: 0.05em;
  /* Prevent double-tap zoom on mobile */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,0.06), transparent 60%);
  pointer-events: none;
}

/* Desktop hover */
@media (hover: hover) {
  .btn:hover {
    background: var(--btn-hover);
    border-color: #3a3a4a;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
  }
}

.btn:active, .btn.pressed {
  background: var(--btn-press);
  transform: translateY(1px) scale(0.95);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5), inset 0 2px 4px rgba(0,0,0,0.4);
}

/* ── Operator ─────────────────────────────────── */
.btn.op {
  color: var(--amber);
  border-color: rgba(245,166,35,0.2);
  background: rgba(245,166,35,0.06);
  font-size: 20px;
  text-shadow: 0 0 8px rgba(245,166,35,0.3);
}
@media (hover: hover) {
  .btn.op:hover {
    background: rgba(245,166,35,0.12);
    border-color: rgba(245,166,35,0.35);
  }
}

/* ── Clear ────────────────────────────────────── */
.btn.clear {
  color: var(--red);
  border-color: rgba(224,80,80,0.2);
  background: rgba(224,80,80,0.06);
  font-size: 13px;
}
@media (hover: hover) {
  .btn.clear:hover {
    background: rgba(224,80,80,0.12);
    border-color: rgba(224,80,80,0.35);
  }
}

/* ── Equals ───────────────────────────────────── */
.btn.equals {
  background: var(--amber);
  color: #0a0a0c;
  border-color: var(--amber);
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(245,166,35,0.3), 0 0 0 1px rgba(245,166,35,0.2);
}
@media (hover: hover) {
  .btn.equals:hover {
    background: #f7b84a;
    box-shadow: 0 6px 24px rgba(245,166,35,0.45), 0 0 0 1px rgba(245,166,35,0.3);
    transform: translateY(-1px);
  }
}
.btn.equals:active, .btn.equals.pressed {
  background: #d4880f;
  transform: translateY(1px) scale(0.95);
  box-shadow: 0 2px 10px rgba(245,166,35,0.2);
}

/* ── Func (±, %) ──────────────────────────────── */
.btn.func {
  color: var(--green);
  border-color: rgba(78,204,163,0.2);
  background: rgba(78,204,163,0.05);
  font-size: 12px;
  letter-spacing: 0.04em;
}
@media (hover: hover) {
  .btn.func:hover {
    background: rgba(78,204,163,0.1);
    border-color: rgba(78,204,163,0.3);
  }
}

/* ── Wide Zero ────────────────────────────────── */
.btn.zero {
  grid-column: span 2;
  aspect-ratio: unset;
  text-align: left;
  padding-left: 22px;
}

/* ── Ripple ───────────────────────────────────── */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  transform: scale(0);
  animation: ripple-out 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple-out {
  to { transform: scale(4); opacity: 0; }
}

/* ── Hint ─────────────────────────────────────── */
.hint {
  text-align: center;
  margin-top: 12px;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ── Nixie flicker ────────────────────────────── */
@keyframes flicker {
  0%,100%{ opacity:1 }
  5%     { opacity:0.7 }
  10%    { opacity:1 }
  50%    { opacity:0.95 }
  55%    { opacity:0.8 }
  60%    { opacity:1 }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════════════════════ */

/* Small phones (≤360px) */
@media (max-width: 360px) {
  .calc { padding: 14px 10px 12px; border-radius: 16px; }
  .buttons { gap: 7px; }
  .btn { font-size: 14px; min-height: 48px; border-radius: 10px; }
  .btn.op { font-size: 18px; }
  .btn.func { font-size: 10px; }
  .btn.zero { padding-left: 16px; }
  .display-main { font-size: 32px; }
  .brand { font-size: 9px; letter-spacing: 0.3em; }
}

/* Medium phones (361px – 480px) — default styles already work well */
@media (min-width: 361px) and (max-width: 480px) {
  .calc { max-width: 100%; }
  .buttons { gap: 9px; }
  .btn { min-height: 60px; }
}

/* Large phones / small tablets (481px – 640px) */
@media (min-width: 481px) and (max-width: 640px) {
  .calc { max-width: 420px; padding: 24px 20px; }
  .buttons { gap: 12px; }
  .btn { font-size: 18px; min-height: 68px; border-radius: 14px; }
  .btn.op { font-size: 22px; }
  .btn.func { font-size: 13px; }
  .display-main { font-size: 44px; }
}

/* Tablets and up (641px+) */
@media (min-width: 641px) {
  .calc { max-width: 400px; padding: 26px 22px; }
  .buttons { gap: 12px; }
  .btn { font-size: 18px; min-height: 72px; border-radius: 14px; }
  .btn.op { font-size: 22px; }
  .btn.equals { font-size: 24px; }
  .btn.func { font-size: 13px; }
  .display-main { font-size: 42px; }
  .hint { font-size: 11px; }
}

/* Landscape on phones — keep calc compact vertically */
@media (max-height: 600px) and (orientation: landscape) {
  body { justify-content: flex-start; padding-top: 8px; overflow-y: auto; }
  .calc-wrapper { padding: 8px 12px; }
  .brand { margin-bottom: 8px; }
  .display { min-height: 60px; padding: 10px 16px 8px; margin-bottom: 10px; }
  .display-main { font-size: 28px; }
  .buttons { gap: 6px; }
  .btn { min-height: 44px; font-size: 14px; aspect-ratio: unset; }
  .btn.op { font-size: 17px; }
  .hint { margin-top: 8px; }
}