/* =============================================================================
   log.t97.vn — design system "Hand-Drawn"
   Giấy ngà, chì đen, bút xoá đỏ, bút bi xanh, giấy note vàng. Mọi khung dùng viền
   nguệch ngoạc và bóng cứng không nhoè.
   Ngoại lệ có chủ đích: ô mã và ô soạn log luôn đứng thẳng, log dùng font mono
   để đọc và copy chính xác.
   ============================================================================= */

/* ---------- Font tự host (latin + vietnamese) ---------- */

@font-face {
  font-family: "Patrick Hand";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/patrick-hand-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Patrick Hand";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/patrick-hand-vietnamese-400-normal.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Shantell Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/shantell-sans-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Shantell Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/shantell-sans-vietnamese-700-normal.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-vietnamese-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

/* ---------- Token ---------- */

:root {
  color-scheme: light;

  /* Màu: chỉ 1 bảng màu sáng */
  --paper: #fdfbf7; /* giấy ngà */
  --ink: #2d2d2d; /* chì đen, không bao giờ dùng đen tuyền */
  --muted: #e5e0d8; /* giấy cũ, vết tẩy */
  --marker: #ff4d4d; /* bút xoá đỏ */
  --pen: #2d5da1; /* bút bi xanh */
  --postit: #fff9c4; /* giấy note vàng */
  --sheet: #ffffff;
  --ink-soft: rgb(45 45 45 / 0.7);
  --ink-faint: rgb(45 45 45 / 0.4);
  --pen-ring: rgb(45 93 161 / 0.2);
  --marker-tint: rgb(255 77 77 / 0.12);
  --marker-fill: rgb(255 77 77 / 0.3); /* thanh giữ-để-xoá */
  --highlighter: #ffe066; /* bút dạ vàng: tô dòng mới, mức dung lượng trung bình */
  /* Màu cú pháp JSON: đều đạt ≥ 4,5:1 trên nền trắng, mọi kênh ≥ 45 để hoà "lighten" ra đúng màu */
  --syn-key: #2d5da1;
  --syn-str: #2d7a3d;
  --syn-num: #b4532d;
  --syn-lit: #b0306a;
  --tape: rgb(190 184 172 / 0.55);

  /* Viền nguệch ngoạc */
  --wobbly: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobbly-md: 15px 255px 15px 225px / 225px 15px 255px 15px;
  --wobbly-lg: 2% 6% 5% 4% / 1% 1% 2% 4%;
  --blob: 52% 48% 55% 45% / 48% 55% 45% 52%; /* vòng tròn vẽ tay */

  /* Bóng cứng, không blur */
  --shadow-sm: 2px 2px 0 0 var(--ink);
  --shadow: 4px 4px 0 0 var(--ink);
  --shadow-md: 6px 6px 0 0 var(--ink);
  --shadow-lg: 8px 8px 0 0 var(--ink);
  --shadow-soft: 3px 3px 0 0 rgb(45 45 45 / 0.1);

  /* Chữ */
  --font-head: "Shantell Sans", "Patrick Hand", "Comic Sans MS", cursive;
  --font-body: "Patrick Hand", "Comic Sans MS", cursive;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Chuyển động nhanh, dứt khoát */
  --snap: 100ms;

  /* Hình vẽ tay dùng lại (data URI, CSP cho phép img-src data:) */
  --squiggle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 8'%3E%3Cpath d='M2 5Q7 1 12 4T22 3' fill='none' stroke='%232d2d2d' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E");
  --wave-red: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='6' viewBox='0 0 20 6'%3E%3Cpath d='M0 3Q5 0 10 3T20 3' fill='none' stroke='%23ff4d4d' stroke-width='2'/%3E%3C/svg%3E");
  --arrow-up: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 26'%3E%3Cpath d='M29 23C20 23 10 18 7 6' fill='none' stroke='%232d2d2d' stroke-width='2.5' stroke-linecap='round'/%3E%3Cpath d='M2 11l5-7 5 6' fill='none' stroke='%232d2d2d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ---------- Nền ---------- */

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

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(var(--muted) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font: 400 19px/1.45 var(--font-body);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden; /* đồ trang trí xoay/thò ra ngoài không tạo thanh cuộn ngang */
}

[hidden] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--postit);
  color: var(--ink);
}

