/**
 * Porphyrii — site styles.
 *
 * Every color, font size, and spacing references a --ds-* design token
 * from tokens.css. No hardcoded pigment
 * values, no hardcoded font sizes. Local custom properties (--por-*) only
 * ever COMBINE tokens (e.g. color-mix of a role color), never introduce
 * new raw values.
 */

/* ---------- self-hosted fonts (interface behavior; subsets documented in fonts/README.md) ---------- */
@font-face {
  font-family: "Cardo";
  src: url("fonts/Cardo-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cardo";
  src: url("fonts/Cardo-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cardo";
  src: url("fonts/Cardo-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- local token combinations ---------- */
:root {
  /* Card borders: highlight-border in light mode. */
  --por-border-subtle: var(--ds-color-highlight-border);
  /* Secondary-button outline: text-primary at 20% (interface behavior). */
  --por-btn-outline: color-mix(in srgb, var(--ds-color-text-primary) 20%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Dark container borders = creta 10% (interface behavior). In dark mode
       --ds-color-text-primary IS creta, so the mix is token-derived. */
    --por-border-subtle: color-mix(in srgb, var(--ds-color-text-primary) 10%, transparent);
  }
}
:root[data-theme="dark"] {
  --por-border-subtle: color-mix(in srgb, var(--ds-color-text-primary) 10%, transparent);
}

/* ---------- base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  text-autospace: normal; /* interface behavior */
}
body {
  margin: 0;
  font-family: var(--ds-font-sans-ui);
  font-size: var(--ds-text-body);
  line-height: var(--ds-leading-body);
  color: var(--ds-color-text-primary);
  background: var(--ds-color-surface-base);
  /* Safe-area for standalone PWA display (interface behavior). */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
h1, h2, h3 {
  line-height: var(--ds-leading-heading);
  margin: 0;
}
a {
  color: var(--ds-color-link);
  text-decoration: underline; /* interface behavior */
}
a:hover {
  text-decoration-thickness: 0.15em; /* raise distinguishability, never lower */
}

.app {
  max-width: var(--ds-container-wide);
  margin-inline: auto;
  padding-inline: var(--ds-space-3);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--ds-space-3);
  inset-block-start: calc(-1 * var(--ds-space-6));
  z-index: 1500; /* toast tier (tokens.json layout.z-index; not exported to CSS) */
  background: var(--ds-color-surface-raised);
  padding: var(--ds-space-2) var(--ds-space-3);
  border-radius: var(--ds-radius-sm);
}
.skip-link:focus-visible {
  inset-block-start: var(--ds-space-2);
}

/* The hidden attribute must always win over component display rules
   (.btn sets display:inline-flex, which would otherwise override the
   UA stylesheet's [hidden] display:none). */
[hidden] {
  display: none !important;
}

/* ---------- focus (interface behavior) ---------- */
:focus-visible {
  outline: 2px solid var(--ds-color-link);
  outline-offset: 2px;
  border-radius: var(--ds-radius-sm);
}

/* ---------- header ---------- */
.site-header {
  border-block-end: 1px solid var(--por-border-subtle);
  padding-block: var(--ds-space-3);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-3);
}
.wordmark {
  font-family: var(--ds-font-display);
  font-size: var(--ds-text-h2);
  color: var(--ds-color-brand-title);
  letter-spacing: 0.04em;
}
.tagline {
  margin: 0;
  font-size: var(--ds-text-small);
}

/* ---------- buttons (interface behavior) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-touch-min);
  padding: var(--ds-space-2) var(--ds-space-4);
  font-family: var(--ds-font-sans-ui);
  font-size: var(--ds-text-body);
  border-radius: var(--ds-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--ds-color-brand-title);
  color: var(--ds-color-surface-base);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ds-color-brand-title) 85%, black);
}
.btn-secondary {
  background: transparent;
  color: var(--ds-color-text-primary);
  border-color: var(--por-btn-outline);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--ds-color-text-primary);
}
.btn-icon {
  padding: var(--ds-space-2);
  min-width: var(--ds-touch-min);
}
.linklike {
  background: none;
  border: none;
  padding: var(--ds-space-2) 0;
  min-height: var(--ds-touch-min);
  font: inherit;
  font-size: var(--ds-text-small);
  color: var(--ds-color-link);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- input section ---------- */
#input-section {
  padding-block: var(--ds-space-4);
}
.input-label {
  display: block;
  font-weight: 600;
  margin-block-end: var(--ds-space-2);
}
#input-text {
  width: 100%;
  max-width: var(--ds-measure-prose);
  padding: var(--ds-space-3);
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body); /* 1.125rem ≥ 1rem — no iOS focus zoom (interface behavior) */
  line-height: var(--ds-leading-body);
  color: var(--ds-color-text-primary);
  background: var(--ds-color-surface-raised);
  border: 1px solid var(--por-border-subtle);
  border-radius: var(--ds-radius-md);
  resize: vertical;
}
.input-meta {
  max-width: var(--ds-measure-prose);
  text-align: end;
  font-size: var(--ds-text-small);
  margin-block-start: var(--ds-space-1);
}
#char-counter.over-limit {
  color: var(--ds-color-error);
  font-weight: 600;
}
.button-row {
  display: flex;
  gap: var(--ds-space-3);
  margin-block-start: var(--ds-space-3);
}
.stage-status {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-touch-min);
  margin: var(--ds-space-2) 0 0;
  font-size: var(--ds-text-small);
}
.stage-status:empty {
  display: none;
}
.spinner {
  width: 1em;
  height: 1em;
  border: 2px solid var(--por-btn-outline);
  border-block-start-color: var(--ds-color-brand-title);
  border-radius: 50%;
  animation: por-spin calc(var(--ds-dur-normal) * 4) linear infinite;
}
@keyframes por-spin {
  to { transform: rotate(360deg); }
}

