* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --board-bg: #fafaf7;
  --grid: #e5e7eb;
}

html, body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: grid;
  grid-template-rows: 56px 1fr 28px;
  grid-template-columns: 64px 1fr;
  grid-template-areas:
    "topbar topbar"
    "toolbar board"
    "status status";
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  font-size: 22px;
  color: var(--primary);
  background: linear-gradient(135deg, #6366f1, #ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.3px; }

.actions { display: flex; gap: 8px; }

.btn {
  background: var(--surface-light);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--border); transform: translateY(-1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); }

.toolbar {
  grid-area: toolbar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  gap: 6px;
  overflow-y: auto;
}
.toolbar hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.tool {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.tool:hover { background: var(--surface-light); }
.tool.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(99,102,241,0.4);
}

.color-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.active { border-color: var(--text); transform: scale(1.15); }

.size-label { font-size: 10px; color: var(--text-dim); text-align: center; }
.size-label input { width: 100%; margin-top: 4px; }

.board-wrapper {
  grid-area: board;
  position: relative;
  overflow: hidden;
  background: var(--board-bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

#board {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
}

#notes-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

.note {
  position: absolute;
  min-width: 180px;
  min-height: 120px;
  padding: 14px;
  background: #fef3c7;
  border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18), 0 2px 4px rgba(0,0,0,0.1);
  pointer-events: auto;
  cursor: move;
  font-family: "Comic Sans MS", "Marker Felt", cursive;
  font-size: 14px;
  color: #1f2937;
  resize: both;
  overflow: auto;
  transform: rotate(-1deg);
  transition: transform 0.2s, box-shadow 0.2s;
}
.note:hover { box-shadow: 0 10px 24px rgba(0,0,0,0.22); transform: rotate(0deg) scale(1.02); }
.note[contenteditable="true"]:focus { outline: 2px solid var(--primary); }
.note .delete-btn {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.1);
  border: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}
.note:hover .delete-btn { opacity: 1; }

.note.color-pink { background: #fce7f3; }
.note.color-blue { background: #dbeafe; }
.note.color-green { background: #d1fae5; }
.note.color-purple { background: #ede9fe; }

.zoom-indicator {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  border: 1px solid var(--border);
}

.status {
  grid-area: status;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: 12px;
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-content header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-content h2 { font-size: 18px; }
.modal-close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}
.modal-body { padding: 20px 24px 24px; }
.modal-body label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--text-dim); }
.modal-body textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.modal-body textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.modal-actions { margin-top: 14px; display: flex; justify-content: flex-end; }

.result {
  margin-top: 18px;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 4px solid var(--primary);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.result.hidden { display: none; }
.result.loading { color: var(--text-dim); font-style: italic; }
.result h3 { font-size: 14px; margin: 12px 0 6px; color: var(--primary); }
.result h3:first-child { margin-top: 0; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
