:root {
  color-scheme: dark;
  --bg: #0b1022;
  --bg-mid: #101735;
  --glow: rgba(61, 28, 115, .72);
  --panel: #151b32;
  --panel-alt: #1a213b;
  --stroke: #293257;
  --stroke-strong: #3b4670;
  --button: #1a2138;
  --active: #432093;
  --active-border: #7c4dff;
  --key: #222946;
  --nav-start: #171c35;
  --nav-end: #21164b;
  --nav-active: #4722a2;
  --text: #f4f5ff;
  --muted: #aeb5cc;
  --accent: #8a5cff;
  --danger: #ff647c;
  --success: #48d59b;
  --shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fc;
  --bg-mid: #fff;
  --glow: rgba(124, 77, 255, .12);
  --panel: #fff;
  --panel-alt: #f8f7fd;
  --stroke: #e5e7f0;
  --stroke-strong: #daddE8;
  --button: #fff;
  --active: #f2ecff;
  --active-border: #b79aff;
  --key: #fff;
  --nav-start: #fff;
  --nav-end: #f8f5ff;
  --nav-active: #f0eaff;
  --text: #111827;
  --muted: #697182;
  --accent: #6b35f2;
  --danger: #d93155;
  --success: #148a60;
  --shadow: 0 20px 60px rgba(39, 30, 82, .1);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { background: var(--bg); }
body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(80% 45% at 8% 72%, var(--glow), transparent 70%),
    linear-gradient(145deg, var(--bg-mid), var(--bg) 52%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }

.app-shell { width: 100%; min-height: 100dvh; }
.desktop-header { display: none; }
.page { display: none; min-height: calc(100dvh - 102px); padding-bottom: calc(102px + env(safe-area-inset-bottom)); }
.page.active { display: block; animation: page-in .22s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } }
.content { width: min(100%, 740px); min-height: calc(100dvh - 102px); margin: 0 auto; padding: 30px 20px 24px; }
.narrow-content { max-width: 620px; }

.button {
  min-height: 52px;
  border: 1px solid var(--stroke);
  border-radius: 9px;
  background: var(--button);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 16px;
  font-weight: 650;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease;
}
.button:hover { border-color: var(--active-border); }
.button:active { transform: scale(.98); }
.button.primary { background: var(--active); border-color: var(--active-border); color: #fff; }
.button.small { min-height: 40px; font-size: 13px; }
.button:disabled { opacity: .58; cursor: wait; }
.two-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--stroke); border-radius: 9px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.input {
  width: 100%; height: 54px; border: 1px solid var(--stroke); border-radius: 9px;
  background: var(--panel); color: var(--text); padding: 0 16px;
}
.input::placeholder { color: var(--muted); }
.input:disabled { opacity: .65; }

