:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --card: rgba(255, 255, 255, 0.9);
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --accent: #0f172a;
  --accent-soft: rgba(15, 23, 42, 0.08);
  --danger: #d11a2a;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #f8fafc, #eef2f7 48%, #e9eef6);
  color: var(--text);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.app-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.app-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.view {
  flex: 1;
  padding: 16px 20px 80px;
}

.hidden {
  display: none;
}

.notes-list {
  display: grid;
  gap: 12px;
}

.note-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: fadeIn 0.2s ease;
}

.note-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

.note-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.note-preview {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.note-date {
  margin-top: 8px;
  color: #aaa;
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.title-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: 22px;
  font-weight: 600;
  padding: 8px 0;
  outline: none;
  margin-bottom: 12px;
}

.editor-area {
  position: relative;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
  min-height: 360px;
  box-shadow: var(--shadow);
}

.text-input {
  width: 100%;
  min-height: 260px;
  border: none;
  outline: none;
  resize: vertical;
  font-size: 16px;
  line-height: 1.6;
  background: transparent;
}

.items-layer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.item {
  position: absolute;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: none;
  background: transparent;
  pointer-events: auto;
  z-index: 1;
}

.item.drawing {
  z-index: 3;
}

.item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item .delete {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 999px;
  padding: 4px 6px;
  cursor: pointer;
}

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 10px 12px;
  gap: 8px;
  flex-wrap: wrap;
  backdrop-filter: blur(16px);
}

.tool-button {
  border: none;
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 16px;
  cursor: pointer;
  min-width: 52px;
  transition: transform 0.15s ease, background 0.2s ease;
}

.tool-button:active {
  transform: scale(0.96);
}

.tool-button.active {
  background: #ffecec;
}

.icon-button {
  border: none;
  background: #111827;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.icon-button.ghost {
  background: var(--accent-soft);
  color: var(--text);
}

.icon-button:active {
  transform: scale(0.95);
}

.text-button {
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.text-button.danger {
  color: var(--danger);
}

.primary-button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  width: min(92vw, 520px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-content.compact {
  width: min(92vw, 420px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-weight: 600;
  text-align: center;
}

.modal-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.modal-footer.right {
  justify-content: flex-end;
}

canvas {
  width: 100%;
  height: auto;
  background: transparent;
  border-radius: 12px;
  border: 1px solid var(--border);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media print {
  body {
    background: #fff;
  }
  .app-header,
  .toolbar,
  .editor-header,
  .icon-button,
  .text-button,
  .modal {
    display: none !important;
  }
  .view {
    padding: 0;
  }
  .editor-area {
    border: none;
  }
  .item {
    box-shadow: none;
  }
}