/* ---------- alerts (interface behavior) ---------- */
.alerts {
  display: grid;
  gap: var(--ds-space-2);
  margin-block-start: var(--ds-space-3);
}
.alerts:empty {
  display: none;
}
.alert {
  padding: var(--ds-space-2) var(--ds-space-3);
  border-inline-start: 3px solid;
  border-radius: var(--ds-radius-sm);
  font-size: var(--ds-text-small);
}
.alert-title {
  display: block;
  font-weight: 700;
  margin-block-end: var(--ds-space-1);
}
.alert-error {
  background: color-mix(in srgb, var(--ds-color-error) 10%, transparent);
  border-inline-start-color: var(--ds-color-error);
}
.alert-error .alert-title { color: var(--ds-color-error); }
.alert-warning {
  background: color-mix(in srgb, var(--ds-color-warning) 10%, transparent);
  border-inline-start-color: var(--ds-color-warning);
}
.alert-success {
  background: color-mix(in srgb, var(--ds-color-success) 10%, transparent);
  border-inline-start-color: var(--ds-color-success);
}
.alert-success .alert-title { color: var(--ds-color-success); }
.alert .btn {
  margin-block-start: var(--ds-space-2);
  min-height: var(--ds-touch-min);
}

/* diff rows (the integrity-warning behavior) */
.diff-list {
  margin: var(--ds-space-2) 0 0;
  padding: var(--ds-space-2) var(--ds-space-3);
  list-style: none;
  background: var(--ds-color-surface-raised);
  border-radius: var(--ds-radius-sm);
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body);
  overflow-x: auto;
}
.diff-del {
  text-decoration: line-through;
  color: var(--ds-color-error);
}
.diff-add {
  color: var(--ds-color-success);
  font-weight: 600;
}
.diff-same {
  opacity: 1;
}

/* ---------- result section ---------- */
#result-section {
  padding-block: var(--ds-space-4);
}
#result-section > h2 {
  font-size: var(--ds-text-h3);
  color: var(--ds-color-section-title);
  margin-block-end: var(--ds-space-3);
}
.result-grid {
  display: grid;
  gap: var(--ds-space-4);
}
@media (min-width: 72rem) {
  .result-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    align-items: start;
  }
}
.result-side {
  display: grid;
  gap: var(--ds-space-4);
}

/* ---------- cards (interface behavior) ---------- */
.card {
  background: var(--ds-color-surface-raised);
  border: 1px solid var(--por-border-subtle);
  border-inline-start: 3px solid var(--ds-color-highlight-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3) var(--ds-space-4);
}
.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ds-space-3);
  flex-wrap: wrap;
  margin-block-end: var(--ds-space-2);
}
.card-header h3 {
  font-size: var(--ds-text-h4);
  color: var(--ds-color-section-title);
}
.card-header-side {
  display: inline-flex;
  align-items: baseline;
  gap: var(--ds-space-2);
  flex-wrap: wrap;
}
.badge {
  font-size: var(--ds-text-small);
  padding: var(--ds-space-1) var(--ds-space-2);
  border: 1px solid var(--ds-color-success);
  border-radius: var(--ds-radius-sm);
  color: var(--ds-color-text-primary);
}
.confidence-note {
  font-size: var(--ds-text-small);
  color: var(--ds-color-error);
  font-weight: 600;
}
.card-note {
  margin-block-start: var(--ds-space-3);
  font-size: var(--ds-text-small);
}
.prose-block {
  max-width: var(--ds-measure-prose);
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body);
}
.prose-block p {
  margin: 0 0 var(--ds-space-3);
}
.prose-block p:last-child {
  margin-block-end: 0;
}

