:root {
  --bg: #0b1d30;
  --panel: #102a43;
  --panel-2: #16365a;
  --text: #f0f4f8;
  --muted: #9fb3c8;
  --accent: #ffc43d;
  --accent-text: #102a43;
  --ok: #3ddc97;
  --warn: #ff8a5b;
  --danger: #ff5c5c;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand img { border-radius: 6px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  max-width: 45vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge-on { background: rgba(61, 220, 151, 0.15); color: var(--ok); }
.badge-off { background: rgba(255, 92, 92, 0.15); color: var(--danger); }

.icon-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.main { padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 640px; margin: 0 auto; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
}

.notice h2 { margin: 0 0 6px; font-size: 20px; color: var(--accent); }
.notice p { margin: 0 0 12px; color: var(--muted); }

.status-card { display: flex; gap: 14px; align-items: center; min-height: 92px; }
.status-dot {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 22px;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(255,255,255,0);
}
.status-dot.listening { background: var(--ok); animation: pulse 1.2s infinite; }
.status-dot.speaking { background: var(--accent); animation: pulse 0.8s infinite; }
.status-dot.working { background: var(--warn); animation: pulse 1.6s infinite; }
.status-dot.error { background: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.35); }
  100% { box-shadow: 0 0 0 16px rgba(255,255,255,0); }
}
.status-text { flex: 1; min-width: 0; }
.status-line { font-size: 24px; font-weight: 700; }
.heard-line { color: var(--muted); font-size: 16px; margin-top: 4px; word-wrap: break-word; }

.email-card { border-left: 6px solid var(--accent); }
.email-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pill { background: var(--panel-2); border-radius: 999px; padding: 2px 10px; font-size: 14px; color: var(--muted); }
.email-time { color: var(--muted); font-size: 14px; }
.email-from { font-weight: 700; font-size: 20px; }
.email-subject { font-size: 18px; margin-top: 2px; }
.email-preview { color: var(--muted); font-size: 15px; margin-top: 8px; max-height: 6.5em; overflow: hidden; }

.draft-card { border-left: 6px solid var(--ok); }
.draft-label { color: var(--ok); font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.draft-to { color: var(--muted); font-size: 15px; margin: 6px 0; }
.draft-body { white-space: pre-wrap; font-family: inherit; font-size: 16px; margin: 0; max-height: 40vh; overflow: auto; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.controls-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.btn {
  border: 0;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 700;
  padding: 16px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  min-height: 60px;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-main { background: var(--accent); color: var(--accent-text); font-size: 28px; min-height: 96px; }
.btn-main.stop { background: var(--danger); color: #fff; }
.btn-secondary { font-size: 18px; }

.log-wrap { background: var(--panel); border-radius: var(--radius); padding: 10px 16px; color: var(--muted); }
.log-wrap summary { cursor: pointer; font-size: 15px; }
.log { font-family: ui-monospace, Consolas, monospace; font-size: 12px; max-height: 30vh; overflow: auto; margin-top: 8px; white-space: pre-wrap; }

.safety { color: var(--muted); font-size: 14px; text-align: center; margin: 4px 0 24px; }

/* Car mode overlay */
.car-overlay {
  position: fixed; inset: 0; z-index: 15; background: var(--accent); color: var(--accent-text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  text-align: center; padding: 24px; cursor: pointer; user-select: none;
}
.car-overlay img { border-radius: 20px; }
.car-overlay-title { font-size: 36px; font-weight: 800; line-height: 1.15; }
.car-overlay-sub { font-size: 20px; opacity: 0.8; }

/* Settings modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-panel {
  background: var(--panel); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-panel h3 { margin: 22px 0 8px; font-size: 16px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-panel label { display: block; font-size: 15px; color: var(--muted); margin-bottom: 12px; }
.modal-panel label.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
.modal-panel input[type=text], .modal-panel input[type=password], .modal-panel input[type=number], .modal-panel textarea {
  display: block; width: 100%; margin-top: 4px; padding: 12px; font-size: 17px;
  border-radius: 10px; border: 1px solid #2a4a6e; background: var(--bg); color: var(--text);
}
.modal-panel input[type=range] { width: 100%; margin-top: 8px; }
.modal-panel input[type=checkbox] { width: 22px; height: 22px; }
.sig-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.sig-preview .hint { width: 100%; margin: 0 0 4px; }
.row { display: flex; gap: 10px; margin: 8px 0; }
.row .btn { flex: 1; }
.modal-foot { margin-top: 20px; }
.hint { color: var(--muted); font-size: 14px; }
.hint code { background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.version { text-align: center; margin-top: 10px; }
