:root {
  --desk: #cdc3b1;
  --ink: #2b2621;
  --muted: #5f5649;
  --print: #f4eedf;   /* 프린트한 시 종이 */
  --sheet: #fffdf8;   /* 빈 종이 */
  --accent: #b4441d;
  --mark: rgba(255, 210, 80, 0.65);
  --scissors: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Ctext x='3' y='20' font-size='20'%3E%E2%9C%82%3C/text%3E%3C/svg%3E") 13 13, crosshair;
  --poem-size: 2.9cqw;  /* 종이 폭 기준 (왼쪽·오른쪽 공통) */
  --font-poem: 'Nanum Myeongjo', 'AppleMyungjo', 'Batang', serif;
  --font-ui: 'Gowun Dodum', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  background-color: var(--desk);
  background-image: radial-gradient(rgba(255, 255, 255, 0.10) 1px, transparent 1px);
  background-size: 5px 5px;
  color: var(--ink);
  font-family: var(--font-ui);
}

.top { max-width: 1240px; margin: 0 auto; padding: 28px 24px 4px; }
.top h1 { margin: 0; font-family: var(--font-poem); font-weight: 700; font-size: 28px; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.desk {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 24px 48px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
}
/* 글자 크기(cqw)의 기준: 종이와 폭이 같은 패널. 종이 자체를 기준으로 하면
   여백(padding)이 있는 왼쪽 종이만 글자가 작아진다 */
.panel { position: relative; min-width: 0; container-type: inline-size; }

@media (min-width: 761px) {
  /* 두 종이는 같은 폭(= 같은 글자 크기)으로, 오른쪽 종이가 창 높이 안에 다 들어오게 */
  .panel {
    width: min(100%, calc((100vh - 150px) / 1.414));
    min-width: 260px;
    justify-self: center;
  }
  /* 왼쪽 시가 길어 스크롤해도 오른쪽 종이는 그 자리에 */
  .panel-collage { position: sticky; top: 16px; }
}

@media (max-width: 760px) {
  .top { padding: 20px 16px 0; }
  .desk { grid-template-columns: 1fr; gap: 28px; padding: 12px 16px 40px; }
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; min-height: 36px; margin-bottom: 10px;
}
.label { font-size: 13px; letter-spacing: 0.08em; color: var(--muted); }
.actions { display: flex; gap: 8px; }

button {
  font: inherit; font-size: 14px; color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 999px; padding: 6px 14px; cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.9); }
button.armed { background: var(--accent); border-color: var(--accent); color: #fff; }

.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(0, 0, 0, 0.08); }
.seg button { border: 0; background: transparent; }
.seg button[aria-pressed="true"] { background: var(--sheet); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); }


/* ---------- paper ---------- */
.paper {
  position: relative;
  aspect-ratio: 1 / 1.414;
  font-family: var(--font-poem);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 12px 30px rgba(60, 40, 10, 0.18);
}

/* 왼쪽: 프린트된 시 */
.sheet-source {
  display: flex; flex-direction: column;
  padding: 11% 10%;
  background: var(--print);
}
.sheet-source textarea {
  flex: 1 0 auto;
  width: 100%; padding: 0; border: 0; outline: 0; resize: none; overflow: hidden;
  background: transparent; color: inherit;
  font: inherit; font-size: var(--poem-size); line-height: 2.1;
  /* 오리기 모드(.poem)와 똑같이 줄을 바꾼다: 어절을 쪼개지 않음 */
  white-space: pre-wrap; word-break: keep-all; overflow-wrap: break-word;
}
.poem {
  font-size: var(--poem-size); line-height: 2.1;
  white-space: pre-wrap; word-break: keep-all; overflow-wrap: break-word;
  user-select: none; -webkit-user-select: none;
}
.line { min-height: 2.1em; }

.poem { touch-action: none; }
/* 영역을 그을 때는 가위, 다 그은 영역 위에서는 손 */
.ch {
  cursor: var(--scissors);
  transition: opacity 0.12s;
}
.ch.selected { cursor: grab; }
.ch.lifting { opacity: 0.2; }
body.grabbing, body.grabbing * { cursor: grabbing !important; }
/* 영역을 긋는 동안에는 어디를 지나든 가위 */
body.cutting, body.cutting * { cursor: var(--scissors) !important; }

/* 오릴 영역: 가위로 따라 자를 점선 */
.sel-layer { position: absolute; inset: 0; pointer-events: none; }
.sel-box {
  position: absolute;
  border: 1.5px dashed rgba(43, 38, 33, 0.8);
  border-radius: 2px;
}
/* 오려 낸 자리: 책상이 비쳐 보이는 구멍 */
.hole {
  background: var(--desk);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.ch.cut { color: transparent; cursor: default; }

/* 오른쪽: 빈 종이 */
.sheet-collage { background: var(--sheet); }
.sheet-collage.drop-target { outline: 3px dashed rgba(180, 68, 29, 0.5); outline-offset: 6px; }
.empty {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-size: 3.2cqw; color: rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* ---------- 오린 조각 ---------- */
.scrap {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  font-family: var(--font-poem); font-size: var(--poem-size); line-height: 1.6; color: var(--ink);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.28)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
  cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.scrap-paper {
  padding: 0.25em 0.6em;
  background: var(--print);
  white-space: pre; text-align: center;
}
.scrap.dragging { cursor: grabbing; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.3)); }
.scrap.ghost { position: fixed; z-index: 1000; pointer-events: none; }
.scrap.ghost.no-drop { opacity: 0.85; }
.scrap.removing { opacity: 0.35; }
.empty[hidden], [hidden] { display: none !important; }

/* ---------- 도움말 ---------- */
.paper { isolation: isolate; } /* 조각의 z-index를 종이 안에 가둔다 */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.help-link {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; padding: 4px 6px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font-size: 14px;
}
.help-link:hover { background: rgba(255, 255, 255, 0.35); color: var(--ink); }
.help-icon {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border: 1.5px solid currentColor; border-radius: 50%;
  font-size: 11px; font-weight: 700; line-height: 1;
}

dialog.help {
  width: min(460px, calc(100vw - 32px));
  padding: 24px 28px 20px;
  border: 0; border-radius: 12px;
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 20px 50px rgba(40, 30, 20, 0.3);
  font-size: 14px; line-height: 1.7;
}
dialog.help::backdrop { background: rgba(40, 30, 20, 0.35); }
dialog.help h2 { margin: 0 0 12px; font-family: var(--font-poem); font-size: 19px; }
dialog.help ol { margin: 0; padding-left: 1.2em; }
dialog.help li + li { margin-top: 6px; }
dialog.help form { margin-top: 18px; text-align: right; }
