/* ============================================
   Calculator(tm) - app-specific styles
   Loaded in addition to style.css
   ============================================ */

.calc-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin: 0 0 2.5rem;
}

.calc {
  width: 100%;
  max-width: 330px;
  background: linear-gradient(180deg, #1c1c2c 0%, #12121c 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  user-select: none;
  -webkit-user-select: none;
}

/* --- Display --- */
.calc-display {
  background: #0a1410;
  border: 1px solid #1d3a2e;
  border-radius: 10px;
  padding: 0.75rem 0.9rem 0.6rem;
  margin-bottom: 0.9rem;
  text-align: right;
  overflow: hidden;
}

.calc-expression {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #3f7d63;
  min-height: 1.1em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calc-value {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  line-height: 1.2;
  font-weight: 700;
  color: #6ee7a8;
  text-shadow: 0 0 12px rgba(110, 231, 168, 0.35);
  white-space: nowrap;
  overflow: hidden;
  transition: font-size 0.12s;
}

.calc-value.is-long {
  font-size: 1.6rem;
}

.calc-value.is-error {
  color: var(--accent-secondary);
  text-shadow: 0 0 12px rgba(255, 107, 107, 0.35);
}

.calc-status {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #4b8f72;
  text-align: left;
  min-height: 2.2em;
  margin-top: 0.5rem;
  line-height: 1.4;
}

.calc-status.is-warn { color: var(--accent-yellow); }
.calc-status.is-good { color: var(--accent-green); }

/* --- Keypad --- */
.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.key {
  position: relative;
  appearance: none;
  border: 1px solid #2a2a40;
  background: linear-gradient(180deg, #262638 0%, #1b1b28 100%);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  height: 52px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, transform 0.06s, border-color 0.12s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.key:hover { background: linear-gradient(180deg, #2f2f45 0%, #212130 100%); }

.key:active,
.key.is-active {
  transform: translateY(2px);
  box-shadow: none;
  background: linear-gradient(180deg, #1b1b28 0%, #262638 100%);
}

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

.key-op {
  color: var(--accent);
  border-color: #22415c;
  background: linear-gradient(180deg, #1a2c3c 0%, #142331 100%);
}

.key-op:hover { background: linear-gradient(180deg, #21384c 0%, #182a3a 100%); }

.key-fn {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.key-eq {
  color: #05202b;
  background: linear-gradient(180deg, #00d4ff 0%, #00a8cc 100%);
  border-color: #00d4ff;
}

.key-eq:hover { background: linear-gradient(180deg, #33ddff 0%, #00bce0 100%); }

/* --- The broken 3 --- */
.key-broken {
  overflow: hidden;
  color: transparent;
  border-color: #4a3340;
  background: linear-gradient(180deg, #292430 0%, #1d1a22 100%);
  cursor: not-allowed;
}

.key-broken:hover { background: linear-gradient(180deg, #302a38 0%, #221e28 100%); }

/* Two halves of the glyph, split along the crack and nudged apart */
.key-broken .glyph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7a7a90;
  font-size: 1.15rem;
  font-weight: 700;
}

.key-broken .glyph-a {
  clip-path: polygon(0 0, 38% 0, 46% 22%, 34% 38%, 48% 56%, 40% 76%, 52% 100%, 0 100%);
  transform: translate(-1.5px, -1px) rotate(-1.5deg);
}

.key-broken .glyph-b {
  clip-path: polygon(38% 0, 100% 0, 100% 100%, 52% 100%, 40% 76%, 48% 56%, 34% 38%, 46% 22%);
  transform: translate(1.5px, 1px) rotate(1.5deg);
}

.key-broken .crack {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.key-broken .crack polyline {
  fill: none;
  stroke: #05050a;
  stroke-width: 2.5;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* Fill that climbs while the key is held */
.key-broken .hold-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.35), rgba(0, 212, 255, 0.12));
  transform-origin: bottom;
  transform: scaleY(0);
  transition: transform 0.18s ease-out;
  pointer-events: none;
}

.key-broken.is-holding .hold-fill {
  transform: scaleY(1);
  transition-duration: var(--hold-ms, 1200ms);
  transition-timing-function: linear;
}

/* Progress pips for coax attempts banked so far */
.key-broken .pips {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 3px;
  pointer-events: none;
}

.key-broken .pip {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #45455e;
  transition: background 0.2s, box-shadow 0.2s;
}

.key-broken .pip.on {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(0, 212, 255, 0.8);
}

.key-broken.is-denied {
  animation: crackShake 0.26s ease-in-out;
}

@keyframes crackShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px) rotate(-0.6deg); }
  45% { transform: translateX(3px) rotate(0.6deg); }
  70% { transform: translateX(-2px); }
}

.key-broken.is-earned {
  animation: earnedFlash 0.5s ease-out;
}

@keyframes earnedFlash {
  0% { box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.7); }
  100% { box-shadow: 0 0 0 18px rgba(0, 212, 255, 0); }
}

/* --- Toolbar + stats --- */
.calc-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 330px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.calc-stats {
  display: flex;
  gap: 0.9rem;
}

.calc-stats b {
  color: var(--text-secondary);
  font-weight: 700;
}

.calc-toolbar button {
  appearance: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.calc-toolbar button:hover {
  color: var(--accent);
  border-color: rgba(0, 212, 255, 0.4);
}

@media (max-width: 480px) {
  .calc { max-width: 100%; }
  .calc-toolbar { max-width: 100%; }
  .calc-value { font-size: 2rem; }
}