:focus-visible {
  outline: 3px dashed var(--pen);
  outline-offset: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Icon lucide: nét đậm 2.5 */
.btn svg,
.icon-btn svg,
.tag svg,
.ring svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell {
  width: 100%;
  max-width: 1024px;
  margin: 0 auto;
  padding: 20px 24px calc(40px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 28px;
  flex: 1;
}

/* ---------- Đầu trang ---------- */

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

.brand {
  padding-bottom: 7px;
  color: var(--ink);
  font: 700 24px/1 var(--font-head);
  text-decoration: none;
  background: var(--wave-red) repeat-x left bottom / 20px 6px;
}

.brand span {
  color: var(--pen);
}

.e2e {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  transform: rotate(-1.5deg);
}

.ring {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: var(--blob);
}

.ring svg {
  width: 18px;
  height: 18px;
}

/* ---------- Hero ---------- */

.hero {
  display: grid;
  align-items: center;
  gap: 16px;
  padding-top: 20px;
}

.title {
  margin: 0;
  font: 700 clamp(40px, 7vw, 64px)/1.05 var(--font-head);
  letter-spacing: -0.01em;
}

.bang {
  display: inline-block;
  margin-left: 0.04em;
  color: var(--marker);
  transform-origin: 50% 90%;
  animation: rock 3s ease-in-out infinite;
}

.lead {
  margin: 12px 0 0;
  max-width: 32em;
  font-size: clamp(20px, 2.4vw, 24px);
  color: var(--ink-soft);
}

.doodle {
  display: none;
  width: 300px;
  height: 170px;
  justify-self: end;
}

.doodle path,
.doodle circle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doodle .fill-sheet {
  fill: var(--sheet);
}

.doodle .fill-muted {
  fill: var(--muted);
}

.doodle .fill-postit {
  fill: var(--postit);
}

.doodle .pen {
  stroke: var(--pen);
  stroke-width: 2.5;
}

.doodle .dash {
  stroke-dasharray: 6 7;
}

.doodle-note {
  transform-box: fill-box;
  transform-origin: center;
  animation: bob 3s ease-in-out infinite;
}

@media (min-width: 768px) {
  .hero {
    grid-template-columns: 1fr 300px;
  }

  .doodle {
    display: block;
  }
}

/* ---------- Hai lựa chọn ---------- */

.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
  margin-top: 8px;
}

@media (min-width: 768px) {
  .split {
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    gap: 28px;
  }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 32px 24px 26px;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow-soft);
  transition: transform var(--snap);
}

.card h2 {
  margin: 0;
  font: 700 clamp(28px, 3.4vw, 34px)/1.1 var(--font-head);
}

.card-create {
  transform: rotate(-1deg);
}

.card-create:hover {
  transform: rotate(0.6deg);
}

/* Giấy note: nền vàng là lớp ::before xoay nghiêng, nội dung bên trong vẫn thẳng. */
.note {
  position: relative;
}

.note::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--postit);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow);
  transform: rotate(1.2deg);
  transition: transform var(--snap);
}

.note:hover::before {
  transform: rotate(-0.5deg);
}

.note > * {
  position: relative;
  z-index: 1;
}

.note > .tape,
.note > .tack {
  position: absolute;
  z-index: 2;
}

.card.note {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  font: 700 22px/1 var(--font-head);
}

.or::before,
.or::after {
  content: "";
  flex: 1;
  border-top: 2px dashed var(--ink-faint);
}

.or span {
  padding: 10px 14px;
  background: var(--paper);
  border: 2px dashed var(--ink);
  border-radius: var(--blob);
  transform: rotate(-6deg);
}

