@font-face {
  font-family: "Jiashang Hand B";
  src: url("./fonts/jiashang-hand-b.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Jiashang Print";
  src: url("./fonts/jiashang-print.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #F0E7D2;
  --grid-red: #B85C4F;
  --graphite: #4B4A45;
  --teacher-red: #C0392B;
  --stamp-red: #A8322A;
  --cover: #C7A97B;
  --spine: #2F4438;
  --ink: #292824;
  --desk: #74624E;
  --shadow: rgba(33, 27, 20, 0.24);
  --font-print: "Jiashang Print", serif;
  --font-hand-b: "Jiashang Hand B", serif;
  --font-teacher: sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #4B3322;
}

body {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-print);
  background-color: #4B3322;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 48%, rgba(20, 11, 6, 0.42) 100%),
    linear-gradient(to bottom, rgba(72, 45, 28, 0) 62%, rgba(77, 48, 29, 0.34) 77%, rgba(56, 34, 20, 0.46) 100%),
    linear-gradient(115deg, rgba(255, 247, 232, 0.08), rgba(255, 247, 232, 0) 30%),
    url("./assets/plate-11.png") center top / cover no-repeat,
    #4B3322;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled,
input:disabled {
  cursor: default;
}

.app-shell {
  /* 左右內距抽成變數，窄螢幕才有辦法讓稿紙整片出血到螢幕邊緣 */
  --shell-pad: clamp(14px, 3vw, 28px);
  width: min(1240px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  /* iPhone 安全區：瀏海與 home indicator 不壓到內容（桌機 env() 為 0，版面不變） */
  padding:
    calc(16px + env(safe-area-inset-top, 0px))
    max(var(--shell-pad), env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px))
    max(var(--shell-pad), env(safe-area-inset-left, 0px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: #FFF7E8;
  margin-bottom: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.82rem;
  letter-spacing: 0;
  opacity: 0.86;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 2.8vw, 2.4rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  letter-spacing: 0;
}

.reset-button,
.sound-toggle,
.back-button,
.primary-button,
.week-switch,
.settlement-actions button {
  border: 1px solid rgba(255, 247, 232, 0.42);
  border-radius: 6px;
  padding: 9px 14px;
  color: #FFF7E8;
  background: rgba(47, 68, 56, 0.78);
}

.reset-button:hover,
.sound-toggle:hover,
.back-button:hover,
.primary-button:hover,
.week-switch:hover,
.settlement-actions button:hover {
  background: rgba(47, 68, 56, 0.98);
}

.sound-toggle[data-enabled="true"] {
  color: #2F4438;
  border-color: rgba(255, 247, 232, 0.78);
  background: rgba(255, 247, 232, 0.86);
}

.app-main {
  min-height: calc(100vh - 92px);
}

.loading {
  color: #FFF7E8;
}

.name-view {
  display: grid;
  min-height: calc(100vh - 210px);
  place-items: center;
}

.name-form {
  width: min(420px, 100%);
  padding: 24px;
  color: var(--ink);
  border-radius: 6px;
  background: rgba(240, 231, 210, 0.96);
  box-shadow: 0 18px 36px var(--shadow);
}

.name-form .eyebrow {
  color: rgba(41, 40, 36, 0.74);
}

.name-form label {
  display: block;
  margin: 16px 0 8px;
  font-weight: 700;
}

.name-form input {
  width: 100%;
  padding: 11px 12px;
  color: var(--ink);
  border: 1px solid rgba(184, 92, 79, 0.62);
  border-radius: 5px;
  background: rgba(255, 248, 234, 0.88);
}

.name-form .primary-button {
  margin-top: 8px;
}

.desk-view {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 260px) 1fr;
  gap: clamp(18px, 4vw, 36px);
  align-items: start;
  isolation: isolate;
}

.desk-summary {
  position: relative;
  z-index: 2;
  color: #FFF7E8;
  padding-top: 8px;
}

.desk-summary p {
  line-height: 1.7;
  opacity: 0.92;
}

.week-history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.week-history-label {
  flex-basis: 100%;
  margin-bottom: 0;
  color: rgba(255, 247, 232, 0.82);
  font-size: 0.88rem;
}

.week-switch {
  padding: 7px 10px;
  font-size: 0.92rem;
}

.week-switch:disabled {
  opacity: 0.56;
}

.notebook-stack {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.desk-prop-notebooks {
  position: absolute;
  z-index: 1;
  left: clamp(10px, 3vw, 38px);
  top: clamp(390px, 56vh, 520px);
  width: min(23vw, 260px);
  min-width: 188px;
  height: auto;
  opacity: 0.92;
  filter: drop-shadow(0 18px 22px rgba(22, 13, 7, 0.38));
  pointer-events: none;
  transform: rotate(4deg);
  transform-origin: 50% 70%;
}

.notebook {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  text-align: left;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: 0 12px 24px var(--shadow);
  transform: rotate(var(--tilt));
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.notebook:hover {
  box-shadow: 0 16px 30px rgba(33, 27, 20, 0.32);
  transform: rotate(var(--tilt)) translateY(-3px);
}

.book-spine {
  display: none;
}

.book-cover {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

.book-cover::before {
  position: absolute;
  inset: -0.5%;
  background: var(--cover-image) center / contain no-repeat;
  content: "";
}

.book-week,
.book-meta {
  position: absolute;
  z-index: 1;
  font-size: clamp(0.68rem, 1.3vw, 0.86rem);
}

.book-week {
  top: 10.2%;
  left: 15.4%;
  color: rgba(41, 40, 36, 0.72);
}

.book-label {
  position: absolute;
  z-index: 1;
  top: 31.4%;
  left: 50%;
  display: grid;
  /* 兩行各自取自然高度＋行距，避免姓名加大後壓到座號 */
  grid-template-rows: auto auto;
  row-gap: 0.28em;
  align-content: center;
  justify-items: center;
  width: 58%;
  height: 22.4%;
  padding: 4.2% 5.5%;
  border: 2px solid rgba(170, 49, 38, 0.76);
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 1px rgba(170, 49, 38, 0.18),
    0.7px -0.5px 0 rgba(170, 49, 38, 0.24);
  transform: translate(-50%, -50%) rotate(-0.2deg);
}

.book-label::after {
  position: absolute;
  inset: 3px 2px 2px 3px;
  border: 1px solid rgba(170, 49, 38, 0.38);
  border-radius: 3px;
  content: "";
  pointer-events: none;
  transform: rotate(0.35deg);
}

.book-name {
  position: relative;
  z-index: 1;
  display: block;
  color: rgba(41, 40, 36, 0.82);
  text-align: center;
  font-family: var(--font-print);
  font-size: clamp(1.55rem, 3.1vw, 2.14rem);
  line-height: 1.05;
}

.book-meta {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  color: rgba(41, 40, 36, 0.72);
  text-align: center;
  font-family: var(--font-print);
  font-size: clamp(0.78rem, 1.5vw, 1rem);
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.book-status {
  position: absolute;
  z-index: 1;
  right: 2.3%;
  bottom: 5.3%;
  display: grid;
  place-items: center;
  width: 43%;
  aspect-ratio: 3 / 2;
  color: #A8322A;
  background: transparent var(--status-stamp-image) center / 100% 100% no-repeat;
  font-family: var(--font-print);
  font-size: clamp(1.45rem, 3vw, 2.1rem);
  font-weight: 700;
  line-height: 1;
  opacity: var(--status-stamp-opacity, 0.9);
  filter: saturate(var(--status-stamp-saturation, 1)) contrast(var(--status-stamp-contrast, 1));
  text-shadow: 0.03em 0.02em 0 rgba(168, 50, 42, 0.2);
  transform: rotate(var(--status-stamp-tilt, 0deg));
  transform-origin: 52% 48%;
}

.notebook.is-reviewed .book-status {
  color: #594C93;
  text-shadow: 0.03em 0.02em 0 rgba(89, 76, 147, 0.18);
}

.notebook.is-unsubmitted .book-meta {
  color: var(--teacher-red);
  font-weight: 700;
}

.review-view {
  color: #FFF7E8;
}

.review-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  margin-bottom: 10px;
}

.review-toolbar p {
  margin-bottom: 0;
  opacity: 0.9;
}

.review-topic {
  margin-top: 6px;
  color: #FFF0C2;
}

.lock-note {
  color: #FFE5DC;
}

.review-workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(238px, 292px);
  gap: 16px;
  align-items: stretch;
  height: min(760px, calc(100vh - 116px));
  min-height: 0;
}

.review-paper-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
}

.paper-sheet {
  container-type: inline-size;
  position: relative;
  width: min(100%, 570px);
  aspect-ratio: 1086 / 1448;
  max-height: calc(100% - 56px);
  min-height: 0;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  color: var(--graphite);
  border: 0;
  border-radius: 4px;
  box-shadow: 0 18px 36px var(--shadow);
  background-color: var(--paper);
  background-image: url("./assets/plate-16.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.paper-caption {
  flex: 0 0 auto;
  width: min(100%, 570px);
  min-height: 48px;
  margin-bottom: 8px;
  color: #FFF7E8;
  text-align: center;
  font-size: clamp(0.82rem, 1.45vw, 1rem);
  line-height: 1.45;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(22, 13, 7, 0.64);
}

.paper-caption p {
  margin-bottom: 0;
}

.paper-caption .review-topic {
  margin-top: 3px;
  color: rgba(255, 247, 232, 0.88);
}

.manuscript-text {
  position: absolute;
  inset: 0;
  overflow: hidden;
  font-family: var(--font-print);
  line-height: 1;
}

.paper-comment {
  position: absolute;
  z-index: 3;
  top: 14.2%;
  left: calc(var(--comment-left, 75.9668508287) * 1%);
  width: calc(var(--comment-width, 16.4825046041) * 1%);
  height: 72.8%;
  overflow: hidden;
  color: var(--teacher-red);
  font-family: var(--font-teacher);
  font-size: clamp(1rem, 3.3cqw, 1.28rem);
  font-style: italic;
  font-weight: 600;
  line-height: 1.42;
  text-align: start;
  text-orientation: upright;
  text-shadow: 0.02em 0.02em 0 rgba(168, 50, 42, 0.12);
  white-space: pre-wrap;
  word-break: break-all;
  writing-mode: vertical-rl;
  pointer-events: none;
}

.student-font-hand-a,
.student-font-hand-b {
  font-family: var(--font-hand-b);
}

.student-font-print {
  font-family: var(--font-print);
}

.paragraph {
  display: contents;
}

.char-cell {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  top: calc(var(--cell-top) * 1%);
  left: calc(var(--cell-left) * 1%);
  width: calc(var(--cell-width) * 1%);
  height: calc(var(--cell-height) * 1%);
  padding: 0;
  color: var(--graphite);
  background: transparent;
  border: 0;
  font-size: 1.26rem;
  line-height: 1;
  vertical-align: top;
}

.char-glyph {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--char-color, currentColor);
  pointer-events: none;
  transform:
    translate(
      calc(var(--char-offset-x, 0) * 0.208333cqw),
      calc(var(--char-offset-y, 0) * 0.208333cqw)
    )
    rotate(calc(var(--style-rotation, 0deg) + var(--char-rotation, 0deg)))
    scale(var(--char-size-scale, 1));
  transform-origin: 50% 50%;
}

.char-cell::after {
  position: absolute;
  inset: 9%;
  border: 2px solid transparent;
  border-radius: 50%;
  content: "";
  transform: rotate(-10deg);
}

.char-cell.is-circled::after {
  border-color: var(--teacher-red);
}

.char-cell:disabled {
  color: var(--graphite);
}

.char-cell:focus-visible,
.notebook:focus-visible,
.reset-button:focus-visible,
.sound-toggle:focus-visible,
.back-button:focus-visible,
.primary-button:focus-visible,
.week-switch:focus-visible,
.name-form input:focus-visible,
.grade-option:focus-visible,
.stamp-button:focus-visible,
.settlement-actions button:focus-visible {
  outline: 3px solid rgba(255, 247, 232, 0.9);
  outline-offset: 3px;
}

.writing-tool-pencil .char-cell {
  font-weight: 400;
}

.writing-tool-pencil .char-glyph {
  text-shadow:
    0.02em 0 rgba(75, 74, 69, 0.16),
    -0.025em 0.018em 0.055em rgba(75, 74, 69, 0.42),
    0.018em -0.016em 0.045em rgba(240, 231, 210, 0.62);
}

.writing-tool-pencil .char-cell.has-pencil-break .char-glyph {
  text-shadow:
    0.02em 0 rgba(75, 74, 69, 0.06),
    -0.02em 0.014em 0.04em rgba(75, 74, 69, 0.18);
}

.writing-tool-pen .char-cell {
  color: #1F2A2D;
  font-weight: 650;
}

.writing-tool-pen .char-glyph {
  text-shadow: 0 0 0 #1F2A2D;
}

.writing-tool-pen .char-cell.has-ink-blot .char-glyph {
  filter: blur(0.2px);
  text-shadow:
    0 0 0.06em rgba(31, 42, 45, 0.72),
    0.018em 0.012em 0 rgba(31, 42, 45, 0.48);
}

.handwriting-round .char-cell {
  font-size: 1.32rem;
}

.handwriting-tilted .char-cell {
  --style-rotation: 2deg;
}

.handwriting-light.writing-tool-pencil .char-cell {
  color: rgba(75, 74, 69, 0.78);
}

.handwriting-firm .char-cell {
  font-weight: 700;
}

.handwriting-small .char-cell {
  font-size: 1.06rem;
}

.handwriting-wide .char-cell {
  letter-spacing: 0;
  font-size: 1.36rem;
}

.handwriting-careful .char-cell {
  font-size: 1.2rem;
  font-weight: 500;
}

.handwriting-loose .char-cell:nth-child(3n) {
  font-size: 1.22rem;
}

.writing-scale-large .char-cell {
  font-size: 1.48rem;
}

.writing-scale-small .char-cell {
  font-size: 0.92rem;
}

.manuscript-unsubmitted {
  position: absolute;
  top: 17.5%;
  right: 14%;
  display: grid;
  place-items: center;
  width: 16%;
  aspect-ratio: 1;
  color: var(--teacher-red);
  border: 4px double var(--teacher-red);
  border-radius: 50%;
  font-size: clamp(1.4rem, 4vw, 2.8rem);
  font-weight: 700;
  line-height: 1;
  opacity: 0.82;
  transform: rotate(-10deg);
}

.teacher-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-height: 100%;
  padding: 15px;
  color: var(--ink);
  border-radius: 4px;
  background:
    linear-gradient(90deg, rgba(184, 92, 79, 0.15) 1px, transparent 1px) 22px 0 / 24px 100%,
    linear-gradient(180deg, rgba(255, 248, 234, 0.96), rgba(230, 211, 177, 0.96));
  box-shadow:
    0 18px 36px var(--shadow),
    inset 0 0 0 1px rgba(105, 73, 48, 0.2);
}

.review-prop {
  position: absolute;
  z-index: 0;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 14px 18px rgba(22, 13, 7, 0.38));
}

.review-prop-pen {
  top: 4px;
  right: -52px;
  width: min(22vw, 170px);
  transform: rotate(-18deg);
  transform-origin: 55% 50%;
}

.review-prop-ink {
  right: 246px;
  bottom: 14px;
  width: min(18vw, 132px);
  transform: rotate(-7deg);
}

.comment-label,
.grade-field legend {
  font-weight: 700;
}

textarea {
  width: 100%;
  resize: none;
  min-height: 96px;
  padding: 10px 8px;
  color: var(--teacher-red);
  font-family: var(--font-teacher);
  font-style: italic;
  border: 0;
  border-radius: 2px;
  border-bottom: 2px solid rgba(168, 50, 42, 0.38);
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 248, 234, 0.78) 0,
      rgba(255, 248, 234, 0.78) 30px,
      rgba(184, 92, 79, 0.28) 31px
    );
  line-height: 31px;
}

