/* Aura Voice Companion — calm, high-contrast, large targets */

:root {
  --bg: #0a0a0b;
  --bg-elevated: #121214;
  --bg-subtle: #1a1a1e;
  --fg: #f4f4f5;
  --fg-muted: #a1a1aa;
  --fg-subtle: #71717a;
  --border: color-mix(in oklab, var(--fg) 12%, transparent);
  --border-strong: color-mix(in oklab, var(--fg) 22%, transparent);
  --accent: #e8eaed;
  --accent-fg: #0a0a0b;
  --listen: #5b9fd4;
  --speak: #6dbf8a;
  --danger: #d97878;
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
  --text-sm: clamp(0.875rem, 0.82rem + 0.25vw, 0.9375rem);
  --text-base: clamp(1.05rem, 0.95rem + 0.4vw, 1.125rem);
  --text-lg: clamp(1.2rem, 1.05rem + 0.6vw, 1.35rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1vw, 2rem);
  --text-2xl: clamp(2rem, 1.5rem + 1.5vw, 2.75rem);
  --leading-normal: 1.55;
  --leading-tight: 1.15;
  --motion-quick: 150ms;
  --motion-fast: 250ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow: 0 12px 40px color-mix(in oklab, #000 45%, transparent);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button:not(:disabled),
[role="button"]:not(:disabled) {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  top: calc(var(--safe-t) + var(--space-3));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + var(--space-4)) var(--space-4) calc(var(--safe-b) + var(--space-6));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, color-mix(in oklab, var(--fg) 18%, transparent), transparent 55%),
    var(--bg-elevated);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
}

.brand-tag {
  margin: 2px 0 0;
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

.top-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  min-height: 44px;
  font-weight: 500;
  background: transparent;
  transition:
    background var(--motion-quick) var(--ease-out),
    border-color var(--motion-quick) var(--ease-out),
    opacity var(--motion-quick) var(--ease-out),
    transform var(--motion-quick) var(--ease-out);
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover {
  opacity: 0.92;
}
.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
}
.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}
.btn-ghost {
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  color: var(--fg);
  background: var(--bg-elevated);
}

.status-panel {
  text-align: center;
  padding: var(--space-2) var(--space-3);
}

.status-label {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status-detail {
  margin: var(--space-2) 0 0;
  color: var(--fg-muted);
  font-size: var(--text-base);
  max-width: 36ch;
  margin-inline: auto;
}

body.is-listening .status-label {
  color: var(--listen);
}
body.is-speaking .status-label {
  color: var(--speak);
}
body.is-error .status-label {
  color: var(--danger);
}

body.is-thinking .status-label {
  color: var(--fg);
}

.mic-help {
  margin: 0 auto var(--space-4);
  max-width: 36rem;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid color-mix(in oklab, var(--danger) 40%, var(--border));
  background: color-mix(in oklab, var(--danger) 10%, var(--bg-elevated));
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: flex-start;
}

.mic-help[hidden] {
  display: none;
}

.mic-help p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--fg-muted);
}

.mic-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) 0 var(--space-2);
}

.mic-btn {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  transition:
    background var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}
.mic-btn:hover {
  border-color: color-mix(in oklab, var(--fg) 35%, transparent);
}
.mic-btn[aria-pressed="true"] {
  background: color-mix(in oklab, var(--listen) 18%, var(--bg-elevated));
  border-color: color-mix(in oklab, var(--listen) 55%, transparent);
  color: var(--listen);
}
body.is-speaking .mic-btn {
  background: color-mix(in oklab, var(--speak) 14%, var(--bg-elevated));
  border-color: color-mix(in oklab, var(--speak) 45%, transparent);
  color: var(--speak);
}

.mic-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid color-mix(in oklab, var(--listen) 40%, transparent);
  opacity: 0;
  pointer-events: none;
}
.mic-ring-2 {
  inset: -18px;
  border-color: color-mix(in oklab, var(--listen) 22%, transparent);
}
body.is-listening .mic-ring {
  animation: pulse-ring 1.8s var(--ease-out) infinite;
  opacity: 1;
}
body.is-listening .mic-ring-2 {
  animation: pulse-ring 1.8s var(--ease-out) 0.35s infinite;
  opacity: 1;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.92);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.08);
    opacity: 0;
  }
}