/* Main page */
.home-content { display: flex; flex-direction: column; align-items: center; padding-top: 34px; }
.power-button {
  width: 88px; height: 88px; border-radius: 50%; border: 1.5px solid var(--active-border);
  background: var(--panel); color: var(--text); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 0 0 8px rgba(124,77,255,.05), 0 15px 38px rgba(0,0,0,.16);
  transition: transform .18s ease, box-shadow .18s ease;
}
.power-button svg { width: 43px; height: 43px; stroke-width: 1.7; }
.power-button:active { transform: scale(.94); }
.power-button:hover { box-shadow: 0 0 0 10px rgba(124,77,255,.1), 0 18px 42px rgba(0,0,0,.2); }
.power-label { color: var(--muted); margin: 10px 0 28px; font-size: 13px; }
.home-actions { width: 100%; }
.screen-panel {
  width: 100%; flex: 1; min-height: 360px; margin-top: 12px; border: 1px solid var(--stroke);
  border-radius: 10px; background: var(--panel); display: grid; place-items: center; overflow: hidden;
}
.screen-panel.has-image { cursor: zoom-in; background: #070914; }
.screen-panel > img { width: 100%; height: 100%; min-height: 360px; object-fit: contain; display: block; }
.screen-placeholder { color: var(--muted); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 7px; }
.screen-placeholder svg { width: 45px; height: 45px; opacity: .62; margin-bottom: 4px; }
.screen-placeholder strong { color: var(--text); font-size: 15px; }
.screen-placeholder span { font-size: 12px; }

/* Search */
.search-content { padding-top: 42px; }
.action-row {
  width: 100%; min-height: 82px; display: grid; grid-template-columns: 46px 1fr 22px; align-items: center; gap: 13px;
  padding: 13px 15px; margin: 0 0 12px; border: 1px solid var(--stroke); border-radius: 9px;
  background: var(--panel); color: var(--text); text-align: left; cursor: pointer;
}
.action-row:hover { border-color: var(--active-border); }
.action-row > span:nth-child(2) { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.action-row strong { font-size: 17px; }
.action-row small { color: var(--muted); font-size: 13px; }
.action-icon { width: 46px; height: 46px; border-radius: 9px; background: var(--active); color: #fff; display: grid; place-items: center; }
.action-icon svg { width: 23px; height: 23px; }
.chevron { color: var(--muted); width: 19px; }
.section-title { margin: 30px 0 20px; text-align: center; font-size: 20px; }
.number-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px clamp(24px, 13vw, 82px); justify-items: center; }
.number-key {
  width: 62px; height: 62px; border-radius: 50%; border: 1px solid var(--stroke); background: var(--key);
  color: var(--text); font-size: 27px; cursor: pointer; transition: transform .15s, border-color .15s;
}
.number-key:hover { border-color: var(--active-border); }
.number-key:active { transform: scale(.92); }
.number-grid.compact { gap: 16px clamp(18px, 11vw, 68px); }

/* Voice */
.voice-content { padding-top: 28px; }
.segmented { display: grid; grid-template-columns: 1fr 1.18fr 1.15fr .72fr; gap: 5px; background: var(--panel); border: 1px solid var(--stroke); border-radius: 9px; padding: 5px; }
.segmented button { height: 41px; padding: 0 5px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 750; cursor: pointer; }
.segmented button.active { background: var(--active); color: #fff; border-color: var(--active-border); }
.voice-pane { display: none; padding-top: 20px; }
.voice-pane.active { display: block; }
.api-card { min-height: 86px; padding: 15px 16px; display: flex; justify-content: space-between; align-items: center; }
.api-card span { display: flex; flex-direction: column; gap: 8px; }
.api-card small { color: var(--muted); }
.api-card > svg { color: var(--accent); width: 37px; height: 37px; }
.listen-button { width: 100%; height: 64px; margin-top: 20px; font-size: 16px; }
.listen-button.listening { animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(138,92,255,.16); } }
.result-panel { min-height: 78px; margin-top: 18px; padding: 17px; display: grid; place-items: center; text-align: center; color: var(--muted); line-height: 1.45; }
#manualCommand { margin-top: 18px; }
.execute-button { width: 100%; height: 56px; margin-top: 16px; }
.empty-state { min-height: 330px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; color: var(--accent); margin-bottom: 6px; }
.empty-state strong { color: var(--text); font-size: 17px; }
.empty-state span { max-width: 360px; line-height: 1.5; font-size: 13px; }
.logs-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.logs-list { min-height: 290px; margin-top: 12px; padding: 14px; color: var(--muted); font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.log-entry { padding: 8px 0; border-bottom: 1px solid var(--stroke); }

/* Settings */
.settings-content { padding-top: 28px; padding-bottom: 36px; }
.shortcut-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shortcut { height: 40px; border: 1px solid var(--stroke); border-radius: 8px; background: var(--button); color: var(--text); font-size: 13px; cursor: pointer; }
.shortcut:hover { border-color: var(--active-border); }
.section-heading { display: flex; align-items: center; gap: 9px; margin: 24px 0 9px; font-size: 18px; }
.section-heading svg { width: 21px; height: 21px; color: var(--accent); }
.prompt-link { width: 100%; padding: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-align: center; margin-bottom: 8px; }
.compact-row { min-height: 72px; margin-top: 12px; }
.clipboard-heading { margin-top: 26px; }
.clipboard-card { padding: 16px; }
.clipboard-card > div { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.clipboard-card small { color: var(--muted); line-height: 1.45; }
.clipboard-card .button { width: 100%; }
.device-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.device-button { min-height: 72px; flex-direction: column; gap: 5px; font-size: 12px; }

/* Account */
.login-content { padding-top: 42px; }
.account-card { padding: 20px 18px 18px; display: grid; grid-template-columns: 52px 1fr; gap: 15px; }
.account-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: var(--active); color: #fff; }
.account-icon svg { width: 27px; height: 27px; }
.account-card h1 { margin: 2px 0 8px; font-size: 21px; }
.account-card p { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.4; }
.account-card form { grid-column: 1 / -1; margin-top: 6px; display: flex; flex-direction: column; gap: 12px; }
.account-card label { display: flex; flex-direction: column; gap: 7px; }
.account-card label > span { color: var(--muted); font-size: 12px; padding-left: 2px; }
.login-button { width: 100%; margin-top: 4px; }
.theme-card { margin-top: 18px; padding: 18px; }
.theme-card h2 { margin: 0 0 16px; font-size: 18px; }
.theme-button.selected { background: var(--active); border-color: var(--active-border); color: #fff; }
.account-card.logged-in form label { display: none; }

/* Navigation */
.bottom-nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; min-height: 78px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  background: linear-gradient(90deg, var(--nav-start), var(--nav-end));
  border-top: 1px solid var(--stroke); box-shadow: 0 -15px 40px rgba(0,0,0,.16);
}
.bottom-nav button { position: relative; min-width: 0; height: 64px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; }
.bottom-nav button.active { background: var(--nav-active); color: #fff; }
.bottom-nav svg { width: 25px; height: 25px; }
.bottom-nav span { font-size: 10px; white-space: nowrap; }
.bottom-nav i { position: absolute; width: 7px; height: 7px; top: 8px; right: calc(50% - 18px); border-radius: 50%; background: var(--success); border: 1px solid var(--nav-start); display: none; }
.bottom-nav i.online { display: block; }

/* Modal and toast */
.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: end center; padding: 18px; background: rgba(3,5,15,.7); backdrop-filter: blur(7px); }
.modal { width: min(100%, 430px); max-height: calc(100dvh - 36px); overflow: auto; padding: 24px 20px 18px; border: 1px solid var(--stroke-strong); border-radius: 18px; background: var(--panel-alt); box-shadow: var(--shadow); animation: modal-in .18s ease-out; }
@keyframes modal-in { from { transform: translateY(18px); opacity: 0; } }
.modal-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--active); color: #fff; display: grid; place-items: center; }
.modal h2 { margin: 16px 0 9px; font-size: 21px; }
.modal p { color: var(--muted); line-height: 1.5; margin: 0 0 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.modal textarea { width: 100%; min-height: 135px; resize: vertical; padding: 13px; border: 1px solid var(--stroke); border-radius: 9px; background: var(--panel); color: var(--text); line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.modal-actions .button { min-height: 44px; }
.modal-actions .button.danger { color: #fff; background: #9d2440; border-color: var(--danger); }
.toast-region { position: fixed; z-index: 200; left: 16px; right: 16px; bottom: calc(94px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 430px; padding: 12px 16px; border: 1px solid var(--stroke-strong); border-radius: 10px; background: var(--panel-alt); color: var(--text); box-shadow: var(--shadow); animation: toast-in .2s ease-out; font-size: 13px; text-align: center; }
.toast.error { border-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.image-viewer { position: fixed; z-index: 300; inset: 0; background: rgba(2, 3, 10, .96); display: grid; place-items: center; padding: 20px; }
.image-viewer img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.image-viewer button { position: absolute; z-index: 1; top: max(16px, env(safe-area-inset-top)); right: 16px; width: 46px; height: 46px; border: 1px solid rgba(255,255,255,.25); border-radius: 50%; background: rgba(10,12,24,.72); color: #fff; font-size: 31px; line-height: 1; cursor: pointer; }

@media (min-width: 760px) {
  body { padding: 24px; }
  .app-shell { width: min(100%, 1100px); min-height: calc(100dvh - 48px); margin: auto; border: 1px solid var(--stroke); border-radius: 20px; overflow: hidden; background: color-mix(in srgb, var(--bg) 90%, transparent); box-shadow: var(--shadow); position: relative; }
  .desktop-header { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 26px; border-bottom: 1px solid var(--stroke); background: var(--panel); }
  .brand { display: flex; align-items: center; gap: 11px; font-weight: 760; }
  .brand img { width: 36px; height: 36px; border-radius: 9px; }
  .connection-pill { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
  .connection-pill span { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
  .connection-pill.online span { background: var(--success); }
  main { margin-left: 100px; }
  .page { min-height: calc(100dvh - 122px); padding-bottom: 0; }
  .content { min-height: calc(100dvh - 122px); padding-bottom: 38px; }
  .bottom-nav { position: absolute; left: 0; right: auto; top: 72px; bottom: 0; width: 100px; min-height: 0; padding: 13px 10px; display: flex; flex-direction: column; gap: 7px; border-top: 0; border-right: 1px solid var(--stroke); box-shadow: none; }
  .bottom-nav button { width: 100%; height: 70px; flex: 0 0 auto; }
  .bottom-nav span { font-size: 11px; }
  .bottom-nav i { top: 10px; right: 24px; }
  .modal-backdrop { place-items: center; }
  .toast-region { bottom: 30px; left: 130px; }
  .home-content { padding-top: 38px; }
  .screen-panel { min-height: 330px; }
}

@media (max-width: 390px) {
  .content { padding-left: 15px; padding-right: 15px; }
  .bottom-nav { padding-left: 4px; padding-right: 4px; gap: 1px; }
  .bottom-nav span { font-size: 9px; }
  .shortcut { font-size: 11px; }
  .segmented button { font-size: 9px; }
  .number-grid { column-gap: 16px; }
}
