/* Shared site chrome. Warm paper, ink nav, burnt-orange primary action,
   teal links. Game element / quality / heatmap colors stay in tool sheets.
   System font stack, 16–20px corners, one soft shadow. */
/* Ownership: theme.css = brand tokens + shared controls.
   Tool pages own their layout in /public/<tool>/styles.css.
   Avoid bare .wrap/.panel overrides here that reshape other tools. */
:root {
  --bg: #f7f8f2;
  --panel: #ffffff;
  --panel2: #eef2f0;
  --line: #dce3e5;
  --text: #183747;
  --muted: #516674;
  --accent: #b94f2c;
  --link: #2a7180;
  --brand: #183747;
  --forest: #183747;
  --gold: #f4efe6;
  --nav-current: #f4efe6;
  --danger: #9b2c2c;
  --dim: #dce3e5;
  --header-bg: #183747;
  --header-text: #f7f8f2;
  --header-muted: #c5d2d8;
  --focus-ring: #183747;
  --focus-ring-on-dark: #f7f8f2;
  --shadow: 0 8px 24px rgba(24, 55, 71, .06);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --tool-workspace-max-width: 1632px;
  --tool-workspace-gutter: 24px;
  --tool-workspace-width: min(var(--tool-workspace-max-width), calc(100% - var(--tool-workspace-gutter) * 2));

  --space-25: 2px;
  --space-50: 4px;
  --space-75: 8px;
  --space-100: 12px;
  --space-200: 16px;
  --space-300: 24px;
  --space-400: 32px;
  --space-500: 40px;
  --space-600: 48px;
  --space-700: 64px;
  --space-800: 80px;
  --space-900: 96px;

  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-full: 9999px;

  /* Type scale: title / body / note. Numbers use tabular lining figures. */
  --text-title-size: 1.125rem;
  --text-title-leading: 1.35;
  --text-body-size: 0.9375rem;
  --text-body-leading: 1.7;
  --text-note-size: 0.8125rem;
  --text-note-leading: 1.65;
  --text-num: tabular-nums;
}

/* Foundation shared by every tool, including pages with dedicated stylesheets. */
*,
*::before,
*::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  scrollbar-gutter: stable;
  /* Shared sticky offset for header-aware docks / anchors. Measured on PET pages. */
  --site-header-offset: 96px;
  scroll-padding-top: var(--site-header-offset);
}

@media (min-width: 1024px) and (max-width: 1279px) {
  :root { --tool-workspace-gutter: 16px; }
}

@media (max-width: 760px) {
  :root { --tool-workspace-gutter: 12px; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-body-size);
  line-height: var(--text-body-leading);
  overflow-x: clip;
  overflow-wrap: anywhere;
}

.text-title {
  font-size: var(--text-title-size);
  line-height: var(--text-title-leading);
  font-weight: 600;
  color: var(--text);
}
.text-body {
  font-size: var(--text-body-size);
  line-height: var(--text-body-leading);
  color: var(--text);
}
.text-note {
  font-size: var(--text-note-size);
  line-height: var(--text-note-leading);
  color: var(--muted);
}
.num {
  font-variant-numeric: var(--text-num);
  font-feature-settings: "tnum" 1, "lnum" 1;
}

.skip-link {
  position: absolute;
  left: var(--space-200);
  top: 0;
  z-index: 100;
  padding: var(--space-75) var(--space-100);
  border-radius: var(--radius-lg);
  background: var(--forest);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  text-decoration: none;
  transform: translateY(calc(-100% - 8px));
  transition: transform 500ms var(--ease-out);
}
.skip-link:focus {
  top: var(--space-200);
  transform: translateY(0);
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Shared site header and compact navigation controls. */
body > header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-200);
  width: 100%;
  margin: 0;
  padding: var(--space-100) max(var(--tool-workspace-gutter), calc((100% - var(--tool-workspace-max-width)) / 2));
  border: 0;
  border-radius: 0;
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .18);
}

