:root {
  color-scheme: light;
  --desktop-a: #667eea;
  --desktop-b: #764ba2;
  --taskbar: #1e1e1e;
  --taskbar-button: #2d2d2d;
  --taskbar-button-active: #4d4d4d;
  --surface: #ffffff;
  --panel: #f5f5f5;
  --line: #dddddd;
  --line-strong: #bfbfbf;
  --text: #111827;
  --muted: #666666;
  --primary: #667eea;
  --primary-hover: #5568d3;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #27ae60;
  --success-hover: #219a52;
  --warning-bg: #fff3cd;
  --warning-text: #856404;
  --ok-bg: #d4edda;
  --ok-text: #155724;
  --bad-bg: #f8d7da;
  --bad-text: #721c24;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Tahoma, "Microsoft YaHei UI", system-ui, sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

button,
label,
input[type="checkbox"],
input[type="radio"] {
  cursor: pointer;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.16);
}

[hidden] {
  display: none !important;
}

.desktop {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(135deg, var(--desktop-a) 0%, var(--desktop-b) 100%);
}

.desktop-icons {
  position: relative;
  width: 100%;
  height: calc(100vh - 50px);
  overflow: hidden;
}

.desktop-icon {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100px;
  min-height: 86px;
  padding: 10px;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  user-select: none;
  transition: background 0.2s ease;
}

.desktop-icon:nth-child(1) {
  top: 20px;
  left: 8px;
}

.desktop-icon:nth-child(2) {
  top: 112px;
  left: 8px;
}

.desktop-icon:nth-child(3) {
  top: 204px;
  left: 8px;
}

.desktop-icon:nth-child(4) {
  top: 296px;
  left: 8px;
}

.desktop-icon:hover,
.desktop-icon:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}

.icon-image {
  display: block;
  margin-bottom: 8px;
  font-size: 48px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.icon-label {
  display: block;
  max-width: 86px;
  overflow: hidden;
  color: #fff;
  font-size: 12px;
  text-align: center;
  text-overflow: ellipsis;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.windows-container {
  position: fixed;
  inset: 0 0 50px;
  pointer-events: none;
}

.windows-container > * {
  pointer-events: auto;
}

.window {
  position: fixed;
  display: flex;
  min-width: 400px;
  min-height: 300px;
  overflow: hidden;
  background: #fff;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  flex-direction: column;
}

.window.maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: calc(100vh - 50px) !important;
  border-radius: 0;
}

.window.minimized {
  display: none;
}

.window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--desktop-a) 0%, var(--desktop-b) 100%);
  user-select: none;
}

.window-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
}

.window-title span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.window-controls {
  display: flex;
  gap: 5px;
}

.window-control-btn {
  display: grid;
  width: 24px;
  height: 24px;
  min-width: 24px;
  place-items: center;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

.window-control-btn:hover {
  background: rgba(255, 255, 255, 0.32);
}

.window-control-btn.close:hover {
  background: var(--danger);
}

.window-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 20px;
  background: var(--panel);
}

.taskbar {
  position: fixed;
  z-index: 10000;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  height: 50px;
  padding: 0 10px;
  background: var(--taskbar);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.taskbar-left,
.taskbar-right {
  display: flex;
  align-items: center;
}

.start-button,
.taskbar-item {
  min-height: 32px;
  border-radius: 4px;
  background: var(--taskbar-button);
  color: #fff;
  transition: background 0.2s ease;
}

.start-button {
  padding: 0 20px;
  font-size: 14px;
}

.taskbar-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 12px;
  white-space: nowrap;
}

.start-button:hover,
.taskbar-item:hover,
.taskbar-item.active {
  background: var(--taskbar-button-active);
}

.taskbar-items {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 5px;
  margin-left: 10px;
  overflow-x: auto;
}

.system-tray {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.start-menu {
  position: fixed;
  bottom: 60px;
  left: 10px;
  z-index: 10001;
  width: 280px;
  overflow: hidden;
  border-radius: 8px;
  background: #2d2d2d;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.menu-section {
  padding: 9px 0;
}

.menu-title {
  padding: 8px 15px;
  color: #999;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.menu-item {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: 0 20px;
  background: transparent;
  color: #fff;
  text-align: left;
  transition: background 0.2s ease;
}

.menu-item:hover {
  background: #3d3d3d;
}

.menu-separator {
  height: 1px;
  margin: 5px 0;
  background: #3d3d3d;
}

.login-screen {
  position: fixed;
  z-index: 20000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--desktop-a) 0%, var(--desktop-b) 100%);
}