textarea:disabled {
  opacity: 0.78;
}

textarea:focus-visible {
  outline: 2px solid rgba(168, 50, 42, 0.42);
  outline-offset: 2px;
}

.branch-choice[hidden] {
  display: none;
}

.branch-field {
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(184, 92, 79, 0.5);
  border-radius: 6px;
  background: rgba(255, 248, 234, 0.6);
}

.branch-field legend {
  padding: 0 4px;
  color: var(--ink);
  font-weight: 700;
}

.branch-options {
  display: grid;
  gap: 8px;
}

.branch-option {
  width: 100%;
  padding: 9px 10px;
  color: var(--stamp-red);
  text-align: left;
  border: 2px solid rgba(168, 50, 42, 0.44);
  border-radius: 6px;
  background: rgba(255, 248, 234, 0.78);
  line-height: 1.5;
}

.grade-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.grade-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.grade-option {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  color: var(--stamp-red);
  border: 0;
  border-radius: 50%;
  background: transparent url("./assets/stamp-ring.png") center / contain no-repeat;
  font-size: clamp(1rem, 2.2vw, 1.34rem);
  font-weight: 700;
  line-height: 1;
  opacity: 0.45;
  text-shadow: 0 0 0 var(--stamp-red), 0.03em 0.02em 0 rgba(168, 50, 42, 0.18);
  transform: rotate(-4deg) scale(0.92);
}

