:root {
  --bg: #0b1120;
  --panel: #111c33;
  --panel-2: #16233d;
  --line: #22304d;
  --text: #e2e8f0;
  --muted: #7c8ba5;
  --accent: #38bdf8;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "top top"
    "side main";
}

#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; letter-spacing: .5px; }

.status { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.muted { color: var(--muted); }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
}
.pill.online { color: var(--ok); border-color: rgba(74,222,128,.35); background: rgba(74,222,128,.1); }
.pill.offline { color: var(--err); border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.1); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ghost-btn:disabled { opacity: .5; cursor: not-allowed; }

.mini-select {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.mini-select:hover { border-color: var(--accent); color: var(--accent); }

#sidebar {
  grid-area: side;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.side-title button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.side-title button:hover { color: var(--accent); }

#deviceList {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

#deviceList li {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--panel-2);
  transition: border-color .15s, background .15s;
}
#deviceList li:hover { border-color: var(--line); }
#deviceList li.active { border-color: var(--accent); background: rgba(56,189,248,.08); }

.dev-name { font-size: 14px; margin-bottom: 3px; }
.dev-meta { font-size: 11px; color: var(--muted); }

.empty-tip {
  padding: 20px 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(56,189,248,.05), transparent 60%),
    var(--bg);
}

/* 画面 + 状态条 + 工具栏，整体宽度跟随画面 */
#phoneFrame {
  display: none;
  flex-direction: column;
  max-width: 100%;
  max-height: 100%;
}
#phoneFrame.ready { display: flex; }

#screen {
  display: block;
  max-width: 100%;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-drag: none;
  background: #020617;
}

#statsBar {
  height: 26px;
  line-height: 26px;
  padding: 0 10px;
  font-size: 11px;
  font-family: Consolas, "Courier New", monospace;
  color: var(--muted);
  background: var(--panel-2);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#statsBar b { color: var(--accent); font-weight: 600; }

#placeholder {
  position: absolute;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}
#placeholder.hidden { display: none; }

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 10px 10px;
}

#toolbar button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
#toolbar button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#toolbar button:disabled { opacity: .4; cursor: not-allowed; }

#toolbar select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
#toolbar select:hover { border-color: var(--accent); }

#textInput {
  flex: 1 1 120px;
  min-width: 100px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  outline: none;
}
#textInput:focus { border-color: var(--accent); }

/* 消息编辑区 + 展开面板 */
.composer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 200px;
  min-width: 150px;
}

.composer #textInput {
  flex: 1 1 auto;
  min-width: 80px;
  width: auto;
}

.plus-btn {
  width: 32px;
  height: 32px;
  padding: 0 !important;
  font-size: 18px !important;
  line-height: 1;
  flex: 0 0 auto;
}

.fx-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0,0,0,.55);
  width: max-content;
  max-width: 92vw;
}
.fx-panel.open { display: flex; }

.fx-group { display: flex; align-items: center; gap: 10px; }
.fx-label { font-size: 12px; color: var(--muted); min-width: 28px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(56,189,248,.12);
}

/* 特效本地预览层 */
#fxPreview {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 10;
}

.fx-preview {
  position: absolute;
  font-size: 64px;
  line-height: 1;
  will-change: transform, opacity;
}

.fx-preview.car { left: 102%; top: 58%; animation: fxCar 3s linear forwards; }
.fx-preview.rocket { left: 46%; top: 105%; animation: fxRocket 2.6s ease-out forwards; }
.fx-preview.carnival { left: 42%; top: 38%; animation: fxCarnival 3s ease-out forwards; }
.fx-preview.firework { left: 44%; top: 42%; animation: fxFirework 2s ease-out forwards; }
.fx-preview.gift { left: 44%; top: 38%; animation: fxGift 2s ease-out forwards; }

@keyframes fxCar {
  from { transform: translateX(0) }
  to { transform: translateX(-160vw) }
}

@keyframes fxRocket {
  from { transform: translateY(0) scale(1) }
  to { transform: translateY(-130vh) scale(0.7) }
}

@keyframes fxCarnival {
  0% { transform: scale(.3) rotate(-25deg); opacity: 0 }
  35% { transform: scale(1.25) rotate(12deg); opacity: 1 }
  100% { transform: scale(1) rotate(0); opacity: 0 }
}

@keyframes fxFirework {
  0% { transform: scale(.2); opacity: 0 }
  35% { transform: scale(1.5); opacity: 1 }
  100% { transform: scale(2.4); opacity: 0 }
}

@keyframes fxGift {
  0% { transform: scale(.3); opacity: 0 }
  45% { transform: scale(1.18); opacity: 1 }
  100% { transform: scale(1); opacity: 0 }
}