@media (min-width: 768px) {
  .or {
    flex-direction: column;
    align-self: stretch;
    padding: 24px 0;
  }

  .or::before,
  .or::after {
    border-top: 0;
    border-left: 2px dashed var(--ink-faint);
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.label {
  color: var(--ink-soft);
}

.hint {
  margin: 0;
  font-size: 18px;
  color: var(--ink-soft);
}

.error {
  margin: 0;
  color: var(--ink);
  text-decoration: underline wavy var(--marker) 2px;
  text-underline-offset: 6px;
  text-decoration-skip-ink: none;
}

/* Lựa chọn dạng thẻ: chọn rồi thì thành mẩu giấy note dán lên */
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.seg button {
  appearance: none;
  min-height: 48px;
  padding: 6px 18px;
  color: var(--ink-soft);
  background: var(--sheet);
  border: 2px dashed var(--ink-faint);
  border-radius: var(--wobbly);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform var(--snap), background-color var(--snap), border-color var(--snap);
}

.seg button:hover {
  color: var(--ink);
  border-color: var(--ink);
  transform: rotate(-2deg);
}

.seg button[aria-checked="true"] {
  color: var(--ink);
  background: var(--postit);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  transform: rotate(-1deg);
}

.seg button[aria-checked="true"]:hover {
  transform: rotate(1deg);
}

/* Mũi tên "bắt đầu ở đây" — chỉ màn rộng, khi lề đủ chỗ */
.create-hint {
  font-size: 17px;
}

.start-here {
  display: none;
  position: absolute;
  left: -128px;
  bottom: 20px;
  width: 128px;
  pointer-events: none;
}

.start-here span {
  display: block;
  margin-left: 4px;
  color: var(--marker);
  font-size: 21px;
  line-height: 1.1;
  transform: rotate(-8deg);
}

.start-here svg {
  width: 120px;
  height: 90px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.start-here .dash {
  stroke-dasharray: 6 7;
}

@media (min-width: 1200px) {
  .start-here {
    display: block;
  }
}

.foot {
  margin: 4px 0 0;
  max-width: 44em;
  padding: 14px 18px;
  color: var(--ink-soft);
  font-size: 18px;
  border: 2px dashed var(--ink-faint);
  border-radius: var(--wobbly-md);
  transform: rotate(0.4deg);
}

/* ---------- Nút ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 20px;
  color: var(--ink);
  background: var(--sheet);
  border: 3px solid var(--ink);
  border-radius: var(--wobbly);
  box-shadow: var(--shadow);
  font-size: 20px;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--snap), box-shadow var(--snap), background-color var(--snap), color var(--snap);
}

.btn:not(:disabled):hover {
  color: #fff;
  background: var(--marker);
  box-shadow: var(--shadow-sm);
  transform: translate(2px, 2px);
}

.btn:not(:disabled):active {
  box-shadow: none;
  transform: translate(4px, 4px);
}

.btn.secondary {
  background: var(--muted);
}

.btn.secondary:not(:disabled):hover {
  background: var(--pen);
}

.btn.cta {
  min-height: 56px;
  padding: 10px 26px;
  background: var(--postit);
  box-shadow: var(--shadow-md);
  font-size: clamp(21px, 2.4vw, 24px);
}

.note .btn.cta,
.banner .btn.cta {
  background: var(--sheet);
}

.btn.cta:not(:disabled):hover {
  box-shadow: var(--shadow-sm);
  transform: translate(4px, 4px);
}

.btn.cta:not(:disabled):active {
  box-shadow: none;
  transform: translate(6px, 6px);
}

/* Nút nguy hiểm: viền và bóng màu bút xoá đỏ, chữ vẫn chì đen để đủ tương phản */
.btn.danger {
  border-color: var(--marker);
  box-shadow: 4px 4px 0 0 var(--marker);
}

.btn.danger:not(:disabled):hover {
  box-shadow: 2px 2px 0 0 var(--marker);
}

/* Giữ để xoá: thanh đỏ chạy ngang nút trong lúc giữ, nhả sớm là huỷ */
.btn.hold {
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.btn.hold::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--marker-fill);
  transform-origin: left center;
  transform: scaleX(0);
  pointer-events: none;
}

.btn.hold.holding::after {
  transform: scaleX(1);
  transition: transform var(--hold, 1000ms) linear;
}

.btn.hold > * {
  position: relative;
  z-index: 1;
}

.btn.hold.holding,
.btn.hold.holding:hover {
  color: var(--ink);
  background: var(--sheet);
  box-shadow: none;
  transform: translate(4px, 4px);
}

/* Nút Lưu nảy nhẹ khi vừa có thay đổi cần lưu */
@media (prefers-reduced-motion: no-preference) {
  .btn.save.nudge {
    animation: nudge 0.35s ease-out;
  }
}

@keyframes nudge {
  40% {
    transform: rotate(-4deg) scale(1.06);
  }
}

.btn.small {
  min-height: 42px;
  padding: 6px 16px;
  font-size: 19px;
  box-shadow: 3px 3px 0 0 var(--ink);
}

.btn.small:not(:disabled):hover {
  box-shadow: 1px 1px 0 0 var(--ink);
}

.btn.block {
  width: 100%;
}

.btn[aria-pressed="true"] {
  background: var(--postit);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
}

/* Nút tạm khoá bằng aria-disabled (giữ được focus): không đổi màu/nhún khi rê chuột */
.btn.btn[aria-disabled="true"]:hover,
.btn.btn[aria-disabled="true"]:active {
  color: var(--ink);
  background: var(--sheet);
  box-shadow: 3px 3px 0 0 var(--ink);
  transform: none;
}

.btn.btn.secondary[aria-disabled="true"]:hover,
.btn.btn.secondary[aria-disabled="true"]:active {
  background: var(--muted);
}

.icon-btn {
  appearance: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--sheet);
  border: 2.5px solid var(--ink);
  border-radius: var(--blob);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--snap), background-color var(--snap);
}

.icon-btn:hover {
  background: var(--postit);
  transform: rotate(-8deg);
}

.icon-btn:active {
  box-shadow: none;
  transform: translate(2px, 2px);
}

