:root {
  --bg: #dfe8f3;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(15, 35, 60, 0.08);
  --title-bar: #2b6ecb;
  --blue-btn: linear-gradient(180deg, #4a90e2 0%, #2b6ecb 100%);
  --grey-btn: linear-gradient(180deg, #e2e8f0 0%, #cbd5e1 100%);
  --orange-btn: linear-gradient(180deg, #fb923c 0%, #ea580c 100%);
  --green-send: linear-gradient(180deg, #34d399 0%, #059669 100%);
  --pad-blue: linear-gradient(180deg, #93c5fd 0%, #60a5fa 100%);
  --radius: 14px;
  --paper-bg: #e8eef5;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: #1e293b;
  min-height: 100vh;
}

body {
  padding: 12px;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}

h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

h2::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: var(--title-bar);
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.icon-btn {
  border: none;
  background: #f1f5f9;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover {
  background: #e2e8f0;
}

.log-area {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  background: #f8fafc;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

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

.device-wrap {
  align-items: stretch;
}

.device-card .btn-row {
  min-width: 0;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 0;
}

.btn-row + .btn-row {
  margin-top: 14px;
}

.btn-row.btn-row-tight .btn {
  padding: 14px 16px;
  min-height: 48px;
}

.btn-row.single {
  grid-template-columns: 1fr;
  margin-top: 14px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

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

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

.btn-grey {
  background: var(--grey-btn);
  color: #334155;
  text-shadow: none;
}

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

.btn-green {
  background: var(--green-send);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dpad {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 10px;
  max-width: 280px;
  margin: 0 auto;
}

.dpad .cell {
  min-height: 52px;
  border-radius: 12px;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #fff;
  background: var(--pad-blue);
}

.dpad .cell:active,
.dpad .cell.active {
  filter: brightness(0.92);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.15);
}

.dpad .u {
  grid-column: 2;
}

.dpad .l {
  grid-column: 1;
  grid-row: 2;
}

.dpad .r {
  grid-column: 3;
  grid-row: 2;
}

.dpad .d {
  grid-column: 2;
  grid-row: 3;
}

.cmd-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.cmd-row input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  padding: 12px 14px;
  font-size: 15px;
  background: #f8fafc;
}

.bt-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.bt-bar .status {
  font-size: 14px;
  color: #64748b;
}

.gcode-form label {
  display: block;
  font-size: 13px;
  margin: 8px 0 4px;
  color: #475569;
}

.gcode-form input,
.gcode-form select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.form-grid-compact {
  gap: 14px;
}

.preview-dual-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 12px;
}

.preview-stage-wrap {
  margin-top: 4px;
}

.field-inline {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-stage {
  margin: 0 auto;
  max-width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.preview-stage.stage-portrait {
  width: 280px;
  aspect-ratio: 210 / 297;
}

.preview-stage.stage-landscape {
  width: min(420px, 100%);
  aspect-ratio: 297 / 210;
}

.preview-stage.stage-custom {
  width: min(400px, 100%);
}

.preview-paper,
.gcode-path-paper {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--paper-bg);
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  overflow: hidden;
  flex: 1 1 auto;
}

.gcode-path-paper {
  touch-action: none;
}

.preview-paper {
  touch-action: none;
}

.preview-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
}

.preview-layer.dragging {
  cursor: grabbing;
}

.preview-layer img {
  display: block;
  max-width: none;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.path-preview-panel {
  margin-top: 4px;
}

.path-preview-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 8px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #475569;
}

.checkbox-inline input {
  width: auto;
  margin: 0;
}

.gcode-path-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scale-chip {
  position: absolute;
  font-size: 12px;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.65);
  border-radius: 999px;
  padding: 4px 10px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.scale-chip-x {
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
}

.scale-chip-y {
  left: 12px;
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: left top;
}

.preview-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: #64748b;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 9999;
}

.toast.show {
  opacity: 1;
}

.hidden-share-desktop .share-wechat {
  display: none;
}

input[readonly] {
  background: #f1f5f9;
  color: #475569;
}
