/* Brand tokens. Change these to retint the app. */
:root {
  --brand-blue: #053B84;
  --brand-blue-deep: #003087;
  --brand-red: #ED1B30;
  --brand-white: #FFFFFF;
  --brand-sky: #00A9E3;
  --surface-light: #F4F4F4;
  --ink-light: #232323;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
  /* Dark surfaces derived from brand-blue-deep, not a second brand color. */
  --bg: #001433;
  --surface: var(--brand-blue);
  --surface-2: var(--brand-blue-deep);
  --ink: var(--brand-white);
  --muted: var(--surface-light);
  --line: #9BB6D6;
  --header: var(--brand-blue-deep);
  --on-header: var(--brand-white);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: var(--brand-white);
  --surface: var(--surface-light);
  --surface-2: var(--brand-white);
  --ink: var(--ink-light);
  --muted: #3A3A3A;
  --line: #C4C4C4;
  --header: var(--brand-blue-deep);
  --on-header: var(--brand-white);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  min-height: 100dvh;
  padding-top: var(--safe-t);
}

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

button, .tap {
  min-height: var(--tap);
  min-width: var(--tap);
  touch-action: manipulation;
}

input, select, textarea {
  font-size: 16px;
  min-height: var(--tap);
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

textarea { min-height: 96px; }

::placeholder { color: var(--muted); opacity: 1; }

button {
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: left;
}

button.primary {
  background: var(--brand-red);
  color: var(--brand-white);
  border-color: var(--brand-red);
  font-weight: 800;
  font-size: 19px;
}

button.ghost { background: transparent; }

button.on {
  background: var(--brand-red);
  border-color: var(--brand-red);
  color: var(--brand-white);
  font-weight: 800;
}

a { color: inherit; }

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 12px 12px calc(84px + var(--safe-b));
}

.appbar {
  background: var(--header);
  color: var(--on-header);
  margin: -12px -12px 12px;
  padding: 12px 12px 10px;
  border-bottom: 4px solid var(--brand-red);
}

.wordmark {
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 14px;
  color: var(--brand-white);
  margin: 0;
}

.wordmark span {
  display: block;
  letter-spacing: 0;
  font-size: 22px;
  color: var(--brand-white);
  font-weight: 800;
}

.appbar button.ghost {
  background: transparent;
  color: var(--brand-white);
  border-color: var(--brand-white);
  font-weight: 800;
  text-align: center;
}

.toprow {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}
.toprow h1 { flex: 1; min-width: 0; }

.search {
  margin: 12px 0 8px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tools button, .result, .card {
  width: 100%;
}

.result, .card {
  display: block;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 0 0 8px;
  text-align: left;
  min-height: var(--tap);
}

.result strong, .card strong { display: block; }

.muted { color: var(--muted); }

.hot { color: var(--brand-white); font-weight: 800; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.tabs button { flex: 1 1 calc(50% - 8px); }

.rowlist { margin: 0; padding: 0; list-style: none; }

.rowlist li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.kv { margin: 0 0 10px; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0 0 8px; font-weight: 700; }

.footer-cite {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.footer-cite p { margin: 0 0 8px; word-break: break-word; }

.mtable { margin: 0 0 16px; }
.mtable h2 { font-size: 18px; }
.mrow {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}
.mrow span { display: block; color: var(--muted); font-size: 14px; }

.diagram {
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  margin: 8px 0 12px;
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: var(--header);
  border-top: 4px solid var(--brand-red);
  z-index: 5;
}

.nav button {
  background: transparent;
  color: var(--brand-white);
  border-color: transparent;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 4px;
}

.banner, .badge {
  background: var(--brand-blue-deep);
  color: var(--brand-white);
  border: 3px solid var(--brand-red);
  border-radius: 12px;
  padding: 10px;
  margin: 8px 0;
  font-weight: 800;
}

.readout {
  background: #000;
  color: var(--brand-white);
  border: 3px solid var(--brand-red);
  border-radius: 12px;
  padding: 16px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 8px 0;
}

.star {
  min-width: 48px;
  min-height: 48px;
  font-size: 22px;
  text-align: center;
}

h1 { font-size: 26px; line-height: 1.2; margin: 8px 0; }
h2 { font-size: 20px; margin: 16px 0 8px; }

.pinrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }

@media (max-width: 359px) {
  .tools { grid-template-columns: 1fr; }
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--brand-sky);
  outline-offset: 2px;
}

.badge button {
  background: var(--brand-red);
  color: var(--brand-white);
  border-color: var(--brand-red);
  font-weight: 800;
  margin-top: 8px;
}
