:root {
  --bg: #0b1020;
  --panel: rgba(12, 20, 36, 0.88);
  --board: #f8fafc;
  --line: #d1d5db;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #818cf8;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 0% 0%, #1e293b 0%, var(--bg) 42%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.topbar p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.presence {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.badge {
  font-size: 0.75rem;
  border: 1px solid #475569;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  background: #1e293b;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  max-height: calc(100vh - 110px);
  overflow: auto;
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin: 0;
  font-size: 1rem;
}

.section {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 10px;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: rgba(15, 23, 42, 0.45);
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #cbd5e1;
}

input,
button {
  border-radius: 8px;
  border: 1px solid #4b5563;
  background: #0b1220;
  color: #e5e7eb;
  padding: 0.55rem 0.7rem;
}

.color-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.color-swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.65) inset;
  flex: 0 0 1rem;
}

.sr-only-color {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
}

input[type='range'] {
  padding: 0;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 0.5rem;
}

.layer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

button {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

button:hover {
  border-color: #64748b;
  background: #101a31;
}

button.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
  background: rgba(99, 102, 241, 0.16);
}

button.danger {
  border-color: var(--danger);
  color: #fecaca;
}

.upload input {
  background: transparent;
  padding: 0;
  border: 0;
}

.shortcuts h3 {
  margin: 0;
  font-size: 0.86rem;
  color: #cbd5e1;
}

.shortcuts p {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
}

kbd {
  font: inherit;
  font-size: 0.72rem;
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  background: rgba(15, 23, 42, 0.95);
  color: #e2e8f0;
}

.hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.board-wrap {
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.82);
  padding: 0.75rem;
}

.board {
  position: relative;
  width: 100%;
  height: calc(100vh - 150px);
  border-radius: 10px;
  overflow: hidden;
  background: var(--board);
  cursor: crosshair;
  touch-action: none;
}

.board-viewport {
  position: absolute;
  inset: 0;
  transform-origin: top left;
}

.image-layer,
.draw-layer {
  position: absolute;
  inset: 0;
}

.draw-layer {
  pointer-events: none;
  z-index: 3;
  overflow: visible;
}

.image-layer {
  pointer-events: none;
  z-index: 2;
}

.image-item {
  pointer-events: auto;
  position: absolute;
  top: 20px;
  left: 20px;
  width: 200px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.2);
  cursor: grab;
  user-select: none;
}

.image-item img {
  display: block;
  width: 100%;
  border-radius: 8px;
  pointer-events: none;
}

.image-item.is-selected {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  right: -8px;
  bottom: -8px;
  border: 1px solid #4338ca;
  border-radius: 3px;
  background: #c7d2fe;
  cursor: nwse-resize;
  padding: 0;
  display: none;
}

.image-item.is-selected .resize-handle {
  display: block;
}

.zoom-badge {
  position: absolute;
  right: 12px;
  bottom: 12px;
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid #475569;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.tool-cursor {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid rgba(15, 23, 42, 0.75);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-9999px, -9999px);
  z-index: 10;
  background: transparent;
}

.tool-cursor.is-visible {
  transform: translate(-50%, -50%);
}

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

  .panel {
    max-height: none;
  }

  .board {
    height: 70vh;
  }
}
