:root {
  --page: oklch(0.945 0.01 18);
  --paper: oklch(0.975 0.006 28);
  --ink: oklch(0.29 0.025 26);
  --muted: oklch(0.5 0.025 24);
  --rose: oklch(0.55 0.065 16);
  --line: oklch(0.78 0.025 18 / 0.72);
  --board: oklch(0.68 0.025 45);
  --owner-note: oklch(0.93 0.035 18);
  --hero-note: oklch(0.94 0.04 76);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
}

button,
input,
textarea { font: inherit; }

button,
label[for="photoInput"] { touch-action: manipulation; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
label:has(input:focus-visible) span {
  outline: 3px solid var(--rose);
  outline-offset: 3px;
}

.notes-app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) clamp(18px, 5vw, 56px) max(52px, env(safe-area-inset-bottom));
}

.notes-nav {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.78rem;
}

.notes-nav a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.password-gate {
  min-height: calc(100dvh - 92px);
  display: grid;
  place-items: center;
  padding-block: clamp(56px, 10vw, 110px);
}

.gate-paper {
  width: min(620px, 100%);
  padding: clamp(40px, 8vw, 76px);
  background-color: var(--paper);
  background-image: url("../assets/paper-texture.png");
  background-size: 520px auto;
  box-shadow: 0 4px 8px oklch(0.34 0.025 20 / 0.08);
}

.gate-paper > p,
.notes-heading p {
  margin: 0;
  color: var(--rose);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.78rem;
}

.gate-paper h1,
.notes-heading h1 {
  margin: 24px 0 38px;
  font-size: clamp(2.5rem, 8vw, 4.6rem);
  line-height: 1.2;
  font-weight: 400;
  text-wrap: balance;
}

.gate-paper form > label,
.message-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.84rem;
}

.password-row {
  display: flex;
  gap: 10px;
}

