:root {
  --bg-primary: #000000; /* pure black = transparent on additive display, lets real world show through */
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --warning: #ffaa00;
  --info: #00b4d8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app { width: 100%; height: 100%; position: relative; }

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 { font-size: 22px; font-weight: 600; flex: 1; }
.header-meta { font-size: 13px; color: var(--text-secondary); }
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Focus States (critical for EMG/D-pad) --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary { background: var(--accent-primary); color: #0a0a0f; }
.nav-item.primary:focus { background: #33ddff; }
.nav-item.danger { background: var(--danger); color: white; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 2px solid transparent;
}
.card-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.card-subtitle { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.card-value { font-size: 26px; font-weight: 700; color: var(--accent-primary); margin-bottom: 8px; }

/* --- List Items --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 12px;
  width: 100%;
}
.list-item:focus { background: var(--bg-card); }
.list-item-icon { font-size: 22px; flex-shrink: 0; width: 40px; text-align: center; }
.list-item-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-item-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.list-item-meta { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* --- Loading / Error --- */
.loading-container, .error-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 28px; text-align: center;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; color: var(--text-secondary); }
.error-icon { font-size: 40px; }
.error-message { font-size: 15px; color: var(--text-secondary); max-width: 420px; }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card); color: var(--text-primary);
  padding: 12px 24px; border-radius: var(--radius-md);
  font-size: 14px; border: 1px solid var(--accent-primary);
  transition: transform 0.3s ease; z-index: 100; pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

/* --- Tabs --- */
.tab-bar { display: flex; gap: 4px; padding: 4px; background: var(--bg-secondary); border-radius: var(--radius-md); }
.tab-item {
  flex: 1; padding: 10px 8px; background: transparent; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500; text-align: center;
}
.tab-item.active { background: var(--bg-tertiary); color: var(--text-primary); }
.tab-item:focus { background: var(--bg-card); color: var(--text-primary); }

.hidden { display: none !important; }

/* ==================== MedLookup-specific ==================== */

/* Prefix bar — shows the letters the operator has spelled so far */
.prefix-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; background: var(--bg-secondary); flex-shrink: 0;
}
.prefix-label { font-size: 13px; color: var(--text-secondary); }
.prefix-value {
  font-size: 20px; font-weight: 700; letter-spacing: 1px;
  color: var(--accent-secondary); text-transform: lowercase;
  min-height: 24px; flex: 1;
}

/* Letter grid — the hands-free "keyboard" (D-pad navigable, 7 cols) */
.keys {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 8px 16px;
  flex-shrink: 0;
}
.key {
  min-height: 40px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.key:focus { background: var(--bg-card); }
.key-util { font-size: 12px; color: var(--accent-warm); }

/* Results region — scrolls below the keys, with a top scrim */
.results-wrap {
  flex: 1; position: relative; overflow: hidden;
  padding: 8px 16px 16px;
}
.results-wrap .list-container { max-height: 100%; height: 100%; padding-bottom: 24px; }
.results-wrap::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 16px;
  background: linear-gradient(to bottom, var(--bg-primary) 0%, transparent 100%);
  pointer-events: none; z-index: 5;
}

.code-chip {
  font-size: 13px; font-weight: 700; color: var(--accent-primary);
  background: rgba(0, 212, 255, 0.12); border-radius: var(--radius-sm);
  padding: 4px 6px; width: auto; min-width: 56px; white-space: nowrap;
}

.hint {
  font-size: 14px; color: var(--text-secondary); text-align: center;
  padding: 24px 16px; line-height: 1.5;
}