/* Copy → dấu tick: icon copy thu lại, dấu tick bút bi xanh được vẽ ra */
.icon-btn > svg {
  grid-area: 1 / 1;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.ico-done {
  color: var(--pen);
  stroke-width: 3 !important;
}

.icon-btn .ico-done {
  opacity: 0;
  transform: scale(0.6);
}

.icon-btn.done .ico {
  opacity: 0;
  transform: scale(0.4) rotate(-25deg);
}

.icon-btn.done .ico-done {
  opacity: 1;
  transform: none;
}

.btn .ico-done,
.btn.done .ico {
  display: none;
}

.btn.done .ico-done {
  display: block;
}

.btn.done {
  color: var(--pen);
  background: var(--sheet);
}

/* ---------- Ô mã 8 ký tự (luôn đứng thẳng) ---------- */

.cells {
  display: inline-flex;
  align-items: center;
  gap: 0.22em;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.4em;
  height: 1.8em;
  color: var(--ink);
  background: var(--sheet);
  border: 2.5px solid var(--ink);
  border-radius: 18% 30% 22% 34% / 30% 18% 34% 22%;
  box-shadow: 3px 3px 0 0 var(--ink);
  font: 700 1em/1 var(--font-head);
}

.cell:nth-child(2n) {
  border-radius: 30% 18% 34% 22% / 22% 34% 18% 30%;
}

.cell:nth-child(3n) {
  border-radius: 26% 34% 18% 28% / 34% 22% 30% 18%;
}

.cells .sep {
  width: 0.55em;
  height: 0.35em;
  background: var(--squiggle) center / contain no-repeat;
}

.entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
}

.entry .btn {
  flex: 1 0 auto;
}

.cells-field {
  position: relative;
  display: inline-flex;
  font-size: clamp(19px, 5.4vw, 30px);
  cursor: text;
}

.cells-field .cell {
  border-style: dashed;
  border-color: var(--ink-faint);
  box-shadow: none;
}

.cells-field .cell.filled {
  border-style: solid;
  border-color: var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
}

.cells-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px; /* tránh iOS tự phóng to khi focus */
  caret-color: transparent;
  cursor: text;
}

.cells-field:focus-within .cell.active {
  border: 2.5px solid var(--pen);
  box-shadow: 0 0 0 4px var(--pen-ring);
}

.cells-field:focus-within .cell.active:empty::after {
  content: "";
  width: 2px;
  height: 1em;
  background: var(--pen);
  animation: blink 1s steps(1) infinite;
}

/* Ô mã phản hồi: nảy khi điền, lắc khi sai, gợn sóng khi đang kiểm tra mã */
.cells.shake .cell {
  border-style: solid;
  border-color: var(--marker);
}

@media (prefers-reduced-motion: no-preference) {
  .cell.pop {
    animation: cell-pop 0.22s ease-out both;
    animation-delay: calc(var(--d, 0) * 35ms);
  }

  .cells.shake {
    animation: cells-shake 0.42s ease-in-out;
  }

  .cells.checking .cell {
    animation: cell-wave 0.9s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 70ms);
  }

  .code-show .cell.settle {
    animation: cell-pop 0.22s ease-out;
  }
}

@keyframes cell-pop {
  0% {
    transform: scale(0.7) rotate(-6deg);
  }
  60% {
    transform: scale(1.12) rotate(3deg);
  }
  100% {
    transform: none;
  }
}

@keyframes cells-shake {
  15%,
  85% {
    transform: translateX(-3px);
  }
  30%,
  70% {
    transform: translateX(6px);
  }
  45% {
    transform: translateX(-8px);
  }
  60% {
    transform: translateX(8px);
  }
}

@keyframes cell-wave {
  0%,
  60%,
  100% {
    transform: none;
  }
  30% {
    transform: translateY(-8px) rotate(-3deg);
  }
}

/* ---------- Phiên làm việc ---------- */

.session-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px 28px;
  padding-top: 18px;
}

.code-note {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 100%;
  padding: 30px 24px 20px;
}

.code-note::before {
  transform: rotate(-1deg);
}

.code-note:hover::before {
  transform: rotate(0.6deg);
}

.code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 18px;
}

.code-show {
  font-size: clamp(22px, 6.2vw, 40px);
}

.code-show .cell {
  color: var(--pen); /* mã viết bằng bút bi xanh */
}

.tools {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.share-btn {
  min-height: 48px;
}

/* Số máy đang mở: từng chữ số cuộn lên/xuống khi đổi */
.odo {
  display: inline-flex;
}

.odo-d {
  display: inline-grid;
  overflow: hidden;
  line-height: 1.3;
}

.odo-d > span {
  grid-area: 1 / 1;
}

.code-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.code-hint::before {
  content: "";
  width: 32px;
  height: 26px;
  flex: none;
  background: var(--arrow-up) center / contain no-repeat;
}

.code-hint b {
  color: var(--pen);
  font: 700 0.95em var(--font-head);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

@media (min-width: 1000px) {
  .tags {
    flex-direction: column;
    align-items: flex-end;
  }
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 14px;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly);
  font-size: 18px;
  line-height: 1;
  white-space: nowrap;
}

.tag.dashed {
  border-style: dashed;
}

.tag svg {
  width: 18px;
  height: 18px;
}

.tag-mode {
  background: var(--postit);
  box-shadow: var(--shadow-sm);
  font: 700 17px/1 var(--font-head);
  transform: rotate(-2.5deg);
}

.tag-mode[data-mode="once"] {
  border-color: var(--marker);
  box-shadow: 2px 2px 0 0 var(--marker);
}

#s-remain[data-tone="warn"] {
  background: var(--marker-tint);
  border-color: var(--marker);
  border-style: solid;
}