body > header .head-main {
  min-width: 0;
  flex: 1 1 auto;
}

body > header .tool-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-75);
  margin-top: var(--space-100);
}

body > header .tool-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: var(--space-50) var(--space-100);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--header-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 300ms var(--ease-out), color 300ms var(--ease-out), transform 300ms var(--ease-out);
}
body > header .tool-nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, .1);
  text-decoration: none;
}
body > header .tool-nav a:active {
  transform: scale(0.98);
}
body > header .tool-nav a:focus-visible,
body > header .lang-picker > summary:focus-visible,
body > header .home-brand:focus-visible {
  outline: 2px solid var(--focus-ring-on-dark);
  outline-offset: 2px;
}
body > header .tool-nav a[aria-current="page"] {
  background: var(--nav-current);
  border-color: var(--nav-current);
  color: var(--text);
  font-weight: 700;
}

body > header .home-header-main {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--space-100) var(--space-300);
  width: 100%;
}
body > header .home-header-main .tool-nav {
  margin-top: 0;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: var(--space-50);
  scrollbar-width: none;
}
body > header .home-header-main .tool-nav::-webkit-scrollbar { display: none; }

body > header .home-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 40px;
  gap: 0;
  flex: none;
  color: var(--header-text);
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  text-decoration: none;
}
body > header .home-brand span,
body > header .lang-picker__label {
  color: var(--header-muted);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
}

body > header .header-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-75);
  margin-left: auto;
  flex: none;
  min-height: 40px;
}

body > header .lang-picker {
  position: relative;
  flex: none;
}

body > header .lang-picker > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-75);
  min-height: 40px;
  padding: var(--space-50) var(--space-100);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .08);
  color: var(--header-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  box-shadow: none;
  transition: background-color 300ms var(--ease-out), border-color 300ms var(--ease-out);
}
body > header .lang-picker > summary::-webkit-details-marker { display: none; }
body > header .lang-picker > summary:hover,
body > header .lang-picker[open] > summary {
  border-color: rgba(255, 255, 255, .45);
  background: rgba(255, 255, 255, .14);
}
body > header .lang-picker__current { color: var(--header-text); font-weight: 600; }
body > header .lang-picker__chev {
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--header-muted);
  border-bottom: 1.5px solid var(--header-muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 300ms var(--ease-out);
}
body > header .lang-picker[open] .lang-picker__chev {
  transform: translateY(2px) rotate(225deg);
}

body > header .q.q-big {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 18px;
  line-height: 24px;
  cursor: pointer;
  color: var(--header-text);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, .08);
  transition: background-color 300ms var(--ease-out), color 300ms var(--ease-out), transform 300ms var(--ease-out);
}
body > header .q.q-big:hover {
  background: var(--nav-current);
  border-color: var(--nav-current);
  color: var(--text);
}
body > header .q.q-big:focus-visible {
  outline: 2px solid var(--focus-ring-on-dark);
  outline-offset: 2px;
}
body > header .q.q-big:active { transform: scale(0.98); }

.tool-guide {
  width: min(920px, calc(100% - 32px));
  margin: var(--space-200) auto var(--space-400);
  padding: var(--space-300) var(--space-300) var(--space-100);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  background: var(--panel);
}

.tool-guide h2 {
  margin: 0 0 var(--space-75);
  color: var(--text);
  font-size: 18px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.tool-guide p,
.tool-guide li {
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
}

.tool-guide ol,
.tool-guide .faq { margin: 0 0 var(--space-200); padding-left: 1.2em; }
.tool-guide .faq { list-style: none; padding-left: 0; }
.tool-guide .faq h3 {
  margin: 0 0 var(--space-50);
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  color: var(--text);
}
.tool-guide .faq p { margin: 0 0 var(--space-100); color: var(--muted); font-size: 14px; line-height: 20px; }

.related-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-75) var(--space-300);
  align-items: baseline;
  width: min(1120px, calc(100% - 32px));
  margin: var(--space-600) auto var(--space-500);
  padding: var(--space-300) 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.related-tools span {
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  margin-right: var(--space-50);
}
.related-tools a,
.tool-guide .related-tools a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link) 55%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color 300ms var(--ease-out);
  color: var(--link);
}
.related-tools a:hover,
.tool-guide .related-tools a:hover {
  border: 0;
  color: var(--text);
  text-decoration-color: var(--text);
}
.related-tools a:active,
.tool-guide .related-tools a:active { transform: none; }

