/* Mobile first, because a keypad on a phone is the whole point. Everything
   below scales up to desktop rather than the other way round. */

:root {
  --bg: #12141a;
  --panel: #1c1f26;
  --key: #262a33;
  --key-press: #3a4150;
  --ink: #e8eaf0;
  --dim: #8a90a0;
  --accent: #7cd992;
  --pending: #ffd166;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Rapid tapping otherwise selects text and pops the iOS callout menu. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Respect the notch. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header { text-align: center; padding: 1.5rem 1rem 0.5rem; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.sub { margin: 0.35rem 0 0; color: var(--dim); font-size: 0.9rem; }

main { max-width: 420px; margin: 0 auto; padding: 0 1rem 1rem; }

/* --- mode switch --- */

.modes {
  display: flex;
  gap: 0.5rem;
  max-width: 420px;
  margin: 1rem auto 0.75rem;
  padding: 0 1rem;
}
.mode {
  flex: 1;
  background: var(--panel);
  color: var(--dim);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.6rem 0.5rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.mode span { font-weight: 400; font-size: 0.7rem; opacity: 0.8; }
.mode.active { color: var(--ink); border-color: var(--accent); }

/* --- the phone screen --- */

.screen {
  background: #0c1a12;
  border: 1px solid #24402f;
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  min-height: 5.5rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 1.15rem;
  line-height: 1.45;
  word-break: break-word;
  /* Long messages scroll rather than pushing the keypad off screen. */
  max-height: 9rem;
  overflow-y: auto;
  /* Text in the screen should be selectable even though the rest is not. */
  -webkit-user-select: text;
  user-select: text;
}

/* The uncommitted character or word. In multi-tap this is the letter still
   cycling; in T9 it is the word the dictionary is guessing. Same visual
   language for both, because it is the same idea. */
.pending {
  color: var(--pending);
  border-bottom: 2px solid var(--pending);
}

.caret {
  display: inline-block;
  width: 0.55ch;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1.06s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.status {
  min-height: 1.4rem;
  margin: 0.5rem 0.15rem 0.75rem;
  font-size: 0.8rem;
  color: var(--dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.status b { color: var(--pending); font-weight: 600; }

/* --- keypad --- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
}

.key {
  /* 44px is the smallest reliable touch target; this is comfortably above. */
  min-height: 62px;
  background: var(--key);
  color: var(--ink);
  border: none;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  /* No transition on press: a delay here reads as lag on a keypad. */
}
.key b { font-size: 1.3rem; font-weight: 600; line-height: 1; }
.key i { font-style: normal; font-size: 0.62rem; letter-spacing: 0.08em; color: var(--dim); }
.key.down { background: var(--key-press); }

/* The key whose letters are currently cycling, so you can see what multi-tap
   is doing rather than only feeling it. */
.key.cycling { box-shadow: inset 0 0 0 2px var(--pending); }

.controls { display: flex; gap: 0.55rem; margin-top: 0.55rem; }
.ctl {
  flex: 1;
  min-height: 46px;
  background: var(--key);
  color: var(--ink);
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.ctl.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--key); color: var(--dim); }
.ctl.down { background: var(--key-press); }

/* --- explanation --- */

.explain { max-width: 420px; margin: 0 auto; padding: 0 1rem; }
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.card h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.card p { margin: 0 0 0.7rem; font-size: 0.88rem; color: #c3c8d4; }
.card p:last-child { margin-bottom: 0; }
.card strong { color: var(--ink); }
.card em { color: var(--pending); font-style: normal; }

.ad-slot:empty { display: none; }
.ad-slot { max-width: 420px; margin: 0 auto 1rem; padding: 0 1rem; }

footer {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  color: var(--dim);
  font-size: 0.75rem;
  text-align: center;
}

/* Wider screens: keypad and explanation side by side rather than a very long
   column of empty space. */
@media (min-width: 760px) {
  .wrap { display: grid; }
  main, .modes, .explain, footer, .ad-slot { max-width: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
}

/* Consent bar. Only ever rendered for visitors in a region that requires it,
   so it must not push the keypad around for everyone else -- fixed, not in
   flow. Sits above the fold on a phone because a bar nobody can see is not
   consent. */
.consent {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #2c313c;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}
.consent p { margin: 0; color: var(--dim); font-size: 0.85rem; max-width: 46ch; }
.consent-actions { display: flex; gap: 0.5rem; }
.consent button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid #2c313c;
  background: var(--key);
  color: var(--ink);
  cursor: pointer;
}
.consent button.primary { background: var(--accent); border-color: var(--accent); color: #0c1a12; font-weight: 600; }
.consent button:active { transform: translateY(1px); }
