/*
 * Bliss translator: page styles.
 *
 * Paper and ink, one accent, system type, hairline rules. No web fonts,
 * shadows, gradients or motion. Tokens follow the Drummer write-ups so the
 * pages read as one family. The API docs page (docs.html) uses this file too.
 *
 * Themes: display.js sets data-scheme (light | dark), data-contrast
 * (standard | more), data-text and data-symbols on <html>. Every text pair
 * below is at least 4.5:1 and every control edge at least 3:1 in each theme.
 * Sizes are in rem so they follow the browser's text-size setting.
 *
 * Author: Luke Steuber
 * License: MIT
 */

:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --paper: #fffefa;
  --ink: #222b2c;
  --muted: #4f5c5d;
  --line: #ced4d1; /* hairlines between sections */
  --edge: #6f7b7a; /* edges of controls and symbol tiles (3:1 or more) */
  --accent: #775518;
  --tint: #eee6d5;
  --select: #e4e8e3;
  --danger: #9a3027;
  --backdrop: rgb(34 43 44 / 0.5);
  --symbol-ink: none; /* filter for Bliss drawings (black lines) */
  --plate: transparent; /* behind color pictograms */
  --symbol: 6.5rem;
  --caption: 0.9375rem;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Without display.js, still follow the system's dark setting. */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme]) {
    color-scheme: dark;
    --bg: #171a19;
    --paper: #202423;
    --ink: #ecebe5;
    --muted: #b3bcb9;
    --line: #3a413f;
    --edge: #87928f;
    --accent: #e0b462;
    --tint: #2e2a22;
    --select: #2c3532;
    --danger: #ff8f80;
  }
}

:root[data-scheme="dark"] {
  color-scheme: dark;
  --bg: #171a19;
  --paper: #202423;
  --ink: #ecebe5;
  --muted: #b3bcb9;
  --line: #3a413f;
  --edge: #87928f;
  --accent: #e0b462;
  --tint: #2e2a22;
  --select: #2c3532;
  --danger: #ff8f80;
  --backdrop: rgb(0 0 0 / 0.6);
  --symbol-ink: invert(0.93); /* black lines become light ink */
  --plate: #fffefa;
}

:root[data-contrast="more"] {
  --bg: #ffffff;
  --paper: #ffffff;
  --ink: #000000;
  --muted: #1c1c1c;
  --line: #000000;
  --edge: #000000;
  --accent: #5c3d00;
  --tint: #f3ead3;
  --select: #dde4de;
  --danger: #8a1c12;
}

:root[data-scheme="dark"][data-contrast="more"] {
  --bg: #000000;
  --paper: #000000;
  --ink: #ffffff;
  --muted: #ebebeb;
  --line: #ffffff;
  --edge: #ffffff;
  --accent: #ffd27a;
  --tint: #2b2414;
  --select: #1f2e29;
  --danger: #ffb0a6;
  --symbol-ink: invert(1);
  --plate: #ffffff;
}

:root[data-text="125"] {
  font-size: 125%;
}

:root[data-text="150"] {
  font-size: 150%;
}

:root[data-symbols="large"] {
  --symbol: 8.5rem;
  --caption: 1.0625rem;
}

:root[data-symbols="largest"] {
  --symbol: 11rem;
  --caption: 1.25rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.6;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 0.25em;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -100px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--edge);
  z-index: 5;
}

.skip:focus {
  top: 12px;
}

/* ---------------------------------------------------------------------------
   Page frame
   --------------------------------------------------------------------------- */

.site-header,
main,
footer {
  width: min(60rem, 100% - 32px);
  margin: 0 auto;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--line);
}

.site-header h1 {
  margin-right: auto;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.site-header h1 a {
  color: inherit;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 20px;
  font-size: 0.9375rem;
}

.site-nav a {
  display: inline-block;
  padding: 10px 0;
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--ink);
  text-decoration: underline;
}

button.display-toggle {
  font-size: 0.9375rem;
}

button.display-toggle[aria-expanded="true"] {
  background: var(--select);
  border-color: var(--ink);
}

.display-panel {
  flex-basis: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 8px 24px;
  padding: 12px 0 4px;
  border-top: 1px solid var(--line);
}

.display-panel fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.display-panel legend {
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 650;
}

.display-panel label,
.shortcut-setting label {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  margin: 0;
  font-size: 1rem;
  color: var(--ink);
}

.display-panel .hint,
.display-panel .actions {
  grid-column: 1 / -1;
  margin-top: 0;
}

.intro-section {
  padding-top: 32px;
}

/* .intro is the docs page's opening block. */
.intro {
  margin: 32px 0 8px;
}