/* Thanh thời hạn co dần ở đáy chip đếm ngược */
.remain {
  position: relative;
  padding-bottom: 9px;
}

.ttl {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 4px;
  height: 3px;
  overflow: hidden;
  background: var(--muted);
  border-radius: 2px;
}

.ttl b {
  position: absolute;
  inset: 0;
  background: var(--pen);
  transform-origin: left center;
  transform: scaleX(var(--left, 1));
  transition: transform 1s linear;
}

#s-remain[data-tone="warn"] .ttl b {
  background: var(--marker);
}

#s-remain[data-state="ended"] {
  padding-bottom: 4px;
}

#s-remain[data-state="ended"] .ttl {
  display: none;
}

.conn i {
  width: 11px;
  height: 11px;
  background: var(--ink-faint);
  border: 1.5px solid var(--ink);
  border-radius: var(--blob);
}

.conn[data-state="live"] i {
  background: var(--pen);
}

.conn[data-state="connecting"] i,
.conn[data-state="reconnecting"] i {
  background: var(--marker);
  animation: blink 1.2s steps(1) infinite;
}

.conn[data-state="poll"] i {
  background: var(--postit);
}

.banner {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 18px 20px 16px 24px;
  background: var(--postit);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow);
  transform: rotate(-0.4deg);
}

.banner .tack {
  left: 30px;
  margin-left: 0;
}

.banner p {
  margin: 0;
  flex: 1 1 260px;
  font-size: 20px;
}

.banner[data-tone="warn"] {
  border: 3px dashed var(--marker);
}

.banner[data-tone="muted"] {
  background: var(--sheet);
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.gate {
  width: 100%;
  max-width: 580px;
  margin: 8px 0 0 6px;
  padding: 36px 28px 28px;
  gap: 14px;
}

.gate::before {
  transform: rotate(-1.5deg);
}

.gate:hover::before {
  transform: rotate(-0.4deg);
}

.gate p {
  margin: 0;
  font-size: 20px;
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding-top: 6px;
}

/* Tờ soạn log: thẳng, kẻ dòng như vở, lề đỏ bên trái */
.sheet {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--sheet);
  border: 3px solid var(--ink);
  border-radius: var(--wobbly-lg);
  box-shadow: var(--shadow);
  transition: border-color var(--snap), box-shadow var(--snap);
}

.sheet:focus-within {
  border-color: var(--pen);
  box-shadow: var(--shadow), 0 0 0 4px var(--pen-ring);
}

/* Tờ soạn chỉ nhận focus bằng code (sau khi banner biến mất): viền xanh ở trên là đủ */
.sheet:focus {
  outline: none;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 14px 10px 22px;
  border-bottom: 2px dashed var(--muted);
  color: var(--ink-soft);
}

/* Trạng thái lưu: chấm đỏ (chưa lưu) → vòng xoay (đang lưu) → dấu tick vẽ tay (đã lưu) */
.status {
  display: inline-flex;
  flex: 1 1 6.5em;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 30px;
}

.st-icon {
  display: none;
  width: 20px;
  height: 20px;
  flex: none;
  place-items: center;
}

.status:not([data-icon=""]) .st-icon {
  display: inline-grid;
}

.st-icon > * {
  grid-area: 1 / 1;
  display: none;
}

.status[data-icon="dot"] .st-dot {
  display: block;
  width: 11px;
  height: 11px;
  background: var(--marker);
  border: 1.5px solid var(--ink);
  border-radius: var(--blob);
}

.status[data-icon="spin"] .st-spin {
  display: block;
  width: 17px;
  height: 17px;
  border: 2.5px dashed var(--pen);
  border-radius: var(--blob);
  animation: spin 0.9s linear infinite;
}

.status[data-icon="tick"] .st-tick {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--pen);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status[data-tone="ok"] {
  color: var(--pen);
}

.status[data-tone="dirty"] {
  color: var(--ink);
}

.status[data-tone="warn"],
.status[data-tone="error"] {
  color: var(--ink);
}

.status[data-tone="warn"] .st-text,
.status[data-tone="error"] .st-text {
  text-decoration: underline wavy var(--marker) 2px;
  text-underline-offset: 6px;
  text-decoration-skip-ink: none;
}

.save-tools {
  display: inline-flex;
  flex: none;
  gap: 10px;
  margin-left: auto;
}

.btn.save:disabled {
  background: var(--sheet);
  box-shadow: 2px 2px 0 0 var(--ink-faint);
  border-color: var(--ink-faint);
  opacity: 1;
  color: var(--ink-faint);
}

