/* Legal and support pages: plain paper, comfortable long-form reading (SPEC §4a: no glass here but the nav). */

.legal {
  padding-block: calc(76px + var(--space-xl)) var(--space-2xl);
}

@media (min-width: 60rem) {
  .legal {
    padding-block: calc(84px + var(--space-xl)) var(--space-3xl);
  }
}

.legal__head {
  padding-bottom: var(--space-lg);
}

.legal__back {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  min-height: 44px;
  margin-inline-start: -0.15em;
  color: var(--color-ink-2);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--dur) var(--ease-out);
}

.legal__back-arrow {
  display: inline-block;
  transition: transform var(--dur) var(--ease-out);
}

/* one hover signal: the arrow leans back */
@media (hover: hover) {
  .legal__back:hover .legal__back-arrow {
    transform: translateX(-4px);
  }
}

.legal__back:active {
  transform: translateY(1px);
  transition-duration: 80ms;
}

.legal__title {
  max-width: 16em;
  margin-top: var(--space-xs);
  font-size: var(--text-3xl);
}

.legal__lead {
  max-width: 30em;
  margin-top: var(--space-sm);
  color: var(--color-ink-2);
  font-size: var(--text-md);
}

.legal__lead:is(:lang(en), :lang(vi), :lang(th)) {
  max-width: 36em;
}

.legal__updated {
  margin-top: var(--space-xs);
  color: var(--color-caption);
  font-size: var(--text-sm);
}

.legal__updated time {
  font-variant-numeric: tabular-nums;
}

.legal__layout {
  display: grid;
  gap: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: var(--rule-hair) solid var(--color-rule);
}

/* Contents. Narrow screens: a collapsed disclosure above the text. Wide screens: a sticky list on the left. */
.legal__toc {
  display: none;
}

.legal__toc-details {
  border-radius: 20px;
  background: var(--color-paper-2);
  --color-caption: var(--color-ink-2);
}

.legal__toc-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 var(--space-md);
  border-radius: 20px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--dur) var(--ease-out);
}

.legal__toc-summary::-webkit-details-marker {
  display: none;
}

/* A drawn chevron that turns when the list opens */
.legal__toc-summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--dur) var(--ease-out);
}

.legal__toc-details[open] > .legal__toc-summary::after {
  margin-top: 4px;
  transform: rotate(-135deg);
}

@media (hover: hover) {
  .legal__toc-summary:hover {
    background: color-mix(in oklch, var(--color-ink) 4%, transparent);
  }
}

.legal__toc-summary:active {
  transform: scale(0.985);
  transition-duration: 90ms;
}

.legal__toc-details > .legal__toc-list {
  padding: 0 var(--space-md) var(--space-sm);
}

.legal__toc-title {
  color: var(--color-caption);
  font-size: var(--text-sm);
  font-weight: 600;
}

.legal__toc-list {
  display: grid;
  gap: var(--space-3xs);
  margin-top: var(--space-2xs);
}

.legal__toc-list a {
  display: flex;
  padding: 0.4em 0;
  min-height: 44px;
  align-items: center;
  color: var(--color-ink);
  font-size: var(--text-sm);
  line-height: 1.45;
  text-decoration: none;
}

@media (hover: hover) {
  .legal__toc-list a:hover {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.25em;
  }
}

.legal__toc-list a:active {
  opacity: 0.7;
}

/* Wide screens: contents on the left, sticky; the text beside it, biased left, with room for tables */
@media (min-width: 64rem) {
  .legal--toc .legal__layout {
    grid-template-columns: minmax(0, 14rem) minmax(0, 52rem);
    gap: var(--space-2xl);
  }

  .legal__toc-m {
    display: none;
  }

  .legal--toc .legal__toc {
    display: block;
    align-self: start;
    position: sticky;
    top: 96px;
    max-height: calc(100dvh - 120px);
    overflow: auto;
    padding: 0 var(--space-md) 0 0;
    border-inline-end: var(--rule-hair) solid var(--color-rule);
    --color-caption: var(--color-muted);
  }

  .legal__toc-list a {
    min-height: 0;
  }
}

