:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #ca8a04;
  --border: #475569;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
}
.dot.connected { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot.connecting { background: var(--warning); animation: pulse 1s infinite; }
.dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

header button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

main {
  padding: 1rem;
  padding-bottom: 6rem;
  max-width: 640px;
  margin: 0 auto;
}

h2 { margin: 0 0 1rem; font-size: 1.25rem; }
h3 { margin: 0 0 0.75rem; font-size: 1rem; color: var(--muted); font-weight: 500; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.badge {
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.badge.live { background: var(--danger); color: white; }
.badge.recording { background: var(--warning); color: white; }
.badge.idle { background: var(--panel-2); color: var(--muted); }

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
button:hover:not(:disabled) { background: var(--border); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.big { width: 100%; padding: 1rem; font-size: 1.125rem; font-weight: 600; }
button.primary { background: var(--primary); border-color: var(--primary); color: white; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button.danger { background: var(--danger); border-color: var(--danger); color: white; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}
input[type="text"], input[type="password"], select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.filepick {
  display: block;
  position: relative;
  margin-bottom: 1rem;
}
.filepick input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.filepick span {
  display: block;
  text-align: center;
  padding: 1.5rem;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
}

.hint { font-size: 0.875rem; color: var(--muted); margin: 0.75rem 0 0; }
.hint.error { color: var(--danger); }
.hint.success { color: var(--success); }

.list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.list li.active { border-color: var(--primary); background: rgba(37, 99, 235, 0.1); }
.list li.locked { opacity: 0.65; }
.list li button { padding: 0.375rem 0.75rem; font-size: 0.875rem; min-width: auto; }
.list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .drag-handle {
  cursor: grab;
  padding: 0.25rem 0.5rem;
  color: var(--muted);
  font-size: 1.25rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.list li .drag-handle:active { cursor: grabbing; color: var(--text); }
/* Sortable.js のゴースト要素 */
.sortable-ghost { opacity: 0.35; background: var(--panel-2); }
.sortable-chosen { border-color: var(--primary); }
.list li.with-edit { flex-wrap: wrap; }
.list li.with-edit .edit-panel {
  flex-basis: 100%;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.edit-panel h4 { margin: 0; font-size: 0.8125rem; color: var(--muted); font-weight: 500; }
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.375rem;
}
.pos-grid button { padding: 0.625rem; font-size: 1.125rem; line-height: 1; }
.edit-row { display: flex; gap: 0.5rem; align-items: center; }
.edit-row .grow { flex: 1; }
.edit-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.edit-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}
.edit-row input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
}
.size-val { font-size: 0.875rem; color: var(--muted); min-width: 3.5rem; text-align: right; }

.preview-wrap {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 0.5rem;
  aspect-ratio: 16 / 9;
  position: relative;
}
#preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.preview-source-rect {
  fill: rgba(37, 99, 235, 0.15);
  stroke: #2563eb;
  stroke-width: 3;
  cursor: move;
}
.preview-source-rect.hidden { fill: rgba(148, 163, 184, 0.08); stroke: #94a3b8; stroke-dasharray: 8 6; }
.preview-source-rect:hover { fill: rgba(37, 99, 235, 0.28); }
.preview-handle {
  fill: #2563eb;
  stroke: white;
  stroke-width: 3;
  cursor: nwse-resize;
}
.preview-label-bg { fill: rgba(0, 0, 0, 0.65); pointer-events: none; }
.preview-label    { fill: white; font-family: inherit; pointer-events: none; }
.preview-bg       { fill: #0b0b0b; stroke: #475569; stroke-width: 1; }
.preview-screenshot {
  pointer-events: none;
  image-rendering: auto;
}

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.75rem 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 3px solid transparent;
}
.tabbar button.active {
  color: var(--text);
  border-top-color: var(--primary);
}