.editor-wrap {
  --lh: 22px;
  --top: 12px;
  --margin: 42px;
  --pad-r: 20px;
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.size {
  font-size: 17px;
  white-space: nowrap;
}

#s-text,
.marks,
.syntax {
  padding: var(--top) var(--pad-r) 24px calc(var(--margin) + 16px);
  font: 400 14px/var(--lh) var(--font-mono);
  letter-spacing: normal;
  tab-size: 2;
}

#s-text {
  flex: 1;
  width: 100%;
  min-height: 260px;
  margin: 0;
  color: var(--ink);
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  background-color: var(--sheet);
  background-image:
    linear-gradient(90deg, transparent var(--margin), rgb(255 77 77 / 0.45) var(--margin), rgb(255 77 77 / 0.45) calc(var(--margin) + 2px), transparent calc(var(--margin) + 2px)),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--lh) - 1px), rgb(45 93 161 / 0.16) calc(var(--lh) - 1px), rgb(45 93 161 / 0.16) var(--lh));
  background-position: 0 0, 0 var(--top);
  background-attachment: local, local;
  transition: background-color 0.7s ease;
}

#s-text::placeholder {
  color: var(--ink-faint);
  font: 20px/var(--lh) var(--font-body);
}

#s-text.nowrap {
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

#s-text[readonly] {
  color: var(--ink-soft);
}

/* Log quá dài để tô từng dòng: nháy nền cả ô */
#s-text.flash {
  background-color: rgb(255 249 196 / 0.7);
  transition: none;
}

/* Bút dạ quét các dòng mới/vừa sửa. Lớp phủ trùng khít ô soạn (cùng font, lề, ngắt dòng),
   chữ trong suốt, chỉ hiện vệt vàng; multiply để chữ bên dưới vẫn đọc được. */
/* iOS Safari thêm 3px đệm không gỡ được ở 2 bên chữ trong textarea: lớp phủ đệm theo cho khớp */
.editor-wrap.ios .marks,
.editor-wrap.ios .syntax {
  padding-left: calc(var(--margin) + 16px + 3px);
  padding-right: calc(var(--pad-r) + 3px);
}

/* Tô màu JSON: lớp phủ chép y nguyên nội dung, chỉ token JSON có màu, hoà trộn "lighten" với ô soạn
   nên màu chỉ hiện đúng chỗ trùng nét chữ thật; lớp phủ có trễ một nhịp khi gõ thì chữ vẫn đúng. */
.syntax {
  position: absolute;
  top: 0;
  left: 0;
  right: var(--sbw, 0px);
  bottom: var(--sbh, 0px);
  z-index: 1;
  margin: 0;
  overflow: hidden;
  color: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
  mix-blend-mode: lighten;
}

.syntax.nowrap {
  white-space: pre;
  overflow-wrap: normal;
}

.syntax .j-key {
  color: var(--syn-key);
}

.syntax .j-str {
  color: var(--syn-str);
}

.syntax .j-num {
  color: var(--syn-num);
}

.syntax .j-lit {
  color: var(--syn-lit);
}

.foot-note {
  margin-left: auto;
  font-size: 16px;
  color: var(--ink-soft);
}

.marks {
  position: absolute;
  top: 0;
  left: 0;
  right: var(--sbw, 0px);
  bottom: var(--sbh, 0px);
  z-index: 2;
  margin: 0;
  overflow: hidden;
  color: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
  mix-blend-mode: multiply;
  transition: opacity 0.8s ease;
}

.marks.nowrap {
  white-space: pre;
  overflow-wrap: normal;
}

.marks.fade {
  opacity: 0;
}

.marks mark {
  color: transparent;
  background: linear-gradient(var(--highlighter), var(--highlighter)) no-repeat left center / 100% 90%;
  border-radius: 3px 8px 4px 9px / 8px 4px 9px 3px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* Dòng JSON lỗi: gạch sóng đỏ + khoanh tay quanh dòng */
.marks mark.err {
  background: none;
  text-decoration: underline wavy var(--marker) 2px;
  text-underline-offset: 4px;
  text-decoration-skip-ink: none;
  border-radius: 40% 60% 45% 55% / 60% 45% 55% 40%;
  box-shadow: 0 0 0 3px rgb(255 77 77 / 0.6);
}

@media (prefers-reduced-motion: no-preference) {
  .marks mark {
    background-size: 0% 90%;
    animation: sweep 0.5s cubic-bezier(0.3, 0.7, 0.3, 1) forwards;
    animation-delay: calc(var(--i, 0) * 45ms);
  }

  .marks mark.err {
    background-size: auto;
    animation: circle-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  }

  .btn.shake {
    animation: cells-shake 0.42s ease-in-out;
  }
}

@keyframes circle-in {
  from {
    box-shadow: 0 0 0 14px rgb(255 77 77 / 0);
  }
}

@keyframes sweep {
  to {
    background-size: 100% 90%;
  }
}

/* Chân tờ: thước dung lượng sau nén + mã hoá so với giới hạn */
.sheet-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 22px 10px;
  border-top: 2px dashed var(--muted);
  color: var(--ink-soft);
}