.mic-hint {
  margin: 0;
  color: var(--fg-subtle);
  font-size: var(--text-sm);
}

.type-cmd {
  display: flex;
  gap: var(--space-2);
  width: 100%;
}
.type-cmd input {
  flex: 1;
  min-height: 48px;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
}
.type-cmd input::placeholder {
  color: var(--fg-subtle);
}
.type-cmd .btn {
  flex-shrink: 0;
}

.transcript-panel {
  display: grid;
  gap: var(--space-3);
}

@media (min-width: 560px) {
  .transcript-panel {
    grid-template-columns: 1fr 1fr;
  }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
}

.panel-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-subtle);
}

.panel-body {
  margin: var(--space-3) 0 0;
  font-size: var(--text-lg);
  line-height: 1.45;
  min-height: 2.8em;
  color: var(--fg);
  word-break: break-word;
}

.content-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.content-panel[hidden] {
  display: none;
}

.content-head .meta,
.menu-block .meta {
  margin: var(--space-2) 0 0;
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

#page-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  text-transform: none;
  letter-spacing: -0.02em;
  color: var(--fg);
  font-weight: 400;
}

/* Menu tree */
.menu-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  background: var(--bg);
}
.menu-block[hidden] {
  display: none;
}
.menu-heading {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-subtle);
}
.menu-tree {
  margin-top: var(--space-3);
  max-height: 220px;
  overflow: auto;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
.menu-tree ul {
  margin: 0;
  padding: 0 0 0 var(--space-4);
  list-style: none;
}
.menu-tree > ul {
  padding-left: 0;
}
.menu-tree li {
  margin: var(--space-1) 0;
  line-height: 1.4;
}
.menu-tree .menu-group-title {
  color: var(--fg);
  font-weight: 600;
  margin: var(--space-3) 0 var(--space-2);
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
}
.menu-tree .menu-group-title:first-child {
  margin-top: 0;
}
.menu-tree a {
  color: var(--fg-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.menu-tree a:hover {
  color: var(--fg);
  border-bottom-color: var(--border-strong);
}
.menu-tree .has-kids > .item-label {
  color: var(--fg);
}
.menu-tree .depth-1 {
  color: var(--fg-muted);
}
.menu-tree .depth-2 {
  color: var(--fg-subtle);
}
.menu-actions {
  margin-top: var(--space-3);
}

.content-body {
  max-height: 240px;
  overflow: auto;
  color: var(--fg-muted);
  font-size: var(--text-base);
  padding-right: var(--space-2);
  border-radius: var(--radius-md);
}

.content-body p {
  margin: 0 0 var(--space-3);
}

.content-body p.is-active {
  color: var(--fg);
  background: color-mix(in oklab, var(--speak) 10%, transparent);
  border-radius: var(--radius-xs);
  padding: 2px 4px;
}

.content-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.quick-cmds {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  padding-bottom: var(--space-2);
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg-muted);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  min-height: 44px;
  font-size: var(--text-sm);
  font-weight: 500;
  transition:
    background var(--motion-quick) var(--ease-out),
    color var(--motion-quick) var(--ease-out),
    border-color var(--motion-quick) var(--ease-out);
}
.chip:hover {
  color: var(--fg);
  border-color: var(--border-strong);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, #000 55%, transparent);
  z-index: 40;
}
.backdrop[hidden] {
  display: none;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100%, 400px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  animation: drawer-in var(--motion-fast) var(--ease-out);
}
.drawer[hidden] {
  display: none;
}

@keyframes drawer-in {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.drawer-inner {
  margin: var(--space-3);
  margin-bottom: calc(var(--safe-b) + var(--space-3));
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100dvh - var(--space-6));
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
.field em {
  font-style: normal;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.field input[type="text"],
.field input[type="range"],
.field select {
  width: 100%;
}
.field input[type="text"],
.field select {
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}
.field-check {
  flex-direction: row;
  align-items: flex-start;
  gap: var(--space-3);
}
.field-check input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--fg);
}

.drawer-note {
  margin: 0;
  color: var(--fg-subtle);
  font-size: var(--text-sm);
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.help-group h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-subtle);
}
.help-group ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.help-group li {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
}
.help-group strong {
  display: block;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 2px;
}
.help-group span {
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 390px) {
  .mic-btn {
    width: 112px;
    height: 112px;
  }
  .brand-tag {
    display: none;
  }
}

.struct-body {
  margin-top: var(--space-3);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  line-height: 1.45;
}
.struct-body p {
  margin: 0 0 var(--space-2);
}
.struct-body strong {
  color: var(--fg);
  font-weight: 600;
}
#profile-chip:not([hidden]) {
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ——— Mobile / responsive polish ——— */
html,
body {
  overflow-x: clip;
  max-width: 100%;
}

.app {
  width: 100%;
  max-width: min(720px, 100%);
  min-width: 0;
  overflow-x: clip;
}

.topbar {
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand {
  min-width: 0;
  flex: 1 1 auto;
}

.brand > div {
  min-width: 0;
}

.brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12ch;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1);
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.top-actions .btn {
  padding: 0.5rem 0.7rem;
  min-height: 44px;
  font-size: var(--text-sm);
}

#page-meta,
.meta {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.content-body,
.menu-tree,
.panel-body {
  overflow-wrap: anywhere;
  max-width: 100%;
}

.content-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.content-actions .btn {
  flex: 1 1 auto;
  min-width: min(100%, 7.5rem);
}

.drawer {
  width: min(100vw, 400px);
  max-width: 100%;
}

.drawer-inner {
  width: auto;
  max-width: 100%;
}

.field input[type="text"],
.field select,
.field input[type="range"] {
  max-width: 100%;
  box-sizing: border-box;
}

.type-cmd {
  min-width: 0;
}
.type-cmd input {
  min-width: 0;
  width: 100%;
}

/* Compact header on phones */
@media (max-width: 640px) {
  .app {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
    gap: var(--space-4);
  }

  .topbar {
    gap: var(--space-2);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-name {
    font-size: var(--text-lg);
    max-width: 10ch;
  }

  .brand-tag {
    display: none;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
  }

  /* When profile chip visible, allow 4 cols */
  .top-actions:has(#profile-chip:not([hidden])) {
    grid-template-columns: repeat(4, 1fr);
  }

  .top-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 0.55rem 0.35rem;
    font-size: 0.8125rem;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    color: var(--fg-muted);
  }

  .top-actions .btn:hover {
    color: var(--fg);
    background: var(--bg-subtle);
  }

  #profile-chip:not([hidden]) {
    max-width: none;
  }

  .mic-btn {
    width: 120px;
    height: 120px;
  }

  .mic-ring-2 {
    inset: -14px;
  }

  .status-detail {
    max-width: 100%;
    font-size: var(--text-sm);
    padding-inline: var(--space-2);
  }

  .panel {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }

  .panel-body {
    font-size: var(--text-base);
    min-height: 2.2em;
  }

  .quick-cmds {
    justify-content: flex-start;
    gap: var(--space-2);
    /* horizontal scroll chips without page overflow */
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: var(--space-3);
    margin-inline: calc(var(--space-3) * -1);
    padding-inline: var(--space-3);
    max-width: 100vw;
  }

  .quick-cmds::-webkit-scrollbar {
    display: none;
  }

  .chip {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .drawer {
    inset: 0;
    width: 100%;
  }

  .drawer-inner {
    margin: var(--space-2);
    margin-bottom: calc(var(--safe-b) + var(--space-2));
    padding: var(--space-4);
    max-height: calc(100dvh - var(--space-4));
    border-radius: var(--radius-lg);
  }

  .content-panel {
    padding: var(--space-4);
  }

  .menu-tree {
    max-height: 220px;
  }

  .content-body {
    max-height: min(50dvh, 360px);
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .top-actions {
    grid-template-columns: repeat(3, 1fr);
  }

  .top-actions .btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.25rem;
  }

  .mic-btn {
    width: 108px;
    height: 108px;
  }

  .type-cmd .btn {
    padding-inline: 0.75rem;
  }
}

/* Landscape phones: keep mic usable, less vertical padding */
@media (max-height: 480px) and (orientation: landscape) {
  .mic-stage {
    padding: var(--space-2) 0;
  }
  .mic-btn {
    width: 88px;
    height: 88px;
  }
  .status-panel {
    padding: 0;
  }
}