.grade-option.is-selected {
  color: var(--stamp-red);
  opacity: 0.96;
  filter: saturate(1.24) contrast(1.08);
  transform: rotate(-9deg) scale(1.06);
}

.stamp-area {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 118px;
  margin-top: 0;
  border-top: 1px dashed rgba(184, 92, 79, 0.54);
}

.stamp-button {
  width: 86px;
  height: 86px;
  color: var(--stamp-red);
  border: 0;
  border-radius: 50%;
  background: transparent url("./assets/stamp-ring.png") center / contain no-repeat;
  font-size: 2.35rem;
  font-weight: 700;
  opacity: var(--stamp-opacity, 0.9);
  filter: saturate(var(--stamp-saturation, 1.08)) contrast(var(--stamp-contrast, 1.04));
  text-shadow: 0 0 0 var(--stamp-red), 0.03em 0.02em 0 rgba(168, 50, 42, 0.2);
  transform: rotate(var(--stamp-tilt, -4deg));
}

.stamp-button:hover:not(:disabled) {
  filter: saturate(1.12) contrast(1.05);
}

.stamp-button:disabled {
  opacity: 0.46;
}

.stamp-mark {
  position: absolute;
  right: 20px;
  bottom: 18px;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  color: var(--stamp-red);
  border: 0;
  border-radius: 50%;
  background: transparent url("./assets/stamp-ring.png") center / contain no-repeat;
  font-size: 2.2rem;
  font-weight: 700;
  opacity: 0;
  text-shadow: 0 0 0 var(--stamp-red), 0.03em 0.02em 0 rgba(168, 50, 42, 0.2);
  transform: translateY(-24px) rotate(var(--stamp-tilt, -4deg)) scale(1.4);
}

