/*
===============================================================================
 sitelen-pona/styles.css
-------------------------------------------------------------------------------
 Purpose
 - Define fonts and global theming (dark by default, optional light theme)
 - Enable the OpenType features needed by nasin‑nanpa so Latin input shapes
   into sitelen pona glyphs
 - Lay out the page UI, input form, and output preview
 - Style .tp spans (sitelen tokens) and .tp.cartouche (cartouche brackets live
   in UCSUR PUA so we keep a UCSUR fallback available)

 Notes for future maintainers
 - The whole site uses "NasinNanpa" globally so sitelen pona is visible in UI.
 - The output preview also prefers "NasinNanpa" and has "NasinNanpaUCSUR" as a
   fallback so the special cartouche brackets render.
 - The textarea is intentionally set to resize vertically and scroll internally.
   The surrounding card is allowed to grow; overflow is visible for the form card
   to avoid clipping the browser's resize handle.
===============================================================================
*/

@font-face {
  font-family: "NasinNanpa";
  src: url("nasin-nanpa-4.0.2.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "NasinNanpaUCSUR";
  src: url("nasin-nanpa-4.0.2-UCSUR.otf") format("opentype");
  font-display: swap;
}

:root {
  --bg: #0b0c10;
  --surface: #12141a;
  --text: #e6e8ee;
  --muted: #a9b1c3;
  --primary: #7dc4e4;
  --accent: #8bd5ca;
  --border: #1e2230;
  --ring: #2b3345;
  color-scheme: dark light;
}

/* light theme variables */
.theme-light {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #12141a;
  --muted: #586070;
  --primary: #0d74ce;
  --accent: #0aa394;
  --border: #e6e9ef;
  --ring: #dfe3ea;
}

/* default is dark; user can toggle to light with .theme-light */

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  /* Use nasin‑nanpa for the site UI so sitelen pona is visible globally */
  font-family: "NasinNanpa", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* Enable OpenType features globally so nasin‑nanpa substitutions work everywhere */
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

/* Ensure all native form controls use nasin‑nanpa and shape correctly */
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  /* Some browsers keep native UI styling that can ignore custom fonts/features */
  -webkit-appearance: none;
  appearance: none;
  /* Inherit base metrics, then explicitly set our font family */
  font: inherit;
  font-family: "NasinNanpa", inherit;
  /* Enable OpenType features for sitelen pona shaping */
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
  text-rendering: optimizeLegibility;
}

/* Make sure selects also use nasin‑nanpa consistently */
select {
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  font-family: "NasinNanpa", inherit;
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
  text-rendering: optimizeLegibility;
}

.site-header, .site-footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* Ensure theme toggle button uses nasin‑nanpa and shapes like other buttons */
  font-family: "NasinNanpa", inherit;
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

.explain p {
  margin: 0 0 1rem 0;
  color: var(--muted);
  /* make explanation easier to read: increase size by ~2pt */
  font-size: 14pt;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  margin-top: 1rem;
  box-shadow: 0 1px 0 var(--ring) inset, 0 8px 24px rgba(0,0,0,0.15);
  /* ensure content doesn't visually spill outside rounded corners */
  overflow: hidden;
}

/* Allow the input card to grow and expose the textarea's native resize handle */
form.card {
  overflow: visible;
}

.label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.5rem 0;
}

.input-row {
  display: flex;
  gap: 0.5rem;
  flex-direction: column;
}

input[type="text"],
textarea {
  flex: 1;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  outline: none;
}

/* Allow only vertical resizing for the multiline textbox */
textarea {
  /* As a flex item, let it size itself so manual vertical resize works reliably */
  flex: 0 0 auto;
  display: block;
  resize: vertical; /* enable vertical resize, disable horizontal */
  overflow: auto; /* allow internal scrolling; keep manual resize */
  width: 100%;
  max-width: 100%;
}

/* Extra breathing room so the resize handle isn't obstructed by the button */
.input-row textarea {
  margin-bottom: 0.25rem;
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 20%, transparent);
}

.submit {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 35%, transparent), transparent);
  color: var(--text);
  cursor: pointer;
}

.submit:hover {
  border-color: var(--primary);
}

.output .preview {
  font-size: 2.25rem;
  line-height: 1.2;
  padding: 0.25rem 0.75rem 0.5rem;
  white-space: pre-wrap; /* preserve newlines for multiline text */
  /* keep long content inside card */
  max-width: 100%;
  overflow: auto;
  word-break: normal;
  overflow-wrap: break-word; /* only break very long words when necessary */
}

/* Place the submit button at the end when stacked */
.input-row .submit { align-self: flex-end; }

.site-footer p { color: var(--muted); margin: 1.5rem 0 0; }

/* Controls above the output preview */
.output-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.5rem 0;
}
.output-controls .controls-left {
  display: flex;
  gap: 0.5rem;
}
.output-controls .action {
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 25%, transparent), transparent);
  color: var(--text);
  cursor: pointer;
  font-family: "NasinNanpa", inherit; /* ensure button texts use nasin‑nanpa */
  /* enable sitelen pona shaping on controls, some browsers do not inherit */
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}
.output-controls .action:hover {
  border-color: var(--accent);
}
.output-controls .scheme {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
}
.output-controls select {
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: "NasinNanpa", inherit;
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

/* ensure submit button also shapes as sitelen pona */
.submit {
  font-family: "NasinNanpa", inherit;
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

/* Only Toki Pona tokens use the sitelen font */
.tp {
  font-family: "NasinNanpa", inherit;
  /* Enable OpenType features used by nasin‑nanpa to substitute Latin input
     with sitelen pona glyphs. */
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

/* In the output preview, use the UCSUR variant for sitelen tokens */
.output .tp {
  /* Prefer the regular nasin‑nanpa font to ensure visible sitelen pona glyphs;
     UCSUR remains as a fallback if supported by the system. */
  font-family: "NasinNanpa", "NasinNanpaUCSUR", inherit;
  /* Ensure the same OpenType features are active in the output */
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
  font-feature-settings: "liga" 1, "dlig" 1, "calt" 1, "ss01" 1, "ss02" 1;
}

/* Cartouches contain special UCSUR bracket codepoints. Keeping NasinNanpa first
   ensures Latin → sitelen substitutions still apply to the words inside the
   cartouche, while the PUA brackets (U+F1990/1) will automatically fall back
   to the UCSUR font. */
.output .tp.cartouche {
  font-family: "NasinNanpa", "NasinNanpaUCSUR", inherit;
}