.intro-section > h2,
.intro h2 {
  font-size: clamp(1.625rem, 4vw, 2.25rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 550;
}

.lede,
.intro p {
  margin-top: 10px;
  max-width: 62ch;
  color: var(--muted);
}

main > section {
  padding: 32px 0;
}

main > section + section {
  border-top: 1px solid var(--line);
}

main > section > h2 {
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-note {
  margin-top: 4px;
  color: var(--muted);
  max-width: 62ch;
}

footer {
  padding: 24px 0 48px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

footer p + p {
  margin-top: 8px;
}

/* ---------------------------------------------------------------------------
   Controls
   --------------------------------------------------------------------------- */

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

button,
a,
summary,
select {
  touch-action: manipulation;
}

button {
  cursor: pointer;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: transparent;
}

button:hover:enabled {
  background: var(--tint);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
  font-weight: 650;
}

button.primary:hover:enabled {
  background: var(--ink);
  border-color: var(--ink);
}

button.quiet,
.link-button {
  border: 0;
  padding-left: 0;
  padding-right: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

button.quiet:hover:enabled,
.link-button:hover:enabled {
  background: transparent;
  color: var(--ink);
}

label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.875rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: var(--paper);
}

input[type="checkbox"],
input[type="radio"] {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.hint {
  margin-top: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}

kbd {
  padding: 1px 5px;
  font: 0.8125rem ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--paper);
}

pre,
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.5;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.status {
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--muted);
}

.status:empty {
  margin-top: 0;
}

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

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

.form-grid {
  display: grid;
  gap: 12px 24px;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.form-stack {
  display: grid;
  gap: 14px;
}

/* ---------------------------------------------------------------------------
   Translator
   --------------------------------------------------------------------------- */

.translate-form {
  margin-top: 20px;
  display: grid;
  gap: 16px;
}

.translate-input textarea {
  min-height: 6rem;
  font-size: 1.125rem;
  line-height: 1.5;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0 18px;
  align-items: baseline;
  margin-top: 4px;
  font-size: 0.9375rem;
}

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

.examples button {
  min-height: 44px;
  padding: 0;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-align: left;
}

.examples button:hover:enabled {
  background: transparent;
  color: var(--ink);
}

.translate-options {
  margin: 0;
  padding: 0;
  border: 0;
}

.translate-options legend {
  padding: 0;
  margin-bottom: 4px;
  font-size: 0.875rem;
  color: var(--muted);
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 24px;
}

.option-row label {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ink);
}

.style-options {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.style-options summary,
.translate-notes summary,
.search-settings summary {
  display: list-item;
  padding: 10px 0;
  cursor: pointer;
  font-size: 0.9375rem;
}

.style-grid {
  display: grid;
  gap: 12px 24px;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  padding: 4px 0 12px;
}

.style-grid .hint {
  margin-top: 2px;
  font-size: 0.8125rem;
}

/* Result strips */

.translate-results {
  display: grid;
  gap: 24px;
  margin-top: 20px;
}

.bliss-source {
  margin-bottom: 8px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.bliss-strip {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.bliss-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 4.75rem;
  padding: 10px 8px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.bliss-unit.is-marker {
  background: transparent;
}

/* Low confidence: a dashed edge as well as the badge text, not color alone. */
.bliss-unit.is-uncertain {
  border: 2px dashed var(--accent);
}

/* The symbol being read aloud. */
.bliss-unit.is-speaking {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  background: var(--tint);
}

.bliss-figure {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  height: var(--symbol);
}

.bliss-figure img {
  height: var(--symbol);
  width: auto;
  filter: var(--symbol-ink);
}

.bliss-text {
  display: flex;
  align-items: center;
  height: var(--symbol);
  padding: 0 6px;
  font-size: calc(var(--caption) * 1.2);
  font-weight: 600;
}

.bliss-caption {
  font-size: var(--caption);
  font-weight: 600;
  text-align: center;
  max-width: 14ch;
  overflow-wrap: anywhere;
}

.bliss-badge {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  max-width: 16ch;
}

.is-uncertain .bliss-badge {
  color: var(--accent);
  font-weight: 600;
}

button.bliss-change {
  margin-top: auto;
  min-width: 44px;
  padding: 0 8px;
  border: 0;
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

button.bliss-change:hover:enabled {
  background: transparent;
  color: var(--ink);
}

button.bliss-change[aria-expanded="true"] {
  color: var(--ink);
  text-decoration-thickness: 2px;
}

/* Symbol editor */

.translate-editor {
  display: grid;
  gap: 14px;
  margin-top: 20px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 4px;
}

.translate-editor h3 {
  font-size: 1.0625rem;
}

.editor-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-options .hint {
  flex-basis: 100%;
}

button.editor-option {
  display: grid;
  justify-items: center;
  gap: 4px;
  max-width: 10rem;
  padding: 8px;
  border-radius: 4px;
  font-size: 0.8125rem;
  text-align: center;
}

button.editor-option img {
  height: calc(var(--symbol) * 0.7);
  width: auto;
  filter: var(--symbol-ink);
}

button.editor-option span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

button.editor-option[aria-pressed="true"] {
  border: 3px solid var(--ink);
  background: var(--select);
  font-weight: 650;
}

.editor-count {
  flex-basis: 100%;
}

.editor-lookup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-lookup-row input {
  flex: 1 1 10rem;
  min-width: 0;
  width: auto;
}

.editor-indicator select {
  width: auto;
  min-width: 14rem;
  max-width: 100%;
}

.translate-exports {
  margin-top: 20px;
}

#export-speak.is-reading {
  background: var(--select);
  border: 3px solid var(--ink);
  font-weight: 650;
}

.translate-notes {
  margin-top: 16px;
  font-size: 0.9375rem;
  border-top: 1px solid var(--line);
}

.translate-notes ul {
  margin: 4px 0 8px;
  padding-left: 20px;
}

/* ---------------------------------------------------------------------------
   Symbol search
   --------------------------------------------------------------------------- */

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-top: 16px;
}

.search-row > div {
  flex: 1 1 16rem;
}

.search-settings {
  margin-top: 8px;
}

.search-settings summary {
  color: var(--muted);
}

.search-settings .form-grid {
  padding-bottom: 8px;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 24px;
  margin: 0;
  padding: 0;
  border: 0;
}

.checkbox-row label {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  margin: 0;
  color: var(--ink);
}

.history-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 8px;
}

.history-pill {
  min-height: 44px;
  padding: 0;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.history-pill:hover:enabled {
  background: transparent;
  color: var(--ink);
}

.results-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(11.25rem, 1fr));
  margin-top: 16px;
}

.result-card {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* Color pictograms keep a light plate in dark mode. */
.result-card img,
#preview-content img {
  background: var(--plate);
  border-radius: 4px;
}

.result-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  padding: 4px;
  cursor: pointer;
}

.result-card h3 {
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.result-meta {
  font-size: 0.8125rem;
  color: var(--muted);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.875rem;
}

.result-actions a,
.result-actions button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.result-actions button:hover:enabled {
  background: transparent;
  color: var(--ink);
}

.empty-state {
  padding: 16px 0;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Dialogs (native <dialog>: the page behind is inert while one is open)
   --------------------------------------------------------------------------- */

dialog.modal {
  width: min(35rem, 100% - 32px);
  max-height: calc(100% - 32px);
  padding: 0;
  overflow: auto;
  /* Keep a focused control from scrolling under the sticky header. */
  scroll-padding-top: 5rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 6px;
}

dialog.modal.modal-wide {
  width: min(51rem, 100% - 32px);
}

dialog.modal::backdrop {
  background: var(--backdrop);
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: 1.125rem;
}

.modal-close {
  flex: none;
  min-width: 44px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  border: 0;
}

.modal-body {
  padding: 16px;
}

.shortcuts-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0;
}

.shortcuts-list dd {
  margin: 0;
  color: var(--muted);
}

.shortcut-setting {
  margin-top: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

#preview-content {
  display: grid;
  gap: 16px;
}

#preview-content img {
  display: block;
  width: 100%;
  max-width: 20rem;
  margin: 0 auto;
  padding: 8px;
}

#preview-content .preview-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0;
}