.meter {
  position: relative;
  width: 96px;
  height: 13px;
  flex: none;
  overflow: hidden;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: 40% 60% 50% 45% / 60% 40% 60% 45%;
}

.meter i {
  position: absolute;
  inset: 0;
  background: var(--pen);
  transform-origin: left center;
  transform: scaleX(var(--fill, 0));
  transition: transform 0.45s cubic-bezier(0.3, 0.7, 0.3, 1), background-color 0.3s ease;
}

.meter[data-level="mid"] i {
  background: var(--highlighter);
}

.meter[data-level="high"] i {
  background: var(--marker);
}

.sheet-foot[data-level="high"] .size {
  color: var(--ink);
  text-decoration: underline wavy var(--marker) 2px;
  text-underline-offset: 5px;
  text-decoration-skip-ink: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 14px;
  padding: 4px 0;
}

/* 2 nhóm: công cụ nội dung bên trái, Xoá/Đóng bên phải; hết chỗ thì nhóm phải xuống dòng, vẫn dạt phải */
.actions {
  justify-content: space-between;
}

.act-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 14px;
}

.act-end {
  margin-left: auto;
}

/* ---------- Đồ trang trí dùng chung ---------- */

.tape {
  position: absolute;
  top: -15px;
  left: 50%;
  z-index: 2;
  width: 118px;
  height: 30px;
  background: var(--tape);
  transform: translateX(-50%) rotate(-3deg);
  clip-path: polygon(2% 0, 98% 4%, 100% 22%, 97% 40%, 100% 60%, 97% 80%, 99% 100%, 1% 96%, 3% 78%, 0 58%, 3% 40%, 0 20%);
  pointer-events: none;
}

.tack {
  position: absolute;
  top: -12px;
  left: 50%;
  z-index: 2;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  background: radial-gradient(circle at 35% 35%, #ff9b9b 0 22%, var(--marker) 26%);
  border: 2px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

/* ---------- Toast & hộp thoại ---------- */

/* Toast xếp chồng: mẩu note mới dán ở dưới cùng, mẩu cũ lùi lên và mờ dần, tối đa 3 */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--toast-bottom, 20px) + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  padding: 9px 16px 9px 20px;
  color: var(--ink);
  background: var(--postit);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly);
  box-shadow: var(--shadow);
  font-size: 20px;
  line-height: 1.25;
  pointer-events: auto;
  transform: rotate(-1.5deg);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast:nth-child(even) {
  transform: rotate(1deg);
}

.toast:not(:last-child) {
  opacity: 0.88;
}

.toast.out {
  opacity: 0;
  transform: translateY(10px) rotate(-4deg) scale(0.92);
}

@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.25);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(18px) rotate(-7deg);
  }
}

.toast-action {
  appearance: none;
  flex: none;
  min-height: 36px;
  padding: 4px 12px;
  color: var(--ink);
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly);
  box-shadow: var(--shadow-sm);
  font: 700 17px/1.1 var(--font-head);
  cursor: pointer;
  transition: transform var(--snap), box-shadow var(--snap), background-color var(--snap), color var(--snap);
}

.toast-action:hover {
  color: #fff;
  background: var(--pen);
}

.toast-action:active {
  box-shadow: none;
  transform: translate(2px, 2px);
}

/* Gỡ giấy che khi mở mã xem 1 lần: mẩu note bóc từ góc rồi bay lên */
.cover {
  position: absolute;
  z-index: 15;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--postit);
  border: 2px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow-md);
  font: 700 clamp(26px, 4vw, 34px)/1.1 var(--font-head);
  pointer-events: none;
  transform-origin: 6% 4%;
  animation: peel 0.75s cubic-bezier(0.55, 0, 0.75, 0.2) 0.1s forwards;
}

.cover .tape {
  top: -15px;
}

@keyframes peel {
  0% {
    transform: none;
  }
  28% {
    transform: rotate(-3deg) translateY(-8px);
    box-shadow: 10px 12px 0 0 rgb(45 45 45 / 0.35);
  }
  100% {
    opacity: 0;
    transform: translate(8%, -115%) rotate(-14deg);
    box-shadow: 18px 22px 0 0 rgb(45 45 45 / 0);
  }
}

dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 32px 26px 24px;
  overflow: visible;
  color: var(--ink);
  background: var(--sheet);
  border: 3px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgb(45 45 45 / 0.35);
}

dialog h2 {
  margin: 0 0 10px;
  font: 700 28px/1.15 var(--font-head);
}

dialog p {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 20px;
}

.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

/* ---------- Hộp Chia sẻ: QR, link, gửi qua app ---------- */

dialog.share {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 30px 24px 20px;
}

dialog.share[open] {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

dialog.share h2 {
  margin: 0;
  padding-right: 48px;
}

.share-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
}

.share-sub {
  margin: -6px 0 0;
  font-size: 18px;
}

