:root {
  color-scheme: light dark;
  --page-bg: #f5f7fb;
  --page-glow: #ffffff;
  --panel-surface: #ffffff;
  --panel-shadow: rgba(15, 23, 42, 0.06);
  --surface-raised: #fbfdff;
  --surface-input: #ffffff;
  --surface-dialog: #ffffff;
  --surface-backdrop: rgba(15, 23, 42, 0.34);
  --text: #1f2937;
  --muted-text: #4b5563;
  --border: #d1d5db;
  --button-primary: #005b99;
  --button-primary-text: #ffffff;
  --button-secondary: #4b5563;
  --button-secondary-text: #ffffff;
  --danger-text: #a61b1b;
  --focus-ring: #0a66b2;
  --menu-active-surface: #e5f1fb;
  --menu-active-outline: #93c5fd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #111827;
    --page-glow: #1b2a41;
    --panel-surface: #18202d;
    --panel-shadow: rgba(0, 0, 0, 0.4);
    --surface-raised: #101827;
    --surface-input: #0f1724;
    --surface-dialog: #18202d;
    --surface-backdrop: rgba(2, 6, 23, 0.68);
    --text: #e5edf6;
    --muted-text: #afbccd;
    --border: #334155;
    --button-primary: #2d84c8;
    --button-primary-text: #f8fbff;
    --button-secondary: #4d5d72;
    --button-secondary-text: #f8fbff;
    --danger-text: #ff9a9a;
    --focus-ring: #7cc7ff;
    --menu-active-surface: #1e3a5f;
    --menu-active-outline: #60a5fa;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: radial-gradient(circle at top left, var(--page-glow), var(--page-bg));
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.85rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 1.2rem;
  line-height: 1.3;
  margin-bottom: 6px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--panel-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 1px 2px var(--panel-shadow);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.volume-controls {
  margin-top: 8px;
}

.volume-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.volume-controls input[type="range"] {
  width: 160px;
}

input,
select,
button,
textarea {
  font: inherit;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 44px;
}

button,
input,
select,
textarea {
  line-height: 1.3;
}

input,
select,
textarea {
  color: var(--text);
  background: var(--surface-input);
}

button {
  background: var(--button-primary);
  color: var(--button-primary-text);
  border-color: var(--button-primary);
  cursor: pointer;
}

button.secondary {
  background: var(--button-secondary);
  color: var(--button-secondary-text);
  border-color: var(--button-secondary);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.menu-item-touch:focus-visible,
.actions-item-btn:focus-visible,
#menu-list:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.status {
  color: var(--muted-text);
}

.status.error {
  color: var(--danger-text);
}

.grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(520px, 1.9fr);
  gap: 12px;
}

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 440px;
  overflow-y: auto;
  background: var(--panel-surface);
}

.menu-item {
  width: 100%;
  padding: 8px;
  text-align: left;
  border-radius: 0;
  background: var(--panel-surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  cursor: default;
}

.menu-item:last-child {
  border-bottom: 0;
}

.menu-item.active {
  background: var(--menu-active-surface);
  outline: 2px solid var(--menu-active-outline);
}

.menu-item-touch {
  width: 100%;
  min-height: 44px;
  padding: 8px;
  text-align: left;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
}

.history {
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 480px;
  height: 62vh;
  overflow-y: auto;
  padding: 8px;
  color: var(--text);
  background: var(--surface-raised);
  white-space: pre-wrap;
  resize: none;
}

.history-entry {
  margin: 0 0 6px;
}

.history-log {
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 480px;
  height: 62vh;
  overflow-y: auto;
  padding: 8px;
  color: var(--text);
  background: var(--surface-raised);
}

.history-line {
  margin: 0 0 6px 0;
  white-space: pre-wrap;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.history-toggle-title {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  cursor: default;
}

.actions-btn {
  margin-left: 8px;
}

.actions-list {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 40vh;
  overflow-y: auto;
  background: var(--surface-raised);
}

.actions-item-btn {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  min-height: 44px;
}

.actions-list li:last-child .actions-item-btn {
  border-bottom: 0;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(420px, 92vw);
  color: var(--text);
  background: var(--surface-dialog);
}

dialog::backdrop {
  background: var(--surface-backdrop);
}

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

.footer {
  text-align: right;
}

#login-dialog input,
#login-dialog button {
  min-height: 44px;
}

#connect-form label {
  display: grid;
  gap: 6px;
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  main {
    gap: 14px;
  }

  .panel {
    padding: 14px;
  }

  .row {
    gap: 10px;
  }

  .history {
    display: none;
  }

  .history-log {
    display: block;
    min-height: 300px;
    height: 42vh;
  }

  .history-toggle-title {
    cursor: pointer;
    text-decoration: underline;
  }
}