.password-row input {
  min-width: 0;
  flex: 1;
  min-height: 48px;
  padding: 10px 13px;
  color: var(--ink);
  background: oklch(1 0 0 / 0.72);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.password-row button,
.publish-button {
  min-height: 48px;
  padding: 10px 18px;
  color: oklch(0.98 0.005 20);
  background: var(--rose);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.password-row button:disabled,
.publish-button:disabled { opacity: 0.56; cursor: wait; }

.form-error {
  min-height: 1.5em;
  margin: 10px 0 0;
  color: oklch(0.46 0.14 25);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.82rem;
}

.notes-space { padding-top: clamp(48px, 9vw, 92px); }

.notes-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: clamp(44px, 8vw, 76px);
}

.notes-heading h1 { margin-bottom: 0; }

.quiet-button {
  min-height: 44px;
  padding: 8px 2px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.composer {
  width: min(760px, 100%);
  margin-bottom: clamp(58px, 10vw, 104px);
  padding: clamp(28px, 6vw, 52px);
  background-color: var(--paper);
  background-image: url("../assets/paper-texture.png");
  background-size: 520px auto;
  box-shadow: 0 4px 8px oklch(0.34 0.025 20 / 0.07);
}

.composer-heading h2,
.board-heading h2,
.delete-dialog h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  font-weight: 500;
  text-wrap: balance;
}

.identity-picker {
  display: flex;
  gap: 10px;
  margin: 20px 0 30px;
  padding: 0;
  border: 0;
}

.identity-picker legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.identity-picker label { flex: 1; cursor: pointer; }
.identity-picker input { position: absolute; opacity: 0; pointer-events: none; }

.identity-picker span {
  min-height: 70px;
  display: grid;
  align-content: center;
  padding: 10px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.identity-picker strong { font-size: 1.04rem; font-weight: 500; }

.identity-picker small {
  margin-top: 3px;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.74rem;
}

.identity-picker input:checked + span {
  color: var(--rose);
  border-color: var(--rose);
}

#noteBody {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  padding: 15px;
  color: var(--ink);
  background: oklch(1 0 0 / 0.58);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1.8;
  text-wrap: pretty;
}

#noteBody::placeholder { color: oklch(0.48 0.02 24); }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

#photoInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.photo-button {
  min-height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 8px 2px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.photo-preview {
  width: min(320px, 100%);
  margin: 18px 0 0;
  padding: 10px 10px 14px;
  background: oklch(0.98 0.005 28);
  box-shadow: 0 3px 6px oklch(0.28 0.02 20 / 0.1);
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.photo-preview button {
  margin-top: 10px;
  padding: 5px 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.form-hint {
  margin: 13px 0 0;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.74rem;
  line-height: 1.7;
}

.board-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.board-heading p {
  margin: 0;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.notes-board {
  min-height: 360px;
  padding: clamp(24px, 5vw, 46px);
  columns: 3 250px;
  column-gap: clamp(18px, 3vw, 30px);
  background-color: var(--board);
  background-image: url("../assets/paper-texture.png");
  background-size: 440px auto;
  box-shadow: inset 0 0 0 1px oklch(0.42 0.025 35 / 0.18);
}

.note,
.loading-note,
.empty-board {
  width: 100%;
  display: inline-block;
  break-inside: avoid;
  margin: 0 0 24px;
}

.note {
  position: relative;
  width: var(--note-width, 100%);
  padding: 24px 22px 20px;
  color: var(--ink);
  background-color: var(--owner-note);
  background-image: url("../assets/paper-texture.png");
  background-size: 360px auto;
  box-shadow: 3px 4px 7px oklch(0.27 0.025 30 / 0.15);
  margin-left: var(--note-indent, 0);
  margin-bottom: var(--note-gap, 24px);
  transform: translateX(var(--note-shift, 0)) rotate(var(--rotation, 0deg));
}

.note--hero { background-color: var(--hero-note); }

.note::before {
  content: "";
  position: absolute;
  top: -8px;
  left: calc(50% + var(--tape-shift, 0px));
  width: 54px;
  height: 18px;
  background: oklch(0.92 0.03 75 / 0.7);
  transform: translateX(-50%) rotate(-1deg);
}

.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.note-author { color: var(--rose); }

.note-menu {
  min-width: 36px;
  min-height: 36px;
  margin: -8px -10px -8px 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 1.05rem;
}

.note-photo {
  display: block;
  width: 100%;
  max-height: 440px;
  margin: 15px 0 14px;
  padding: 7px 7px 20px;
  object-fit: contain;
  background: oklch(0.98 0.004 30);
  box-shadow: 0 3px 6px oklch(0.28 0.02 20 / 0.1);
}

.note-body {
  margin: 16px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.85;
  text-wrap: pretty;
}

.reply-list {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.reply {
  width: var(--reply-width, 96%);
  justify-self: center;
  padding: 13px 14px 14px;
  background-color: oklch(0.965 0.018 24);
  background-image: url("../assets/paper-texture.png");
  background-size: 300px auto;
  box-shadow: 2px 3px 5px oklch(0.27 0.025 30 / 0.11);
  transform: translateX(var(--reply-shift, 0)) rotate(var(--reply-rotation, 0deg));
}

.reply--hero { background-color: oklch(0.96 0.026 75); }

.reply-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.reply-meta strong { color: var(--rose); font-weight: 500; }

.reply-delete {
  min-width: 44px;
  min-height: 44px;
  margin: -11px -12px -10px 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 1rem;
}

.reply > p {
  margin: 7px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.75;
  text-wrap: pretty;
}

.reply-composer { margin-top: 16px; }

.reply-toggle {
  min-height: 44px;
  padding: 7px 1px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.78rem;
}

.reply-form {
  margin-top: 12px;
  padding: 15px;
  background: oklch(0.985 0.006 25 / 0.72);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.reply-author-picker {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}

.reply-author-picker legend,
.reply-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.reply-author-picker label { flex: 1; cursor: pointer; }
.reply-author-picker input { position: absolute; opacity: 0; pointer-events: none; }

.reply-author-picker span {
  min-height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.78rem;
}

.reply-author-picker input:checked + span {
  color: var(--rose);
  border-color: var(--rose);
}

.reply-form textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  padding: 10px;
  color: var(--ink);
  background: oklch(1 0 0 / 0.68);
  border: 1px solid var(--line);
  border-radius: 4px;
  line-height: 1.7;
}

.reply-form textarea::placeholder { color: oklch(0.48 0.02 24); }

.reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 10px;
}

.reply-actions button {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.76rem;
}

.reply-cancel {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.reply-submit {
  color: oklch(0.98 0.005 20);
  background: var(--rose);
  border: 1px solid transparent;
}

.reply-submit:disabled { opacity: 0.56; cursor: wait; }

.reply-error {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: oklch(0.46 0.14 25);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.72rem;
}

.loading-note {
  height: 170px;
  background: oklch(0.91 0.02 55 / 0.68);
  box-shadow: 3px 4px 7px oklch(0.27 0.025 30 / 0.1);
}

.loading-note:nth-child(2) { height: 230px; }

.empty-board {
  padding: 48px 24px;
  color: oklch(0.3 0.02 30);
  background: oklch(0.94 0.025 70);
  text-align: center;
  line-height: 1.8;
}

.empty-board strong { display: block; font-size: 1.2rem; font-weight: 500; }
.empty-board span { display: block; margin-top: 7px; color: var(--muted); }

.delete-dialog {
  width: min(430px, calc(100% - 36px));
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 6px;
  box-shadow: 0 8px 24px oklch(0.22 0.025 20 / 0.22);
}

.delete-dialog::backdrop { background: oklch(0.2 0.02 20 / 0.46); }

.delete-dialog form { padding: 28px; }
.delete-dialog p { color: var(--muted); line-height: 1.7; }
.delete-dialog form > div { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

.delete-dialog button {
  min-height: 44px;
  padding: 8px 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.delete-dialog .delete-confirm {
  color: oklch(0.98 0.004 20);
  background: oklch(0.48 0.13 25);
  border-color: transparent;
}

[hidden] { display: none !important; }

@media (max-width: 640px) {
  .notes-nav span { text-align: right; }

  .password-row,
  .notes-heading,
  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .notes-heading { align-items: flex-start; }
  .quiet-button { align-self: flex-start; }

  .identity-picker { flex-direction: column; }

  .photo-button,
  .publish-button { width: 100%; }

  .notes-board {
    columns: 1;
    padding: 30px 24px;
  }

  .note {
    --note-shift: 0px !important;
    --note-width: 100% !important;
    --note-indent: 0px !important;
    transform: rotate(calc(var(--rotation, 0deg) * 0.45));
  }

  .reply {
    --reply-shift: 0px !important;
    width: min(var(--reply-width, 96%), 98%);
    transform: rotate(calc(var(--reply-rotation, 0deg) * 0.45));
  }
}