/* ---------- The text ---------- */

/* Text keeps its measure; tables may use the whole column */
.prose {
  min-width: 0;
  overflow-wrap: break-word;
}

.prose > :not(.table-scroll) {
  max-width: var(--measure-zh);
}

.prose:is(:lang(en), :lang(vi), :lang(th)) > :not(.table-scroll) {
  max-width: var(--measure-en);
}

.prose > * + * {
  margin-top: 1em;
}

.prose h2 {
  margin-top: var(--space-xl);
  font-size: var(--text-xl);
  scroll-margin-top: 96px;
}

.prose h3 {
  margin-top: var(--space-lg);
  font-size: var(--text-md);
  scroll-margin-top: 96px;
}

.prose > :first-child {
  margin-top: 0;
}

.prose h2 + *,
.prose h3 + * {
  margin-top: 0.6em;
}

/* Headings link to themselves; a "#" appears on hover or focus */
.legal__anchor {
  color: inherit;
  text-decoration: none;
}

.legal__anchor::after {
  content: "#";
  display: inline-block;
  margin-inline-start: 0.35em;
  color: var(--color-caption);
  font-family: var(--font-mono);
  font-size: 0.75em;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .legal__anchor:hover::after {
    opacity: 1;
  }
}

.legal__anchor:focus-visible::after {
  opacity: 1;
  transition: none;
}

.prose :target {
  scroll-margin-top: 96px;
}

.prose a:not([class]) {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}

.prose ul,
.prose ol {
  padding-inline-start: 1.4em;
}

.prose li + li {
  margin-top: 0.45em;
}

.prose li > ul,
.prose li > ol {
  margin-top: 0.45em;
}

.prose li::marker {
  color: var(--color-caption);
}

.prose ol li::marker {
  font-variant-numeric: tabular-nums;
}

.prose strong {
  font-weight: 700;
}

.prose small {
  color: var(--color-caption);
  font-size: var(--text-sm);
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--color-paper-3);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.prose blockquote {
  padding-inline-start: var(--space-sm);
  border-inline-start: 2px solid var(--color-rule);
  color: var(--color-ink-2);
}

.prose hr {
  margin-block: var(--space-xl);
  border: 0;
  border-top: var(--rule-hair) solid var(--color-rule);
}

.prose dl {
  display: grid;
  gap: 0.3em 1em;
}

.prose dt {
  font-weight: 600;
}

.prose dd + dt {
  margin-top: 0.6em;
}

/* Tables scroll inside their own box on phones; the page itself never scrolls sideways */
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: 16px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.table-scroll:focus-visible {
  outline-offset: 2px;
}

.prose table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-size: var(--text-sm);
  line-height: 1.55;
}

.prose caption {
  padding: 0.8em 1em 0;
  color: var(--color-caption);
  text-align: start;
}

.prose th,
.prose td {
  padding: 0.75em 1em;
  border-bottom: var(--rule-hair) solid var(--color-rule);
  text-align: start;
  vertical-align: top;
}

.prose thead th {
  background: var(--color-paper-2);
  font-weight: 600;
  white-space: nowrap;
}

.prose tbody tr:last-child > * {
  border-bottom: 0;
}

.prose td {
  font-variant-numeric: tabular-nums;
}

/* Row labels keep a readable width when a long second column squeezes them (e.g. 特種個人資料 on phones) */
.prose tbody td:first-child {
  min-width: 8.5em; /* six zh characters plus the cell padding */
}

/* Support page: the contact line reads as a call, not a footnote */
.prose .contact {
  padding: var(--space-sm) var(--space-md);
  border-radius: 20px;
  background: var(--color-paper-2);
  --color-caption: var(--color-ink-2);
}
