/* 원고지 — 모든 클래스는 ms- 로 시작한다 */

.ms {
  --ms-paper: #fbf5e6;
  --ms-line: #c98773;
  --ms-frame: #b0604c;
  --ms-ink: #2a2521;
  --ms-red: #b4281e;
  --ms-key-bg: rgba(180, 40, 30, 0.07);
  --ms-caret-bg: rgba(42, 37, 33, 0.09);
  --ms-select-bg: rgba(70, 110, 170, 0.24);
  --ms-ring: rgba(176, 96, 76, 0.28);
  --ms-shadow: 0 1px 2px rgba(60, 40, 20, 0.08), 0 6px 18px rgba(60, 40, 20, 0.07);

  /* 컨테이너 단위를 못 쓰는 브라우저용 기본값 */
  --ms-pad: 10px;
  --ms-gutter: 5px;
  --ms-glyph: clamp(15px, 4.6vw, 26px);

  container-type: inline-size;
  box-sizing: border-box;
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  color: var(--ms-ink);
  font-family: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  text-align: left;
}

@supports (width: 1cqw) {
  .ms {
    --ms-pad: 3cqw;
    --ms-gutter: 1.5cqw;
    --ms-glyph: 5.5cqw;
  }
}

.ms-sm {
  max-width: 220px;
  --ms-shadow: 0 1px 2px rgba(60, 40, 20, 0.08);
}

@media (prefers-color-scheme: dark) {
  .ms {
    --ms-paper: #25211c;
    --ms-line: #74483c;
    --ms-frame: #8f584a;
    --ms-ink: #ebe3d3;
    --ms-red: #f08c7c;
    --ms-key-bg: rgba(240, 140, 124, 0.1);
    --ms-caret-bg: rgba(235, 227, 211, 0.12);
    --ms-select-bg: rgba(120, 160, 220, 0.3);
    --ms-ring: rgba(200, 130, 110, 0.3);
    --ms-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
}

.ms *,
.ms *::before,
.ms *::after {
  box-sizing: border-box;
}

.ms-sheet {
  position: relative;
  padding: var(--ms-pad);
  background: var(--ms-paper);
  border: 1px solid var(--ms-frame);
  border-radius: 2px;
  box-shadow: var(--ms-shadow);
}

.ms-editor .ms-sheet {
  transition: box-shadow 0.15s;
}

.ms-editor:focus-within .ms-sheet {
  box-shadow: 0 0 0 3px var(--ms-ring), var(--ms-shadow);
}

/* 줄 사이의 좁은 띠는 줄 간격으로 만든다 */
.ms-row {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  border: 1px solid var(--ms-line);
}

.ms-row + .ms-row {
  margin-top: var(--ms-gutter);
}

.ms-cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-left: 1px solid var(--ms-line);
  font-size: var(--ms-glyph);
  line-height: 1;
  white-space: pre;
}

.ms-cell:first-child {
  border-left: 0;
}

.ms-key {
  color: var(--ms-red);
  background: var(--ms-key-bg);
}

.ms-bad {
  color: var(--ms-red);
  box-shadow: inset 0 0 0 1px var(--ms-red);
}

.ms-selected {
  background: var(--ms-select-bg);
}

.ms-caret,
.ms-caret-end {
  background: var(--ms-caret-bg);
}

.ms-caret::before,
.ms-caret-end::after {
  content: "";
  position: absolute;
  top: 14%;
  bottom: 14%;
  width: 2px;
  background: var(--ms-ink);
  animation: ms-blink 1.1s steps(1) infinite;
}

.ms-caret::before {
  left: 10%;
}

.ms-caret-end::after {
  right: 4%;
  background: var(--ms-red);
}

.ms-composing {
  background: var(--ms-caret-bg);
  box-shadow: inset 0 -2px 0 var(--ms-ink);
}

@keyframes ms-blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ms-caret::before,
  .ms-caret-end::after {
    animation: none;
  }
}

/* 입력을 받는 투명 textarea — 글자·캐럿·선택 표시는 모두 격자가 대신 그린다 */
.ms-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: var(--ms-pad);
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  font: 16px/1.5 sans-serif;
  cursor: text;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.ms-input::selection {
  background: transparent;
  color: transparent;
}

.ms-overflow {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  margin-top: 0.6em;
  color: var(--ms-red);
  font-size: clamp(14px, var(--ms-glyph), 20px);
  line-height: 1.5;
}

.ms-overflow[hidden] {
  display: none;
}

.ms-overflow-label {
  flex: none;
  padding: 0.05em 0.5em;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-size: 0.75em;
}

.ms-overflow-text {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
}

.ms-editor:focus-within .ms-ocaret {
  box-shadow: -2px 0 0 var(--ms-red);
}

/* ── 아래는 manuscript-demo.html 전용 ── */
.ms-demo {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  font-family: system-ui, sans-serif;
  line-height: 1.6;
}

.ms-demo-pair {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.ms-demo-pair > * {
  flex: 1 1 280px;
  min-width: 0;
}

.ms-demo-thumbs > * {
  flex: 0 1 160px;
}

.ms-demo-state {
  max-width: 480px;
  margin: 12px auto;
  padding: 12px;
  overflow: auto;
  border: 1px solid #8884;
  border-radius: 4px;
  font: 13px/1.5 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
}

.ms-demo-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 12px 0;
}

@media (prefers-color-scheme: dark) {
  .ms-demo-body {
    background: #171512;
    color: #ebe3d3;
  }
}
