* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  cursor: default;
  z-index: 0;
}

#paper-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

.paper-el {
  position: absolute;
  pointer-events: all;
  cursor: grab;
  user-select: none;
  transform-origin: center center;
  transition: box-shadow 0.25s ease;
}

.paper-el.dragging {
  cursor: grabbing;
}

.paper-el.editing {
  cursor: text;
}

.paper-inner {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 2px;
  overflow: hidden;
}

.paper-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #fefdfb 0%, #faf8f4 50%, #f5f2ec 100%);
  border: 0.5px solid rgba(0,0,0,0.06);
  border-radius: 2px;
}

.paper-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.paper-margin {
  position: absolute;
  top: 8%;
  bottom: 6%;
  width: 1px;
  background: rgba(210, 80, 80, 0.18);
  pointer-events: none;
}

.paper-text {
  position: absolute;
  top: 18%;
  left: 15%;
  right: 8%;
  bottom: 14%;
  font-family: 'Caveat', cursive;
  font-size: clamp(14px, 2.5vw, 22px);
  color: rgba(40, 30, 20, 0.72);
  line-height: 1.65;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-y: auto;
  scrollbar-width: none;
}

.paper-text::-webkit-scrollbar {
  display: none;
}

.paper-text.edit-mode {
  background: rgba(255, 250, 220, 0.25);
  border: 1px dashed rgba(180, 140, 60, 0.35);
  border-radius: 3px;
  padding: 4px;
  cursor: text;
}

.paper-image-container {
  position: absolute;
  bottom: 14%;
  left: 10%;
  right: 10%;
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: 45%;
  pointer-events: none;
}

.paper-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 2px solid rgba(0,0,0,0.06);
  box-shadow: 1px 2px 6px rgba(0,0,0,0.1);
  border-radius: 2px;
  transition: opacity 0.4s ease;
}

.paper-image-container img.fade-out {
  opacity: 0;
}

.paper-berry {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: clamp(12px, 1.8vw, 18px);
  opacity: 0.28;
  pointer-events: none;
  user-select: none;
}

.paper-dog-ear {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.paper-dog-ear.top-right {
  top: 0;
  right: 0;
}

.paper-dog-ear.bottom-right {
  bottom: 0;
  right: 0;
}

.paper-dog-ear.bottom-left {
  bottom: 0;
  left: 0;
}

.paper-dog-ear.top-left {
  top: 0;
  left: 0;
}

#ui-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

#header {
  position: absolute;
  top: 14px;
  left: 18px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(62, 39, 20, 0.45);
  letter-spacing: 0.5px;
  pointer-events: none;
  user-select: none;
}

#add-btn {
  position: absolute;
  bottom: 52px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(62, 39, 20, 0.12);
  color: rgba(62, 39, 20, 0.6);
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  pointer-events: all;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 25;
}

#add-btn:hover {
  background: rgba(62, 39, 20, 0.22);
  color: rgba(62, 39, 20, 0.85);
  transform: scale(1.08);
}

#add-btn:active {
  transform: scale(0.95);
}

#footer {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  text-align: center;
  pointer-events: all;
}

#footer a {
  font-size: 11px;
  color: rgba(62, 39, 20, 0.3);
  text-decoration: none;
  letter-spacing: 0.3px;
  transition: color 0.2s;
}

#footer a:hover {
  color: rgba(62, 39, 20, 0.6);
}

#hint {
  position: absolute;
  bottom: 58px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: rgba(62, 39, 20, 0.25);
  pointer-events: none;
  user-select: none;
  transition: opacity 0.8s ease;
}

/* Context menu */
#context-menu {
  position: fixed;
  z-index: 100;
  background: linear-gradient(135deg, #faf5ed, #f3ece0);
  border: 1px solid rgba(160, 120, 70, 0.25);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(40, 20, 5, 0.18), 0 1px 4px rgba(40, 20, 5, 0.1);
  padding: 6px 0;
  min-width: 180px;
  font-family: 'Caveat', cursive;
  font-size: 18px;
  overflow: hidden;
  animation: ctxFadeIn 0.12s ease-out;
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

#context-menu.hidden {
  display: none;
}

.ctx-item {
  padding: 8px 18px;
  cursor: pointer;
  color: rgba(50, 30, 15, 0.8);
  transition: background 0.12s ease;
  white-space: nowrap;
}

.ctx-item:hover {
  background: rgba(180, 140, 70, 0.15);
  color: rgba(50, 30, 15, 1);
}

.ctx-item.hidden {
  display: none;
}

.ctx-separator {
  height: 1px;
  background: rgba(160, 120, 70, 0.18);
  margin: 4px 12px;
}

/* Crumple animation (canvas handles this) */
@keyframes paperCrumple {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  100% { transform: scale(0.2) rotate(360deg); opacity: 0; }
}

.paper-el.crumpling {
  animation: paperCrumple 0.5s ease-in forwards;
  pointer-events: none;
}