.tool-guide .related-tools {
  width: auto;
  margin: var(--space-100) 0 var(--space-200);
  padding: var(--space-200) 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.companion-links { margin: 0 0 var(--space-50); }

/* Tool title sits under the shared bar, so the bar itself stays one row on every page. */
.page-intro {
  width: var(--tool-workspace-width);
  margin: var(--space-300) auto 0;
}
.page-intro h1 {
  margin: 0;
  color: var(--text);
  font-size: 30px;
  line-height: 36px;
  font-weight: 600;
  letter-spacing: 0;
  text-wrap: balance;
}
.page-intro p {
  margin: var(--space-50) 0 0;
  max-width: 42rem;
  color: var(--muted);
  font-size: 16px;
  line-height: 24px;
}
.page-intro + .wrap {
  margin-top: var(--space-200);
}

@media (max-width: 760px) {
  html { --site-header-offset: 120px; }

  body > header {
    top: 0;
    width: 100%;
    margin-top: 0;
    padding: var(--space-75) var(--space-100);
    align-items: flex-start;
    border-radius: 0;
  }

  body > header .head-main { flex: 1 1 100%; max-width: none; }
  body > header .header-actions {
    position: absolute;
    top: var(--space-75);
    right: var(--space-75);
    margin-left: 0;
  }

  .page-intro {
    width: calc(100% - 24px);
    margin-top: var(--space-200);
  }
  .page-intro h1 {
    font-size: 24px;
    line-height: 32px;
  }

  .home-brand { padding-right: 112px; }
  body > header .home-brand span,
  body > header .lang-picker__label { display: none; }

  body > header .tool-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    gap: var(--space-75);
    margin: 0 calc(var(--space-100) * -1);
    padding: var(--space-50) var(--space-100);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  body > header .tool-nav.is-at-end,
  body > header .tool-nav:focus-within {
    -webkit-mask-image: none;
    mask-image: none;
  }
  body > header .tool-nav .nav-scroll-end {
    flex: 0 0 32px;
    width: 32px;
    height: 1px;
  }
  body > header .tool-nav::-webkit-scrollbar { display: none; }
  body > header .home-header-main {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-75);
  }
  body > header .home-header-main .tool-nav {
    flex: none;
    width: calc(100% + var(--space-200));
    margin-left: calc(var(--space-100) * -1);
  }
  body > header .tool-nav a {
    flex: 0 0 auto;
    min-height: 40px;
  }

  button:not(.q):not(.help-x):not(.linkish):not(.ui-button) {
    min-height: 40px;
  }

  .tool-guide {
    width: auto;
    margin: var(--space-100) var(--space-100) var(--space-300);
  }
  .related-tools {
    width: auto;
    margin: var(--space-500) var(--space-200) var(--space-400);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* One ink for chrome. Tool stylesheets load first; these rules restyle
   controls, links, and result figures without touching board or element colors.
   Roles: primary = burnt-orange fill; selected = ink fill; secondary = white
   with border; danger = red outline; disabled = muted panel; focus = ink ring. */
button,
input,
select {
  font-family: inherit;
}
button:hover { border-color: var(--text); }
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
button[disabled],
button:disabled {
  opacity: 1;
  color: var(--muted);
  background: var(--panel2);
  border-color: var(--line);
  cursor: not-allowed;
}
input[type="number"],
input[type="text"],
input[type="search"],
select {
  min-height: 40px;
  border-radius: var(--radius-lg);
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--forest);
}
a { color: var(--link); }
.tool-guide a,
.notice-actions a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link) 55%, transparent);
  text-underline-offset: 3px;
}
body > header .lang-picker__menu {
  position: absolute;
  top: calc(100% + var(--space-75));
  right: 0;
  z-index: 80;
  display: grid;
  min-width: 160px;
  padding: var(--space-50);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}
