:root {
  /* Key/button sizes scale with the viewport (both width and height) so
     they stay comfortably large on normal phones, but are still capped so
     the whole screen (info area + 4 keypad rows + action row) fits even on
     a short viewport or in-browser with an address bar eating space. */
  --key-size: min(84px, 22vw, 11dvh);
  --key-gap: min(16px, 1.8dvh);
  --primary-size: min(92px, 26vw, 12.5dvh);
  --secondary-size: min(60px, 17vw, 8dvh);
  color-scheme: dark;
  --bg: #0c0c0e;
  --panel: #1c1c1e;
  --accent-green: #30d158;
  --accent-red: #ff453a;
  --text: #f5f5f7;
  --text-dim: #9a9a9e;
  --key-bg: #2c2c2e;
}

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

button {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

html, body {
  height: 100%;
  margin: 0;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 12px) env(safe-area-inset-left);
}
.screen.active { display: flex; }

.statusbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- Dial screen ---------- */

.dial-display {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(28px, 9vw, 44px);
  font-weight: 300;
  letter-spacing: 2px;
  min-height: 0;
  word-break: break-all;
  padding: 0 16px;
}

.keypad, .call-keypad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, var(--key-size));
  grid-auto-rows: var(--key-size);
  gap: var(--key-gap);
  justify-content: center;
  padding: 8px 24px;
  width: 100%;
}

.key {
  width: var(--key-size);
  height: var(--key-size);
  border-radius: 50%;
  border: none;
  background: var(--key-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 6vw, 26px);
  line-height: 1;
  gap: 2px;
  transition: background 0.08s ease;
}
.key:active { background: #48484a; }
.key .l {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.key-ghost { color: var(--text-dim); }

/* ---------- Shared action row (dial screen + call screen) ---------- */
/* Same class on both screens guarantees identical size & placement:
   a big primary circle (call / hangup) dead-center, flanked by two
   smaller secondary circles. */

.action-row {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 12px 24px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}

.btn-primary,
.btn-secondary,
.btn-secondary-slot {
  margin: 0 auto;
}

.btn-primary {
  width: var(--primary-size);
  height: var(--primary-size);
  aspect-ratio: 1;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-primary svg { width: 38%; height: 38%; fill: #fff; }
.btn-call { background: var(--accent-green); }
.btn-hangup { background: var(--accent-red); }

.btn-secondary {
  width: var(--secondary-size);
  height: var(--secondary-size);
  aspect-ratio: 1;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--key-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-secondary svg { width: 38%; height: 38%; fill: var(--text); }
.btn-secondary.on { background: var(--text); }
.btn-secondary.on svg { fill: #000; }

/* ---------- Call screen ---------- */

.call-info {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 0;
  text-align: center;
}
.avatar {
  width: 88px;
  height: 88px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--key-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.avatar svg { width: 48px; height: 48px; fill: var(--text-dim); }
.caller-name { font-size: 22px; font-weight: 500; margin-bottom: 2px; }
.call-status { color: var(--text-dim); font-size: 15px; }
.call-timer { color: var(--text-dim); font-size: 15px; font-variant-numeric: tabular-nums; margin-top: 4px; }

.call-keypad { padding: 8px 24px; }