.stamp-mark.is-visible {
  opacity: var(--stamp-opacity, 0.86);
  filter: saturate(var(--stamp-saturation, 1.08)) contrast(var(--stamp-contrast, 1.04));
  transform: rotate(var(--stamp-tilt, -4deg)) scale(1);
}

.stamp-mark.is-animated {
  animation: stampDown 420ms cubic-bezier(0.18, 0.85, 0.28, 1.2) both;
}

.form-message {
  min-height: 1.2em;
  margin-bottom: 0;
  color: var(--teacher-red);
  font-size: 0.92rem;
}

.settlement-view {
  color: #FFF7E8;
}

.settlement-heading {
  margin-bottom: 20px;
}

.settlement-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  min-height: 112px;
  padding: 15px;
  color: var(--ink);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 12px 24px var(--shadow);
}

.stat-value {
  margin-bottom: 4px;
  color: var(--stamp-red);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1;
}

.stat-label {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.name-form input,
.teacher-name {
  font-family: var(--font-teacher);
  font-style: italic;
}

.stamp-ledger {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.ledger-stamp {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-height: 86px;
  color: var(--stamp-red);
  border: 0;
  border-radius: 50%;
  background: transparent url("./assets/stamp-ring.png") center / contain no-repeat;
  font-size: 1.8rem;
  font-weight: 700;
  opacity: var(--stamp-opacity, 0.86);
  filter: saturate(var(--stamp-saturation, 1.08)) contrast(var(--stamp-contrast, 1.04));
  text-shadow: 0 0 0 var(--stamp-red), 0.03em 0.02em 0 rgba(168, 50, 42, 0.2);
  transform: rotate(var(--stamp-tilt, 0deg));
}

.settlement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ending-view {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 0.92fr) minmax(320px, 0.72fr);
  gap: clamp(20px, 4vw, 48px);
  align-items: start;
  color: #FFF7E8;
  padding: 10px 0 36px;
}

.ending-paper {
  position: relative;
  justify-self: center;
  width: min(520px, 100%, calc((100vh - 168px) * 1086 / 1448));
  aspect-ratio: 1086 / 1448;
  min-height: 0;
  padding: 0;
  border-radius: 4px;
  background-color: var(--paper);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow: 0 22px 44px var(--shadow);
  transform: rotate(1.2deg);
}

.ending-kicker {
  position: absolute;
  top: 5.8%;
  left: 7%;
  right: 7%;
  margin-bottom: 0;
  color: rgba(41, 40, 36, 0.62);
  font-size: 0.92rem;
  line-height: 1.2;
  text-align: center;
}

.ending-copy {
  display: none;
}

.ending-desk-copy {
  max-width: 560px;
  color: rgba(255, 247, 232, 0.94);
  font-size: clamp(1rem, 2vw, 1.34rem);
  line-height: 1.9;
  text-shadow: 0 2px 2px rgba(29, 17, 9, 0.26);
}

.ending-desk-copy p {
  margin: 0 0 0.85em;
}

.ending-desk-copy p:nth-child(4) {
  margin-bottom: 1.65em;
}

.ending-roster {
  position: absolute;
  left: 13.8%;
  right: 11.6%;
  top: 20.4%;
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  row-gap: 3.1%;
  height: 31.2%;
  color: rgba(41, 40, 36, 0.82);
  font-size: clamp(0.7rem, 1.15vw, 0.95rem);
  line-height: 1.2;
}

.ending-roster-line {
  display: grid;
  grid-template-columns: 43% 57%;
  align-items: center;
  min-width: 0;
  margin: 0;
  font: inherit;
}

.ending-roster-line span {
  min-width: 0;
  overflow: hidden;
  padding: 0 8%;
  white-space: nowrap;
}

.ending-roster-line.is-small {
  font-size: 0.92em;
}

.ending-roster-line.is-destination {
  left: 74%;
  right: 1%;
  color: rgba(41, 40, 36, 0.88);
}

.ending-share {
  grid-column: 1;
  width: min(560px, 100%);
  padding: 18px 0 0;
  color: rgba(255, 247, 232, 0.94);
}

.ending-share h3 {
  margin: 0 0 12px;
  font-size: clamp(1.1rem, 1.7vw, 1.36rem);
  font-weight: 700;
  letter-spacing: 0;
}

.ending-share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ending-share-actions button {
  min-height: 44px;
  border: 1px solid rgba(255, 247, 232, 0.42);
  border-radius: 6px;
  padding: 10px 16px;
  color: #FFF7E8;
  background: rgba(47, 68, 56, 0.78);
}

.ending-share-actions button:hover {
  background: rgba(47, 68, 56, 0.98);
}

.ending-share-actions button:disabled {
  opacity: 0.58;
}

.ending-share-status {
  min-height: 1.6em;
  margin: 10px 0 0;
  color: rgba(255, 247, 232, 0.78);
  font-size: 0.92rem;
}

.ending-stamp-row {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-column: 1 / -1;
  gap: 6px 8px;
  width: min(760px, 100%);
  margin-top: 0;
}

.ending-review-stamp {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  color: var(--stamp-red);
  background: transparent url("./assets/stamp-ring.png") center / contain no-repeat;
  font-size: clamp(1rem, 2vw, 1.42rem);
  font-weight: 700;
  line-height: 1;
  opacity: var(--stamp-opacity, 0.84);
  filter: saturate(var(--stamp-saturation, 1.08)) contrast(var(--stamp-contrast, 1.04));
  text-shadow: 0 0 0 var(--stamp-red), 0.03em 0.02em 0 rgba(168, 50, 42, 0.18);
  transform: rotate(var(--stamp-tilt));
}

@keyframes stampDown {
  0% {
    opacity: 0;
    transform: translateY(-44px) rotate(var(--stamp-tilt, -4deg)) scale(1.55);
  }

  66% {
    opacity: var(--stamp-opacity, 0.86);
    transform: translateY(0) rotate(var(--stamp-tilt, -4deg)) scale(0.94);
  }

  100% {
    opacity: var(--stamp-opacity, 0.86);
    transform: rotate(var(--stamp-tilt, -4deg)) scale(1);
  }
}

@media (max-width: 860px) {
  .desk-view,
  .review-workspace {
    grid-template-columns: 1fr;
  }

  .review-workspace {
    height: auto;
  }

  .paper-sheet {
    max-height: none;
  }

  .desk-prop-notebooks {
    left: auto;
    /* 原本 right: -20px，加上 rotate(4deg) 的外接框會把整頁撐出橫向捲軸 */
    right: 12px;
    top: auto;
    bottom: -54px;
    width: 210px;
  }

  .review-prop {
    display: none;
  }

  .notebook-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ending-view {
    grid-template-columns: 1fr;
  }

  .ending-paper,
  .ending-share,
  .ending-stamp-row {
    justify-self: center;
  }

  .review-toolbar {
    grid-template-columns: 1fr auto;
  }

  .back-button {
    order: 2;
  }

  .lock-note {
    justify-self: end;
  }

  .settlement-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  /* 重置鈕移出頂部黃金位置，改釘在整頁最下方，並替它讓出空間 */
  .app-shell {
    position: relative;
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    display: contents;
  }

  .reset-button {
    position: absolute;
    right: max(var(--shell-pad), env(safe-area-inset-right, 0px));
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    padding: 7px 11px;
    color: rgba(255, 247, 232, 0.72);
    border-color: rgba(255, 247, 232, 0.24);
    background: rgba(47, 68, 56, 0.5);
    font-size: 0.86rem;
  }

  .reset-button[data-armed="true"] {
    color: #FFF7E8;
    border-color: rgba(192, 57, 43, 0.9);
    background: rgba(168, 50, 42, 0.92);
  }

  .sound-toggle {
    position: absolute;
    left: max(var(--shell-pad), env(safe-area-inset-left, 0px));
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    min-width: 84px;
    padding: 7px 11px;
    color: rgba(255, 247, 232, 0.72);
    border-color: rgba(255, 247, 232, 0.24);
    background: rgba(47, 68, 56, 0.5);
    font-size: 0.86rem;
  }

  .sound-toggle[data-enabled="true"] {
    color: #2F4438;
    border-color: rgba(255, 247, 232, 0.66);
    background: rgba(255, 247, 232, 0.78);
  }

  /* 書桌兩欄：一屏看得到四本，不用滾五個螢幕 */
  .notebook-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settlement-grid {
    grid-template-columns: 1fr;
  }

  /* 標籤框尺寸／位置維持百分比（九本一致），只把姓名字級縮到兩行塞得進去 */
  .book-name {
    font-size: clamp(0.9rem, 4.2vw, 1.6rem);
  }

  /* 那疊裝飾簿子在手機上只會製造橫向溢出，直接收掉 */
  .desk-prop-notebooks {
    display: none;
  }

  /* 稿紙整片出血並放大，讓每格手指圈得動；只有這個容器可以橫向捲 */
  .review-paper-column {
    align-items: flex-start;
    margin-inline: calc(var(--shell-pad) * -1);
    padding-inline: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .paper-caption,
  .paper-sheet {
    width: max(440px, 100%);
    max-width: none;
    margin-inline: 0;
  }

  .paper-caption {
    padding-inline: 10px;
  }

  /* 這裡原本有一條 .char-cell::before { inset: -2px } 想撐大命中區，已移除。
     實測：字格是密鋪的（欄距 33.65px vs 格寬 33.63px、列距 29.98px vs 格高 29.97px，
     間隙只有 0.02px），根本沒有空隙可以撐。往外 2px 只是去搶四個鄰格的地盤，
     而重疊帶由「後畫的那一格」勝出（DOM 順序＝行文順序），結果是點在格子內、
     離下緣或左緣 2px 以內會圈到下一個字／左邊那一欄的字。
     實測誤判率：內縮 1px 取樣 170/452、內縮 2px 104/452；移除後 0/452。
     命中區已經等於視覺格子本身、且格子彼此密鋪，本來就沒有可回收的空白。 */

  .grade-options,
  .stamp-ledger {
    grid-template-columns: repeat(2, 1fr);
  }

  .ending-paper {
    width: min(100%, calc((100vh - 154px) * 1086 / 1448));
  }

  .ending-share {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .ending-share-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .ending-share-actions button {
    width: 100%;
    padding-inline: 10px;
  }

  .ending-stamp-row {
    grid-template-columns: repeat(9, minmax(0, 1fr));
  }
}
