/* School stationery: actual sheets, light fibers, and STI blue ink. */
:root {
  --page: #e7e2d8;
  --surface: #fffdf7;
  --surface-soft: #f3f0e7;
  --surface-hover: #eeeee6;
  --line: #d4d0c4;
  --line-strong: #a5a395;
  --timeline-line: #c5c3b8;
  --paper-cover: #faf6eb;
  --paper-cover-light: #fffdf5;
  --paper-rule: #c4bda7;
  --paper-edge: #d2ccbd;
  --paper-stack: #f6f2e8;
  --paper-fold: #ebe5d6;
  --scroll-track: #e8e4da;
  --scroll-thumb: #7d8792;
  --panel-radius: 2px;
  --panel-shadow: 0 1px 2px #35352216, 0 12px 30px #35352212;
  --control-shadow: 0 1px 2px #3535220c;
  /* Reuse a decoded tile instead of filtering noise on every paper surface. */
  --paper-grain: url("/images/paper-grain-light.webp");
}

:root[data-theme="dark"] {
  --page: #1b1f24;
  --surface: #252a30;
  --surface-soft: #2c3239;
  --surface-hover: #343d47;
  --line: #49525d;
  --line-strong: #788594;
  --timeline-line: #65727d;
  --ink: #eeeae2;
  --navy: #eeeae2;
  --muted: #bdc1c5;
  --paper-cover: #2b3035;
  --paper-cover-light: #252a30;
  --paper-rule: #616366;
  --paper-edge: #464b4f;
  --paper-stack: #292e33;
  --paper-fold: #393e43;
  --scroll-track: #252a30;
  --scroll-thumb: #7a889a;
  --panel-shadow: 0 1px 2px #00000022, 0 10px 28px #00000022;
  --control-shadow: 0 1px 2px #00000028;
  --paper-grain: url("/images/paper-grain-dark.webp");
}

:root, :root body, :root body.welcome-page {
  background-color: var(--page);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
}

/* Apply the same paper stock across the welcome page and signed-in workspaces. */
:root[data-theme] :is(
  .card, .account-card, .guide-card, .report-form-card, .reports-empty, .empty-state,
  .welcome-page .welcome, .welcome-page .welcome-auth, .welcome-page .welcome-guide,
  .welcome .journey, .detail-dialog, .detail-head, .detail-facts,
  .queue-stats, .queue-stat, .report-item, .custom-select-menu
) {
  background-color: var(--surface);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
  border-color: var(--line);
}
:root[data-theme] .welcome-copy {
  background-color: var(--paper-cover);
  background-image: var(--paper-grain), linear-gradient(135deg, var(--paper-cover-light), var(--paper-cover));
  background-repeat: repeat, no-repeat;
  background-size: 180px 180px, auto;
  border-color: var(--line);
}
:root[data-theme] :is(.poster-top, .poster-bottom) { border-color: var(--paper-rule); }
:root[data-theme] .welcome-page .welcome { box-shadow: var(--panel-shadow); }
:root[data-theme] :is(.account-card, .guide-card, .report-form-card, .success-card, .reports-list) { border-top-color: var(--blue); }
:root[data-theme] .detail-head { border-bottom-color: var(--yellow); }

