:root {
  --navy: #00205b;
  --blue-header: #85abf1;
  --blue-light: #b1ccff;
  --keyboard-bg: #d1d3d9;
  --key-bg: #ffffff;
  --key-dark: #abb0bc;
  --green: #34b854;
  --red: #d1362f;
  --yellow: #f2c230;
  --text-on-navy: #ffffff;
  --font-body: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--navy);
  font-family: var(--font-body);
  overscroll-behavior: none;
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

/* ---------- Header ---------- */
.header {
  flex: 0 0 auto;
  height: 56px;
  background: #ffffff;
  border-bottom: 1px solid #e4e8f2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
}
.header-left { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 700; font-size: 20px; color: var(--navy); letter-spacing: 0.2px; }
.conn-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #c7ccd6;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.03);
}
.conn-dot.connected { background: var(--green); }
.menu-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--navy);
  background: transparent; color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* ---------- History ---------- */
.history {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--blue-light);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-empty {
  margin: auto;
  text-align: center;
  color: #38508f;
  opacity: 0.75;
  font-size: 15px;
  line-height: 1.5;
}
.demo-link {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--navy);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  opacity: 0.8;
}
.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 17px;
  line-height: 1.35;
  animation: pop-in 0.18s ease-out;
}
.msg-driver {
  align-self: flex-start;
  color: var(--navy);
  background: transparent;
  padding-left: 0;
  font-weight: 700;
}
.msg-passenger {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-fading {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ---------- Compose (live big-caption box) ---------- */
.compose {
  flex: 0 0 auto;
  position: relative;
  min-height: 130px;
  max-height: 40vh;
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 18px 64px 18px 18px;
  overflow: hidden;
  transition: min-height 0.15s ease;
}
.compose-text {
  color: #fff;
  font-weight: 700;
  line-height: 1.25;
  width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 30px;
}
.compose-placeholder {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,0.45);
  font-size: 19px;
  pointer-events: none;
}
.compose.has-text .compose-placeholder { display: none; }
.send-btn {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  cursor: pointer;
}
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.45; }

/* ---------- Keyboard ---------- */
.keyboard {
  flex: 0 0 auto;
  background: var(--keyboard-bg);
  padding: 8px 4px 4px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
.krow {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6px;
}
.krow-bottom { padding: 0 20px; }
.key {
  flex: 1 1 0;
  max-width: 34px;
  height: 42px;
  background: var(--key-bg);
  border: none;
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
  font-size: 19px;
  font-family: var(--font-body);
  color: #1c1c1e;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  user-select: none;
}
.key:active { background: #eceff1; }
.key-shift, .key-back { background: var(--key-dark); flex: 0 0 46px; max-width: 46px; font-size: 15px; }
.krow-space { padding: 0 4px; }
.key-wide { flex: 0 0 68px; max-width: 68px; background: var(--key-dark); font-size: 14px; }
.key-space { flex: 1 1 auto; max-width: none; }
.key-return { background: var(--green); color: #fff; font-weight: 700; }
.kaccessory {
  display: flex; justify-content: space-between;
  padding: 6px 22px 2px;
}
.icon-btn { background: none; border: none; padding: 4px; cursor: pointer; }

/* ---------- Fullscreen "new message" reveal ---------- */
.reveal {
  position: absolute;
  inset: 0;
  background: var(--blue-light);
  color: var(--navy);
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: 40px 28px;
  z-index: 30;
  animation: slide-up 0.32s cubic-bezier(.2,.8,.2,1);
}
.reveal.show { display: flex; }
.reveal-label { font-size: 16px; opacity: 0.65; font-weight: 700; margin-bottom: 10px; }
.reveal-text { font-size: 40px; font-weight: 700; line-height: 1.25; }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---------- Fullscreen alert (horn / ambulance) ---------- */
.alert-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  z-index: 40;
  color: #fff;
}
.alert-screen.show.horn { display: flex; background: radial-gradient(circle at center, #f2c230 0%, #a6790a 100%); animation: pulse-bg 0.9s ease-in-out infinite; }
.alert-screen.show.ambulance { display: flex; background: radial-gradient(circle at center, #d1362f 0%, #4d0c0a 100%); animation: pulse-bg 0.6s ease-in-out infinite; }
@keyframes pulse-bg { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.18); } }
.alert-icon { width: 96px; height: 96px; }
.alert-text { font-size: 26px; font-weight: 700; text-align: center; }

/* ---------- Overlay sheets ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 38, 0.38);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.overlay.show { display: flex; }
.sheet {
  width: 100%;
  max-height: 82%;
  overflow-y: auto;
  overflow-x: hidden;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  color: var(--navy);
  animation: slide-up 0.24s ease-out;
}
.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--navy);
  padding: 13px 4px;
  cursor: pointer;
}
.sheet-item-secondary { color: #38508f; font-size: 15px; }
.sheet-divider { height: 1px; background: #e4e8f2; margin: 6px 0; }
.sheet-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: #7183ab; margin: 10px 4px 6px; }
.pair-row { display: flex; gap: 8px; padding: 0 4px; }
.pair-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1.5px solid #c8d2ea;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 18px;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  font-family: var(--font-body);
  color: var(--navy);
}
.pair-btn {
  flex: 0 0 auto;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 14px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.pair-status { padding: 8px 4px 2px; font-size: 13px; color: #7183ab; }
.size-row { display: flex; gap: 10px; padding: 4px 4px 6px; }
.size-btn {
  flex: 1;
  height: 52px;
  border-radius: 10px;
  border: 2px solid #c8d2ea;
  background: #f4f6fb;
  color: var(--navy);
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
}
.size-btn.active { border-color: var(--green); background: #eafaf0; }
.size-mid { font-size: 22px; }
.size-big { font-size: 28px; }
.sheet-close { text-align: center; color: #7183ab; font-weight: 700; margin-top: 6px; }
.info-title { font-size: 20px; font-weight: 700; padding: 6px 4px 10px; }
.info-body { font-size: 16px; line-height: 1.6; padding: 0 4px 10px; color: #29304a; }
.scan-sheet { max-height: 92%; }
.scan-video { width: 100%; border-radius: 12px; background: #000; margin: 8px 0; aspect-ratio: 3/4; object-fit: cover; }

/* Text-size preference applied to the whole app */
.app.text-medium .compose-text { font-size: 34px; }
.app.text-medium .msg { font-size: 19px; }
.app.text-large .compose-text { font-size: 40px; }
.app.text-large .msg { font-size: 22px; }

@media (min-width: 480px) {
  .app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 40px rgba(0,0,0,0.15); }
}