#preview-content .preview-meta dt {
  color: var(--muted);
}

#preview-content .preview-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------------
   Windows high contrast and other forced-color modes
   --------------------------------------------------------------------------- */

@media (forced-colors: active) {
  /* Symbols are black line drawings or color pictures: keep them on white
     so they stay visible on any system background. */
  .bliss-figure img,
  button.editor-option img,
  .result-card img,
  #preview-content img,
  .board-cell__image,
  .cell-result img {
    forced-color-adjust: none;
    filter: none;
    background: #ffffff;
  }

  :focus-visible {
    outline-color: Highlight;
  }

  button[aria-pressed="true"],
  button.display-toggle[aria-expanded="true"] {
    border: 3px solid Highlight;
  }

  .bliss-unit.is-speaking {
    outline-color: Highlight;
  }

  .bliss-unit.is-uncertain {
    border-color: CanvasText;
  }
}

/* ---------------------------------------------------------------------------
   Print: black on white whatever the theme, without the page's controls
   --------------------------------------------------------------------------- */

@media print {
  :root,
  :root[data-scheme],
  :root[data-contrast] {
    color-scheme: light;
    --bg: #ffffff;
    --paper: #ffffff;
    --ink: #000000;
    --muted: #000000;
    --line: #999999;
    --edge: #666666;
    --accent: #000000;
    --tint: #ffffff;
    --select: #ffffff;
    --symbol-ink: none;
    --plate: transparent;
  }

  .skip,
  .site-nav,
  .display-toggle,
  .display-panel,
  .translate-form,
  .bliss-change,
  .translate-editor,
  .translate-exports,
  .translate-notes,
  #symbols,
  .board-controls,
  .board-title-field,
  .board-grid-controls,
  #board-hint,
  .board-feedback,
  .board-cell__clear,
  footer .link-button {
    display: none !important;
  }
}

/* ---------------------------------------------------------------------------
   Small screens
   --------------------------------------------------------------------------- */

@media (max-width: 640px) {
  :root {
    --symbol: 5rem;
  }

  :root[data-symbols="large"] {
    --symbol: 6.5rem;
  }

  :root[data-symbols="largest"] {
    --symbol: 8.5rem;
  }

  .intro-section {
    padding-top: 24px;
  }

  main > section {
    padding: 24px 0;
  }

  .bliss-unit {
    min-width: 4rem;
  }

  .editor-indicator select {
    width: 100%;
    min-width: 0;
  }
}