/* A crisp edge and two thin backing sheets make the paper visible at a glance. */
:root[data-theme] :is(.welcome-page .welcome, .welcome-guide, .report-form-card, .account-card, .reports-list, .empty-state, .success-card) {
  position: relative;
  border-radius: 2px;
  box-shadow: 0 1px 2px #35352214, 2px 3px 0 -1px var(--paper-stack), 2px 3px 0 var(--paper-edge), 4px 6px 0 -1px var(--paper-stack), 4px 6px 0 var(--paper-edge), 0 14px 28px #35352212;
}
:root[data-theme] :is(.welcome-copy, .welcome-auth, .welcome .journey) { border-radius: 0; }
:root[data-theme] :is(.welcome-auth, .welcome-guide) { position: relative; }
:root[data-theme] :is(.welcome-auth, .welcome-guide)::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  width: 25px;
  height: 25px;
  background: linear-gradient(225deg, var(--page) 0 48%, var(--paper-edge) 49% 51%, var(--paper-fold) 52%, var(--surface) 100%);
  border-bottom-left-radius: 2px;
  pointer-events: none;
}
:root[data-theme] :is(.auth-tabs, .login-footnote, .welcome-faq details, .form-divider, .report-form-card .card-heading, .report-form-card .submit-row) { border-color: var(--line); }
@media (max-width: 760px) {
  :root[data-theme] :is(.welcome-auth, .welcome-guide)::after { width: 20px; height: 20px; }
}

/* Forms read like entries on a fresh sheet rather than glossy inset panels. */
:root[data-theme] :is(
  .field input, .field textarea, .field select, #reportFilters input, #reportFilters select,
  .moderation-box .field textarea, .custom-select-trigger
) {
  background-color: var(--surface);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
  border-color: var(--line-strong);
}
:root[data-theme] :is(.field input, .field textarea, .field select, .custom-select-trigger):focus {
  border-color: var(--blue);
}
:root[data-theme] .custom-select.is-open .custom-select-trigger { border-color: var(--blue); }
:root[data-theme] .custom-select-trigger:hover:not(:disabled) { background-color: var(--surface-soft); border-color: var(--blue); }
:root[data-theme] .custom-select-trigger:disabled { background-color: var(--surface-soft); }
:root[data-theme] .readonly-field { background: var(--paper-grain) repeat var(--surface-soft) !important; }
:root[data-theme] :is(.custom-select.is-invalid .custom-select-trigger, .custom-select-trigger[aria-invalid="true"]) { border-color: #b43835; }
:root[data-theme="dark"] :is(.custom-select.is-invalid .custom-select-trigger, .custom-select-trigger[aria-invalid="true"]) { border-color: #ef9b94; }

:root[data-theme] :is(
  .signup-summary, .identity-card, .report-form-card .identity-card, .security-state,
  .detail-progress-card, .moderation-box, .success-card .tracking-box,
  .report-form-card .upload-zone, .report-form-card .file-item,
  .evidence-link, .role-pill, .recovery-code-list li, .secret-key
) {
  background-color: var(--surface-soft);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
  border-color: var(--line);
}
:root[data-theme] :is(.identity-card, .report-form-card .identity-card, .moderation-box) { border-left-color: var(--blue); }
:root[data-theme] .report-form-card .consent { background: transparent; }
:root[data-theme] :is(.report-item:hover, .queue-stat:hover, .queue-stat[aria-pressed="true"]) { background-color: var(--surface-soft); }
:root[data-theme] .queue-stat[aria-pressed="true"] { border-bottom-color: var(--blue); }
:root[data-theme] .report-form-card .upload-zone:is(:hover, .dragging) { background-color: var(--surface-hover); border-color: var(--blue); }

:root[data-theme] .custom-select-option[aria-selected="true"] { background-color: var(--blue-soft); }
:root[data-theme] .custom-select-option:is(:hover, .is-active):not([aria-disabled="true"]) { background-color: var(--surface-hover); }
:root[data-theme] :is(.button.secondary, .icon-button, .mascot-help) {
  background-color: var(--surface);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
  border-color: var(--line-strong);
}
:root[data-theme] :is(.button.secondary, .icon-button):hover:not(:disabled) { background-color: var(--surface-hover); }
:root[data-theme] :is(.button.primary, .form-message, .emergency-card, .demo-access, .local-test-code) { background-image: var(--paper-grain); }
:root[data-theme] .mascot-help { border-bottom-color: var(--yellow); }

@media (forced-colors: active) {
  :root, :root[data-theme] { --paper-grain: none; }
  :root[data-theme] :is(.welcome-auth, .welcome-guide)::after { display: none; }
}