.qr-box {
  align-self: center;
  padding: 6px;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--wobbly-md);
  box-shadow: var(--shadow-sm);
}

.qr {
  display: block;
  width: min(232px, 60vw, 38dvh);
  height: auto;
  aspect-ratio: 1;
}

.share-code {
  margin: 0;
  color: var(--pen);
  font: 700 30px/1.1 var(--font-head);
  letter-spacing: 0.08em;
  text-align: center;
}

.share-link {
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-link input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 6px 12px;
  color: var(--ink);
  background: var(--paper);
  border: 2px dashed var(--ink-faint);
  border-radius: var(--wobbly);
  font: 400 14px/1.2 var(--font-mono);
}

.share-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 40px;
  color: var(--ink-soft);
  font-size: 18px;
}

/* Dấu mộc "Thêm 1 máy vừa vào": nằm dưới QR, không bao giờ đè lên QR để khỏi cản quét */
.stamp {
  padding: 4px 12px;
  color: var(--pen);
  background: rgb(255 255 255 / 0.85);
  border: 3px double var(--pen);
  border-radius: var(--wobbly);
  font: 700 18px/1.15 var(--font-head);
  white-space: nowrap;
  transform: rotate(-6deg);
}

@media (prefers-reduced-motion: no-preference) {
  .stamp.stamp-in {
    animation: stamp-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
  }

  dialog.share[open]::backdrop {
    animation: fade-in 0.3s ease both;
  }
}

@keyframes stamp-in {
  0% {
    opacity: 0;
    transform: rotate(-22deg) scale(1.9);
  }
  60% {
    opacity: 1;
    transform: rotate(-4deg) scale(0.92);
  }
  100% {
    transform: rotate(-6deg) scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* Các nút trong hộp thoại cùng cỡ; nút chính chỉ khác màu */
.dlg-actions .btn.cta {
  min-height: 48px;
  padding: 8px 20px;
  font-size: 20px;
  box-shadow: var(--shadow);
}

.dlg-actions .btn.cta:not(:disabled):hover {
  box-shadow: var(--shadow-sm);
  transform: translate(2px, 2px);
}

.offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

/* ---------- Chuyển động ---------- */

@keyframes rock {
  0%,
  100% {
    transform: rotate(8deg);
  }
  50% {
    transform: rotate(18deg);
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-7px) rotate(-4deg);
  }
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Nét vẽ: path có pathLength="1" */
@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .icon-btn.done .ico-done path,
  .btn.done .ico-done path,
  .status.draw .st-tick path {
    stroke-dasharray: 1;
    animation: draw 0.4s ease-out both;
  }
}

/* Chuyển màn: tờ cũ trượt đi, tờ mới trượt vào như đặt thêm 1 tờ giấy */
:root[data-nav] #home {
  view-transition-name: page-home;
}

:root[data-nav] #session {
  view-transition-name: page-session;
}

::view-transition-old(page-home),
::view-transition-old(page-session) {
  animation: page-out 0.28s ease-in both;
}

::view-transition-new(page-home),
::view-transition-new(page-session) {
  animation: page-in 0.4s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

:root[data-nav="back"]::view-transition-old(page-session) {
  animation-name: page-out-back;
}

:root[data-nav="back"]::view-transition-new(page-home) {
  animation-name: page-in-back;
}

.view.enter {
  animation: page-in 0.4s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.view.enter-back {
  animation: page-in-back 0.4s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

@keyframes page-out {
  to {
    opacity: 0;
    transform: translateX(-14%) rotate(-3deg);
  }
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateX(16%) rotate(3deg);
  }
}

@keyframes page-out-back {
  to {
    opacity: 0;
    transform: translateX(14%) rotate(3deg);
  }
}

@keyframes page-in-back {
  from {
    opacity: 0;
    transform: translateX(-16%) rotate(-3deg);
  }
}

/* ---------- Màn nhỏ ---------- */

@media (max-width: 600px) {
  .shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .card {
    padding: 30px 18px 22px;
  }

  .code-note {
    padding: 28px 16px 18px;
  }

  .gate {
    margin-left: 0;
    padding: 34px 20px 24px;
  }

  .editor-wrap {
    --margin: 30px;
    --pad-r: 14px;
  }

  #s-text {
    min-height: 220px;
  }

  .status-row {
    padding-left: 16px;
    padding-right: 12px;
  }

  .sheet-foot {
    padding-left: 16px;
    padding-right: 16px;
  }

  .save-tools .btn.secondary .label-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* Hộp thoại trên điện thoại: nút xếp dọc, nút chính ở trên cùng */
  .dlg-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .act-group {
    flex: 1 1 100%;
  }

  .actions .btn {
    flex: 1 1 auto;
  }

  .e2e {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  /* Ngoại lệ: thanh tiến trình khi giữ nút xoá là phản hồi chức năng, không phải trang trí */
  .btn.hold.holding::after {
    transition: transform var(--hold, 1000ms) linear !important;
  }
}
