:root {
  --desk: #138688;
  --panel: #d4d4d4;
  --panel-edge-light: #ffffff;
  --panel-edge-dark: #505050;
  --panel-edge-deep: #000000;
  --text: #111111;
  --muted: #5c6772;
  --blue: #000080;
  --green: #0c6e50;
  --danger: #7d1f2c;
  --field: #ffffff;
  --field-edge: #808080;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "MS Sans Serif", "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 72% 76%, rgba(0, 0, 0, 0.1), transparent 26%),
    linear-gradient(180deg, #149094 0%, var(--desk) 100%);
}

button,
textarea {
  font: inherit;
}

.shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 26px 18px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
}

.chat-panel {
  width: min(100%, 620px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border: 2px solid var(--panel-edge-light);
  border-right-color: var(--panel-edge-dark);
  border-bottom-color: var(--panel-edge-dark);
  box-shadow: inset -1px -1px 0 var(--panel-edge-deep), inset 1px 1px 0 #efefef;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0 0;
}

.topbar-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.topbar h1 {
  margin: 0;
  font-size: 13px;
  color: var(--blue);
  font-weight: 700;
}

.toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost,
#send-button {
  min-width: 28px;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--panel-edge-deep);
  background: #c0c0c0;
  color: var(--text);
  box-shadow: inset 1px 1px 0 var(--panel-edge-light), inset -1px -1px 0 #808080;
  cursor: pointer;
}

.ghost:active,
#send-button:active {
  box-shadow: inset -1px -1px 0 var(--panel-edge-light), inset 1px 1px 0 #808080;
}

.ghost.danger {
  color: var(--danger);
}

.statusbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 4px 8px;
  border: 2px solid var(--field-edge);
  border-right-color: var(--panel-edge-light);
  border-bottom-color: var(--panel-edge-light);
  background: #efefef;
  min-height: 30px;
}

.metrics-panel {
  display: grid;
  gap: 8px;
  padding: 8px;
  background: linear-gradient(180deg, #ececec 0%, #d8d8d8 100%);
  border: 2px solid var(--panel-edge-light);
  border-right-color: var(--panel-edge-dark);
  border-bottom-color: var(--panel-edge-dark);
  box-shadow: inset -1px -1px 0 var(--panel-edge-deep), inset 1px 1px 0 #efefef;
}

.metrics-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.metric-card,
.metrics-block {
  padding: 7px 8px;
  background: #f7f7f7;
  border: 2px solid var(--field-edge);
  border-right-color: var(--panel-edge-light);
  border-bottom-color: var(--panel-edge-light);
}

.metric-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metrics-details summary {
  cursor: pointer;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}

.metrics-details[open] summary {
  margin-bottom: 8px;
}

.metrics-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.metrics-block h2 {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--blue);
  text-transform: uppercase;
}

.metrics-log {
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow: auto;
  font-family: "Courier New", monospace;
  font-size: 10px;
}

.metrics-entry {
  padding: 5px 6px;
  background: #ffffff;
  border: 1px solid #a7a7a7;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #dfeeff;
  color: #2f5f8d;
  font-size: 11px;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.session,
.hint,
.message-time,
.message-debug summary,
.message-meta,
.presence-mini {
  color: var(--muted);
}

.error {
  padding: 2px 8px;
  background: #f4d9de;
  color: var(--danger);
}

.messages {
  min-height: 340px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--field);
  border: 2px solid var(--field-edge);
  border-right-color: var(--panel-edge-light);
  border-bottom-color: var(--panel-edge-light);
}

