:root {
  --bg: #f6f4ef;
  --ink: #121212;
  --ink-soft: #424242;
  --card: rgba(255, 255, 255, 0.84);
  --line: #d8d3c6;
  --accent: #00774a;
  --accent-strong: #005d3a;
  --danger: #9f1f1f;
  --danger-strong: #7f1616;
  --bg-gradient: linear-gradient(145deg, #f0ede2 0%, #f7f3e7 60%, #ece8dd 100%);
  --shape-a: #ffc966;
  --shape-b: #63c4a3;
  --topbar-bg: rgba(245, 241, 233, 0.88);
  --input-bg: #fffef9;
  --secondary-bg: #ffffff;
  --secondary-hover: #f5f0e6;
  --icon-bg: #ffffff;
  --connect-note: #466054;
  --connect-item-bg: rgba(255, 255, 255, 0.82);
  --connect-item-line: #cfe0d7;
  --connect-item-label: #4c6258;
  --log-bg: #171717;
  --log-ink: #d7f7e9;
  --log-line: #2a2a2a;
  --dialog-bg: #fffef9;
  --dialog-ink: #121212;
  --dialog-backdrop: rgba(0, 0, 0, 0.4);
  --mono: "IBM Plex Mono", monospace;
  --title: "Chivo", sans-serif;
}

html[data-theme="dark"] {
  --bg: #111612;
  --ink: #edf4ee;
  --ink-soft: #afbeb1;
  --card: rgba(24, 31, 27, 0.9);
  --line: #2f4238;
  --accent: #1ea86c;
  --accent-strong: #15915b;
  --danger: #bf3f3f;
  --danger-strong: #a43030;
  --bg-gradient: linear-gradient(150deg, #0f1612 0%, #111b15 54%, #0d1411 100%);
  --shape-a: #8a5f1f;
  --shape-b: #1d6f59;
  --topbar-bg: rgba(15, 22, 18, 0.84);
  --input-bg: #141d18;
  --secondary-bg: #1a251f;
  --secondary-hover: #223228;
  --icon-bg: #19241f;
  --connect-note: #95b3a4;
  --connect-item-bg: rgba(20, 30, 25, 0.9);
  --connect-item-line: #355145;
  --connect-item-label: #b2c9be;
  --log-bg: #090d0a;
  --log-ink: #bdeccf;
  --log-line: #1b2820;
  --dialog-bg: #18221d;
  --dialog-ink: #edf4ee;
  --dialog-backdrop: rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--title);
  color: var(--ink);
  background: var(--bg-gradient);
  position: relative;
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  filter: blur(44px);
  pointer-events: none;
  opacity: 0.45;
}

.bg-shape-a {
  width: 360px;
  height: 360px;
  background: var(--shape-a);
  top: -120px;
  right: -80px;
}

.bg-shape-b {
  width: 260px;
  height: 260px;
  background: var(--shape-b);
  left: -80px;
  bottom: 60px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  backdrop-filter: blur(10px);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.8rem);
  letter-spacing: 0.02em;
  font-weight: 900;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.layout {
  max-width: 1200px;
  margin: 18px auto 60px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  position: relative;
  z-index: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.07);
  animation: in 0.35s ease both;
}

@keyframes in {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.card h2 {
  margin: 0 0 10px;
  font-size: 1.08rem;
}

.card h3 {
  margin: 8px 0;
  font-size: 0.95rem;
}

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

.section-head h3 {
  margin: 0;
}

.section-head .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.card-connect { grid-column: span 5; }
.card-device { grid-column: span 7; }
.card-manifest { grid-column: span 12; }
.card-manual-target { grid-column: span 6; }
.card-root { grid-column: span 6; }
.card-actions { grid-column: span 12; }
.card-log { grid-column: span 12; }

.card-connect {
  position: relative;
}

.connect-head {
  position: relative;
  z-index: 1;
  margin-bottom: 10px;
}

.connect-head h2 {
  margin-bottom: 4px;
}

.connect-head small {
  display: block;
  color: var(--connect-note);
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}

.connect-actions {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.connect-actions .btn {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
}

.connect-status-grid {
  position: relative;
  z-index: 1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.connect-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--connect-item-line);
  border-radius: 12px;
  background: var(--connect-item-bg);
}

.connect-status-item span {
  color: var(--connect-item-label);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.connect-status-item strong {
  font-size: 0.92rem;
  margin-left: 8px;
  text-align: right;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-manual-target,
.card-root {
  display: flex;
  flex-direction: column;
}

.card-manual-target .manual-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.manual-root-row,
.root-action-row {
  margin-top: auto;
  padding-top: 10px;
}

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

.row.end {
  justify-content: flex-end;
}

.status-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 8px;
  font-size: 0.92rem;
}

.status-grid span {
  color: var(--ink-soft);
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 8px;
}

label span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

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

input,
select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
}

.btn,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn {
  padding: 8px 11px;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}

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

.btn:active,
.icon-btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  background: var(--secondary-bg);
  color: var(--ink);
  border-color: var(--line);
}

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

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}

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

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

.icon-btn {
  width: 40px;
  height: 40px;
  font-size: 1.15rem;
  background: var(--icon-bg);
  color: var(--ink);
}

.action-block + .action-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

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

.card-actions > h2 {
  grid-column: 1 / -1;
}

.card-actions .action-block + .action-block {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.manual-wrap {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.checkbox-line input {
  width: auto;
}

.log-view {
  margin: 10px 0 0;
  min-height: 220px;
  max-height: 520px;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-ink);
  border-radius: 12px;
  padding: 10px;
  font-family: var(--mono);
  line-height: 1.35;
  border: 1px solid var(--log-line);
}

#settingsDialog {
  border: none;
  border-radius: 14px;
  width: min(560px, 90vw);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.25);
  background: var(--dialog-bg);
  color: var(--dialog-ink);
}

#autoConnectDialog,
#fastbootConnectDialog {
  border: none;
  border-radius: 14px;
  width: min(560px, 90vw);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.25);
  background: var(--dialog-bg);
  color: var(--dialog-ink);
}

#settingsDialog::backdrop {
  background: var(--dialog-backdrop);
}

#autoConnectDialog::backdrop,
#fastbootConnectDialog::backdrop {
  background: var(--dialog-backdrop);
}

.settings-form {
  padding: 12px;
}

@media (max-width: 980px) {
  .card-connect,
  .card-device,
  .card-manual-target,
  .card-actions,
  .card-root,
  .card-manifest,
  .card-log {
    grid-column: span 12;
  }

  .status-grid,
  .input-grid {
    grid-template-columns: 1fr;
  }

  .card-actions {
    grid-template-columns: 1fr;
  }

  .connect-actions,
  .connect-status-grid {
    grid-template-columns: 1fr;
  }

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

  .section-head .btn {
    width: 100%;
  }
}