.login-box {
  width: min(350px, calc(100vw - 32px));
  padding: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-box h1 {
  margin: 0 0 30px;
  color: #333;
  font-size: 28px;
  text-align: center;
}

.login-box input {
  display: block;
  width: 100%;
  height: 43px;
  margin-bottom: 15px;
  padding: 0 12px;
  font-size: 14px;
}

.login-box button {
  width: 100%;
  height: 44px;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
}

.login-box button:hover {
  background: var(--primary-hover);
}

.error-message {
  min-height: 18px;
  margin-top: 10px;
  color: var(--danger);
  font-size: 12px;
  text-align: center;
}

.mobile-link {
  margin: 14px 0 0;
  font-size: 13px;
  text-align: center;
}

.mobile-link a {
  color: var(--primary);
  text-decoration: none;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  margin-bottom: 15px;
  padding: 10px;
  border-radius: 4px;
  background: #fff;
}

.toolbar.compact {
  margin-bottom: 10px;
}

.toolbar-spacer {
  flex: 1;
}

.btn {
  min-height: 35px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: #333;
  font-size: 14px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
  background: #f5f5f5;
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-success {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: var(--success-hover);
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-text {
  min-height: 28px;
  padding: 0 4px;
  background: transparent;
  color: #222;
}

.btn-text:hover {
  background: #f0f0f0;
}

.quota {
  font-weight: 700;
}

.checkline,
.radio-line {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.checkline input,
.radio-line input {
  width: 15px;
  height: 15px;
}

.table-shell {
  height: calc(100% - 70px);
  min-height: 260px;
  overflow: auto;
  background: #fff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.data-table th,
.data-table td {
  height: 44px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  line-height: 1.2;
}

.data-table th {
  background: #f5f5f5;
  color: #333;
  font-size: 16px;
  font-weight: 700;
}

.data-table td {
  font-size: 14px;
}

.data-table tbody tr:hover {
  background: #f9f9f9;
}

.empty-row {
  color: #777;
  text-align: center !important;
}

.title-cell,
.source-cell,
.file-name-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-cell {
  max-width: 150px;
  font-weight: 700;
}

.source-cell {
  max-width: 200px;
}

.file-name-cell {
  max-width: 320px;
}

.pid {
  display: inline-flex;
  min-width: 46px;
  justify-content: center;
  border-radius: 3px;
  padding: 2px 6px;
  background: #f0f0f0;
  color: #111;
  font: 12px/1.3 Consolas, "Courier New", monospace;
}

.status-badge {
  display: inline-flex;
  min-width: 58px;
  justify-content: center;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
}

.status-running {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-stopped,
.status-failed {
  background: var(--bad-bg);
  color: var(--bad-text);
}

.status-created,
.status-starting,
.status-reconnecting,
.status-stopping {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
}

.create-layout {
  display: grid;
  grid-template-columns: 290px minmax(340px, 1fr) 390px;
  height: 100%;
  min-height: 560px;
  gap: 14px;
}

.side-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  padding-right: 12px;
  border-right: 4px solid #dddddd;
  flex-direction: column;
}

.side-title {
  margin-bottom: 10px;
  font-weight: 700;
}

.side-status {
  margin: 15px 0;
  color: #e11d48;
  text-align: center;
}

.listen-box {
  margin-top: auto;
  padding-top: 16px;
  border-top: 2px dashed #d7d7d7;
}

.listen-title {
  display: block;
  margin-bottom: 10px;
  color: #4c3b7a;
  font-weight: 700;
}

.listen-drop {
  display: grid;
  height: 120px;
  place-items: center;
  border: 2px dashed #999;
  border-radius: 7px;
  color: #999;
  text-align: center;
}

.create-form {
  min-width: 0;
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.mode-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.mode-group legend {
  float: left;
  margin-right: 6px;
  font-weight: 700;
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
}

.field span,
.field label {
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
}

.field textarea {
  min-height: 62px;
  padding: 8px 9px;
  resize: vertical;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr)) 110px;
  align-items: end;
  gap: 10px;
}

.inline-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.icon-gear {
  display: inline-grid;
  width: 24px;
  height: 24px;
  min-width: 24px;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: #555;
  font-size: 14px;
}

.icon-gear:hover,
.icon-gear:focus-visible {
  background: #eceff8;
  color: #222;
}

.audio-source-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 5px;
  font-weight: 700;
}

.audio-source-head .checkline {
  margin-left: auto;
  font-weight: 400;
}

.audio-source-head .checkline + .checkline {
  margin-left: 0;
}

.audio-folder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 6px;
  margin-bottom: 8px;
}

.audio-folder-row > span {
  grid-column: 1 / -1;
  color: #555;
  font-size: 13px;
}

.audio-drop {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  padding: 5px 8px;
  border: 1px dashed #b7b7b7;
  border-radius: 5px;
  background: #fff;
  flex-wrap: wrap;
}

.audio-tag {
  display: inline-flex;
  max-width: 100%;
  min-height: 26px;
  align-items: center;
  gap: 3px;
  padding: 0 8px;
  border: 1px solid #9fc4ff;
  border-radius: 999px;
  background: #eef6ff;
  color: #0b63ce;
}

.audio-tag:hover {
  background: #dbeeff;
}

.audio-placeholder {
  overflow: hidden;
  color: #999;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.small-range {
  width: 64px;
  min-height: 38px;
  padding: 0 8px;
}

.audio-hint {
  margin: -2px 0 8px;
  color: #666;
  font-size: 13px;
}

.volume-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  align-items: end;
  gap: 12px;
}

.loop-line {
  height: 34px;
}

.action-row,
.paste-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.paste-row input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
}