.message {
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.message.pending .message-body::after {
  content: "▋";
  animation: blink 1s steps(2, start) infinite;
  color: #2f5f8d;
  margin-left: 3px;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 10px;
  text-transform: lowercase;
}

.message-role {
  color: var(--green);
  font-weight: 700;
}

.message.user .message-role {
  color: #5578a8;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 12px;
  word-break: break-word;
  color: #222222;
}

.message-debug {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #b4b4b4;
}

.message-debug-body {
  margin-top: 8px;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 11px;
}

body.debug-active .metrics-panel {
  background:
    linear-gradient(180deg, #f3f0d5 0%, #ddd7ac 100%);
  box-shadow:
    inset -1px -1px 0 var(--panel-edge-deep),
    inset 1px 1px 0 #fff7d0,
    0 0 0 1px rgba(95, 78, 10, 0.24);
}

body.debug-active .metrics-summary .metric-card strong,
body.debug-active .metrics-details summary,
body.debug-active .metrics-block h2 {
  color: #5d4200;
}

body.debug-active .message-debug {
  padding: 8px;
  background: #fff6cf;
  border: 1px solid #baa565;
}

body.debug-active .message-debug summary {
  color: #5d4200;
  font-weight: 700;
}

.composer {
  display: grid;
  gap: 6px;
}

#message-input {
  width: 100%;
  min-height: 72px;
  max-height: 240px;
  resize: vertical;
  padding: 8px 10px;
  color: var(--text);
  background: var(--field);
  border: 2px solid var(--field-edge);
  border-right-color: var(--panel-edge-light);
  border-bottom-color: var(--panel-edge-light);
  outline: none;
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hint {
  margin: 0;
  font-size: 10px;
}

#send-button {
  min-width: 82px;
}

#send-button:disabled,
.ghost:disabled,
#message-input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.presence-card {
  width: 190px;
  flex: 0 0 190px;
  display: grid;
  align-items: end;
  justify-items: center;
  gap: 8px;
  padding-bottom: 14px;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.presence-figure {
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
}

.presence-figure:focus-visible {
  outline: 2px dotted rgba(255, 255, 255, 0.72);
  outline-offset: 4px;
}

.presence-shadow {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 136px;
  height: 36px;
  border-radius: 999px;
  transform: translateX(-50%);
  background:
    radial-gradient(ellipse at center, rgba(5, 9, 18, 0.52) 0%, rgba(5, 9, 18, 0.28) 48%, rgba(5, 9, 18, 0) 78%),
    radial-gradient(ellipse at 50% 62%, rgba(104, 173, 255, 0.16) 0%, rgba(104, 173, 255, 0) 72%);
  filter: blur(4px);
  opacity: 0.96;
}

.presence-ring,
.presence-ring::before {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  content: "";
}

.presence-ring {
  inset: 18px 18px 26px;
  border: 1px solid rgba(178, 209, 255, 0.55);
  box-shadow: 0 0 18px rgba(125, 172, 255, 0.24);
  transition: transform 160ms linear;
}

.presence-ring::before {
  inset: 10px;
  border: 1px dashed rgba(255, 223, 140, 0.5);
}

.presence-orb-shell {
  position: relative;
  width: 156px;
  height: 156px;
  margin: 0 auto;
  border-radius: 50%;
  padding: 14px;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 25%),
    radial-gradient(circle at 72% 68%, rgba(113, 78, 255, 0.18), rgba(113, 78, 255, 0) 42%),
    rgba(5, 8, 16, 0.82);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 12px 28px rgba(0, 0, 0, 0.3);
}

.presence-orb-shell canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
}

.presence-caption {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(11, 18, 36, 0.7);
  border: 1px solid rgba(170, 192, 255, 0.28);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #edf2ff;
}

.presence-mini {
  display: grid;
  gap: 2px;
  font-size: 11px;
  text-align: center;
}

.presence-card[data-state="connecting"] .presence-ring,
.presence-card[data-state="loading"] .presence-ring,
.presence-card[data-state="working"] .presence-ring,
.presence-card[data-state="streaming"] .presence-ring,
.presence-card[data-state="resetting"] .presence-ring {
  transform: rotate(20deg);
}

.presence-card[data-state="grounded"] .presence-ring,
.presence-card[data-state="complete"] .presence-ring {
  border-color: rgba(138, 227, 187, 0.46);
  box-shadow: 0 0 24px rgba(138, 227, 187, 0.22);
}

.presence-card[data-state="error"] .presence-ring {
  border-color: rgba(243, 138, 152, 0.46);
  box-shadow: 0 0 26px rgba(243, 138, 152, 0.26);
}

.presence-card[data-state="speaking"] .presence-ring {
  border-color: rgba(138, 227, 187, 0.58);
  box-shadow: 0 0 26px rgba(138, 227, 187, 0.28);
}

.presence-card[data-state="speaking"] .presence-shadow {
  transform: translateX(-50%) scale(1.08);
}

.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;
}

@keyframes blink {
  50% {
    opacity: 0.2;
  }
}

@media (max-width: 860px) {
  .shell {
    min-height: 0;
    padding: 18px 12px 14px;
    flex-direction: column;
    gap: 14px;
  }

  .chat-panel {
    width: min(100%, 620px);
  }

  .presence-card {
    width: auto;
    flex: none;
    padding-bottom: 4px;
  }

  .presence-mini {
    display: none;
  }

  .metrics-summary,
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 10px 8px 10px;
  }

  .chat-panel {
    width: 100%;
    padding: 8px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .messages {
    min-height: 280px;
    max-height: 48vh;
  }

  .metrics-summary,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .composer-row {
    flex-direction: column;
    align-items: stretch;
  }

  #send-button {
    width: 100%;
  }
}