/* ---------- scansion rendering (the result-rendering behavior) ---------- */
.scansion-body {
  display: grid;
  gap: var(--ds-space-3);
}
.scansion-line {
  overflow-x: auto; /* verse + marks are NOT capped at the prose measure */
  padding-block-end: var(--ds-space-1);
}
.line-no {
  font-size: var(--ds-text-small);
  margin-inline-end: var(--ds-space-2);
  user-select: none;
}
.feet {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--ds-space-2);
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body); /* never below body size (the typography rules) */
  white-space: nowrap;
}
.foot {
  display: inline-flex;
  gap: var(--ds-space-1);
  padding-inline-end: var(--ds-space-2);
  border-inline-end: 1px solid var(--por-border-subtle);
}
.foot:last-child {
  border-inline-end: none;
  padding-inline-end: 0;
}
.syl {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: var(--ds-leading-heading);
}
.syl-mark {
  /* Marks come from the classical chain (Cardo ships U+23D1/U+23D5);
     alignment is structural (per-syllable columns), not font-based. */
  font-size: var(--ds-text-body);
}
.syl.elided .syl-text {
  font-style: italic;
}
.line-note {
  margin: var(--ds-space-1) 0 0;
  font-size: var(--ds-text-small);
  color: var(--ds-color-error);
}
.prose-line {
  margin: 0;
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body);
  max-width: var(--ds-measure-prose);
}

/* ---------- recitation ---------- */
.recitation-controls {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  flex-wrap: wrap;
}
.audio-status {
  font-size: var(--ds-text-small);
}
.audio-status:empty {
  display: none;
}
.ipa-toggle {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-touch-min);
  margin-block-start: var(--ds-space-2);
  font-size: var(--ds-text-small);
  cursor: pointer;
}
.ipa-toggle input {
  width: var(--ds-space-3);
  height: var(--ds-space-3);
  accent-color: var(--ds-color-brand-title);
}
.ipa-body {
  margin-block-start: var(--ds-space-2);
  padding: var(--ds-space-2) var(--ds-space-3);
  background: var(--ds-color-surface-base);
  border-radius: var(--ds-radius-sm);
  overflow-x: auto;
}
.ipa-line {
  margin: 0 0 var(--ds-space-1);
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body);
  white-space: nowrap;
}
.ipa-line:last-child {
  margin-block-end: 0;
}

/* ---------- history ---------- */
#history-section {
  padding-block: var(--ds-space-4);
}
#history-details summary {
  cursor: pointer;
  font-size: var(--ds-text-h4);
  font-weight: 600;
  min-height: var(--ds-touch-min);
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.history-count {
  font-size: var(--ds-text-small);
  font-weight: 400;
}
.history-hint {
  font-size: var(--ds-text-small);
  margin: var(--ds-space-1) 0 var(--ds-space-2);
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--ds-space-2);
}
.history-item {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  background: var(--ds-color-surface-raised);
  border: 1px solid var(--por-border-subtle);
  border-inline-start: 3px solid var(--ds-color-highlight-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-2) var(--ds-space-3);
}
.history-open {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  padding: var(--ds-space-1) 0;
  min-height: var(--ds-touch-min);
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
}
.history-snippet {
  display: block;
  font-family: var(--ds-font-serif-classical);
  font-size: var(--ds-text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  display: block;
  font-size: var(--ds-text-small);
}
.history-empty {
  font-size: var(--ds-text-small);
}

/* ---------- footer ---------- */
.site-footer {
  border-block-start: 1px solid var(--por-border-subtle);
  padding-block: var(--ds-space-3);
  margin-block-start: var(--ds-space-4);
}
.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-3);
  flex-wrap: wrap;
  font-size: var(--ds-text-small);
}

/* ---------- about overlay ---------- */
.about-view {
  position: fixed;
  inset: 0;
  z-index: 1000; /* modal tier (tokens.json layout.z-index; not exported to CSS) */
  background: var(--ds-color-surface-base);
  overflow-y: auto;
}
.about-panel {
  max-width: var(--ds-container-prose);
  margin-inline: auto;
  padding: var(--ds-space-4) var(--ds-space-3) var(--ds-space-6);
}
.about-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-3);
  margin-block-end: var(--ds-space-3);
}
.about-header h2 {
  font-size: var(--ds-text-h2);
  color: var(--ds-color-section-title);
}
.about-body h3 {
  font-size: var(--ds-text-h4);
  color: var(--ds-color-section-title);
  margin-block: var(--ds-space-4) var(--ds-space-2);
}
.about-body p {
  max-width: var(--ds-measure-prose);
  margin: 0 0 var(--ds-space-3);
}

/* ---------- misc ---------- */
.turnstile-container {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  inset-block-end: 0;
  inset-inline-end: 0;
}
.noscript-note {
  padding: var(--ds-space-3);
  text-align: center;
  color: var(--ds-color-error);
}
.offline-banner {
  padding: var(--ds-space-2) var(--ds-space-3);
  background: color-mix(in srgb, var(--ds-color-warning) 10%, transparent);
  border-inline-start: 3px solid var(--ds-color-warning);
  font-size: var(--ds-text-small);
  text-align: center;
}

/* ---------- reduced motion (interface behavior) ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner {
    animation: none;
    border-block-start-color: var(--ds-color-text-primary);
  }
}
