:root {
  color-scheme: dark;
  --bg: #111418;
  --surface: #171c21;
  --surface-2: #1f252b;
  --surface-3: #252c33;
  --border: #313a42;
  --text: #edf2f4;
  --muted: #a7b0b8;
  --accent: #49c6d8;
  --accent-strong: #33a8bd;
  --accent-soft: rgba(73, 198, 216, 0.14);
  --green: #58c76f;
  --green-soft: rgba(88, 199, 111, 0.16);
  --yellow: #e3b852;
  --yellow-soft: rgba(227, 184, 82, 0.16);
  --red: #e26262;
  --red-soft: rgba(226, 98, 98, 0.16);
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(73, 198, 216, 0.10), transparent 34%),
    linear-gradient(315deg, rgba(227, 184, 82, 0.08), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  line-height: 1.5;
}

body,
button,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

input[type="range"] {
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

button {
  min-height: 40px;
  border: 1px solid rgba(73, 198, 216, 0.55);
  border-radius: 6px;
  background: var(--accent);
  color: #071114;
  cursor: pointer;
  font-weight: 700;
  padding: 9px 14px;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  background: #69d5e4;
  border-color: #8ae1ec;
}

button:active {
  background: var(--accent-strong);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0f1317;
  color: var(--text);
  padding: 8px 10px;
}

select:disabled {
  opacity: 0.72;
}

a {
  color: var(--text);
  text-decoration: none;
}

a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(17, 20, 24, 0.82);
  color: var(--muted);
  box-shadow: var(--shadow);
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

body[data-connection-state="connecting"] .status-dot {
  background: var(--accent);
}

body[data-connection-state="waiting"] .status-dot {
  background: var(--yellow);
}

body[data-connection-state="connected"] .status-dot {
  background: var(--green);
}

body[data-connection-state="disconnected"] .status-dot {
  background: var(--red);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(23, 28, 33, 0.96);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.connection-panel form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

label,
.control-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
}

.checkbox-row,
.ptt-background-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}

.checkbox-row.compact {
  align-items: flex-start;
  line-height: 1.35;
}

.checkbox-row input,
.ptt-background-toggle input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.device-grid {
  display: grid;
  gap: 12px;
}

.presence-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.presence-item {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101418;
  padding: 8px 10px;
}

.presence-item span,
.presence-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.presence-item span {
  color: var(--muted);
  font-size: 12px;
}

.presence-item strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
  margin-top: 2px;
}

.button-secondary,
.button-ghost,
.dev-toggle {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text);
}

.button-secondary:hover,
.button-ghost:hover,
.dev-toggle:hover {
  background: #303942;
  border-color: #49545d;
}

.button-ghost {
  min-height: 34px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}

.session-panel {
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

#log {
  flex: 1;
  min-height: 342px;
  margin: 0;
  padding: 14px 16px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  background: #101418;
  color: #d9e2e8;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
}

#inputArea {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 88px;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 16px;
}

.controls-panel {
  margin-top: 16px;
}

#controls-main {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  padding: 16px;
}

.controls-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 14px;
}

.controls-card-ptt {
  grid-column: 1 / -1;
}

.control-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.control-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-row output {
  min-width: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #101418;
  color: var(--text);
  padding: 3px 8px;
  text-align: center;
}

#micControls {
  display: flex;
  align-items: center;
  gap: 10px;
}

#muteBtn.muted {
  background: var(--red);
  border-color: #ee8383;
  color: #1e0707;
}

#muteBtn.unmuted {
  background: var(--green);
  border-color: #80dc91;
  color: #07140a;
}

#micIndicator {
  width: 13px;
  height: 13px;
  border: 1px solid #68747c;
  border-radius: 50%;
  background: #40484f;
}

#micIndicator.active {
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.controls-divider {
  height: 1px;
  background: var(--border);
}

#controls-dev {
  padding: 14px 16px 16px;
}

.dev-toggle {
  width: 100%;
}

.dev-hidden {
  display: none !important;
}

#devContent {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
  animation: fadeIn 0.15s ease;
}

#testSound {
  width: 100%;
}

.notice {
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.notice-error {
  background: var(--red-soft);
  border: 1px solid rgba(226, 98, 98, 0.55);
}

.app-footer {
  display: flex;
  justify-content: center;
  padding: 18px 0 0;
}

.app-footer a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.githubicon {
  width: 24px;
  height: 24px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding-top: 18px;
  }

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

  h1 {
    font-size: 28px;
  }

  .workspace-grid,
  #controls-main,
  #devContent {
    grid-template-columns: 1fr;
  }

  .session-panel {
    min-height: 420px;
  }

  #inputArea,
  .form-actions,
  .password-row {
    grid-template-columns: 1fr;
  }

  #inputArea label {
    margin-bottom: -4px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 10px 8px calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .app-header {
    gap: 10px;
    margin-bottom: 10px;
  }

  .eyebrow {
    font-size: 11px;
  }

  h1 {
    font-size: 23px;
  }

  .status-pill {
    width: 100%;
    align-items: flex-start;
    border-radius: 8px;
    font-size: 13px;
  }

  .workspace-grid {
    gap: 10px;
  }

  .panel-heading {
    min-height: 46px;
    padding: 11px 12px;
  }

  .connection-panel form,
  #controls-main,
  #controls-dev {
    padding: 12px;
  }

  .presence-grid {
    grid-template-columns: 1fr;
  }

  .session-panel {
    min-height: 360px;
  }

  #log {
    min-height: 210px;
    max-height: 36vh;
    padding: 12px;
    font-size: 12px;
  }

  #inputArea {
    grid-template-columns: minmax(0, 1fr) 72px;
    gap: 8px;
    padding: 10px 12px 12px;
  }

  #inputArea label {
    grid-column: 1 / -1;
  }

  button,
  input,
  select {
    min-height: 44px;
  }

  .button-ghost {
    min-height: 36px;
  }

  .controls-card {
    padding: 12px;
  }
}