.status-line {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
}

.file-picker {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto 30px 1fr;
  gap: 6px;
  padding-left: 12px;
  border-left: 4px solid #dddddd;
}

.picker-toolbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.path-input,
.current-path {
  width: 100%;
  height: 30px;
  border: 2px solid #444;
  border-radius: 0;
  padding: 0 9px;
}

.picker-table {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
}

.file-toolbar .current-path {
  max-width: 360px;
  margin-left: 8px;
  border-width: 1px;
  border-color: #777;
}

.storage-line {
  min-height: 32px;
  padding: 0 0 8px;
  font-size: 16px;
}

.storage-line strong {
  font-size: 17px;
}

.upload-progress {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 260px);
  gap: 10px;
  min-height: 34px;
  margin: -5px 0 10px;
}

.upload-progress-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid #c5cbd3;
  border-radius: 999px;
  background: #fff;
}

.upload-progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.16s ease;
}

.upload-progress strong {
  color: #333;
  font-size: 13px;
  text-align: right;
}

.audio-empty {
  display: grid;
  min-height: 280px;
  place-items: center;
  color: #777;
  background: #fff;
  border-top: 1px solid var(--line);
}

.settings-grid {
  display: grid;
  width: min(860px, 100%);
  gap: 16px;
}

.settings-panel {
  background: #fff;
  border: 1px solid var(--line);
  padding: 18px;
}

.settings-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.settings-panel dl {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  margin: 0 0 16px;
}

.settings-panel dt {
  color: var(--muted);
}

.settings-panel dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.modal {
  width: min(880px, calc(100vw - 40px));
  max-height: min(720px, calc(100vh - 40px));
  padding: 0;
  border: 1px solid var(--line-strong);
  background: #fff;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.audio-settings-dialog {
  width: 420px;
  max-width: calc(100vw - 28px);
  padding: 0;
  border: 1px solid #b7b7b7;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}

.audio-settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.15);
}

.ducking-form {
  padding: 12px;
}

.ducking-form strong {
  display: block;
  margin-bottom: 8px;
}

.ducking-form table {
  width: 100%;
  margin-bottom: 8px;
  border-collapse: collapse;
  text-align: center;
}

.ducking-form th,
.ducking-form td {
  padding: 2px 4px;
  font-size: 13px;
}

.ducking-form th:first-child,
.ducking-form td:first-child {
  text-align: left;
}

.ducking-role-table {
  border-top: 1px solid var(--line);
  text-align: left !important;
}

.ducking-role-table th,
.ducking-role-table td {
  border-bottom: 1px solid #eeeeee;
  text-align: left;
}

.ducking-summary {
  margin: 8px 0 10px;
  color: #333;
  font-size: 13px;
  line-height: 1.5;
}

.ducking-fields {
  display: grid;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.ducking-fields label {
  display: grid;
  gap: 3px;
  color: #555;
  font-size: 12px;
}

.ducking-fields input {
  width: 100%;
  min-height: 28px;
  padding: 0 7px;
}

.ducking-fields small {
  display: block;
  margin: -1px 0 3px;
  color: #777;
  font-size: 12px;
}

.ducking-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.modal header button {
  background: transparent;
  color: #111;
}

#logsContent {
  height: 560px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  background: #10141a;
  color: #d1e7ff;
  font: 12px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

#previewVideo {
  display: block;
  width: 100%;
  max-height: 620px;
  background: #000;
}

@media (max-width: 1100px) {
  .create-layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .side-panel,
  .file-picker {
    border: 0;
    padding: 0;
  }

  .listen-box {
    margin-top: 10px;
  }
}

@media (max-width: 900px) {
  .desktop-icons {
    display: none;
  }

  .window {
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    min-width: 0;
    border-radius: 0;
  }

  .window-content {
    padding: 14px;
  }

  .toolbar,
  .form-head,
  .action-row,
  .paste-row {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .compact-grid,
  .stat-cards,
  .volume-grid {
    grid-template-columns: 1fr 1fr;
  }

  .system-tray span:nth-child(n + 4):not(#clock) {
    display: none;
  }
}

@media (max-width: 560px) {
  .login-box {
    padding: 28px 22px;
  }

  .compact-grid,
  .stat-cards,
  .volume-grid,
  .upload-progress {
    grid-template-columns: 1fr;
  }

  .taskbar-right {
    display: none;
  }
}