body > header .lang-picker__menu a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: var(--space-75) var(--space-100);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}
body > header .lang-picker__menu a:hover { background: var(--panel2); }
body > header .lang-picker__menu a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}
body > header .lang-picker__menu a[aria-current="page"] {
  color: var(--panel);
  background: var(--text);
}
body > header .lang-picker__menu a[aria-current="page"]:focus-visible {
  outline-color: var(--focus-ring-on-dark);
}
/* Shared panel surfaces. */
.tool-guide {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
/* Shared UI components. Pages opt in with ui-* classes as they are migrated. */
.ui-button,
.ui-input,
.ui-select,
.ui-segmented,
.ui-card {
  box-sizing: border-box;
  font-family: var(--font-sans);
}

.ui-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-75);
  min-height: 44px;
  padding: var(--space-75) var(--space-200);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 300ms var(--ease-out), border-color 300ms var(--ease-out), transform 300ms var(--ease-out);
}
.ui-button:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: var(--text);
  background: var(--panel2);
}
.ui-button:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(1px);
}
.ui-button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}
.ui-button--primary:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: #9d4224;
  background: #9d4224;
}
.ui-button--danger {
  border-color: var(--danger);
  color: var(--danger);
}
.ui-button--danger:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 5%, var(--panel));
}
.ui-button:disabled,
.ui-button[aria-disabled="true"] {
  border-color: var(--line);
  background: var(--panel2);
  color: var(--muted);
  cursor: not-allowed;
}
.ui-button--icon {
  flex: none;
  width: 44px;
  padding: 0;
  border-radius: var(--radius-full);
  font-size: 24px;
}

input.ui-input,
select.ui-select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: var(--space-75) var(--space-100);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  font-variant-numeric: tabular-nums;
}
.ui-input::placeholder { color: var(--muted); }
.ui-input:disabled,
.ui-select:disabled {
  background: var(--panel2);
  color: var(--muted);
  cursor: not-allowed;
}
.ui-input[aria-invalid="true"],
.ui-select[aria-invalid="true"] { border-color: var(--danger); }
.ui-button--compact,
.ui-input.ui-input--compact,
.ui-select.ui-select--compact {
  min-height: 40px;
  padding: var(--space-75) var(--space-100);
  font-size: 14px;
  line-height: 20px;
}
.ui-button:focus-visible,
.ui-input:focus-visible,
.ui-select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
.ui-input[aria-invalid="true"]:focus-visible,
.ui-select[aria-invalid="true"]:focus-visible { outline-color: var(--danger); }

.ui-segmented {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel2);
}
.ui-segmented > .ui-button {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 14px;
  line-height: 20px;
}
.ui-segmented > .ui-button:first-child { border-radius: calc(var(--radius-lg) - 1px) 0 0 calc(var(--radius-lg) - 1px); }
.ui-segmented > .ui-button:last-child { border-radius: 0 calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0; }
.ui-segmented > .ui-button[aria-pressed="true"] {
  background: var(--text);
  color: var(--panel);
}
.ui-segmented > .ui-button[aria-pressed="true"]:hover { background: var(--text); }
.ui-segmented > .ui-button:focus-visible { outline-offset: -3px; }
.ui-segmented > .ui-button[aria-pressed="true"]:focus-visible { outline-color: var(--focus-ring-on-dark); }

.ui-card {
  padding: var(--space-200);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.ui-card--large {
  padding: var(--space-300);
  border-radius: var(--radius-2xl);
}
