/* ============================================================
   PeraturanKu — Lembaran Negara design system
   The site is the day's gazette: salmon paper, letterpress ink,
   the Republic's red as the single authority accent.
   ============================================================ */

/* ---------- Fonts (self-hosted, latin subsets) ---------- */
@font-face {
  font-family: "Libre Caslon Display";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/librecaslondisplay-400.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/sourceserif4-400.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/sourceserif4-600.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/sourceserif4-400i.woff2") format("woff2");
}
@font-face {
  font-family: "Courier Prime";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/courierprime-400.woff2") format("woff2");
}
@font-face {
  font-family: "Courier Prime";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/courierprime-700.woff2") format("woff2");
}

/* ---------- Tokens ---------- */
:root {
  /* paper — the gazette's salmon, committed */
  --paper: #f1c9a9;
  --paper-raise: #f8ddc5;
  --paper-deep: #e7b28c;

  /* ink — warm letterpress near-black */
  --ink: #1d1712;
  --ink-soft: #5d4a38;

  /* merah — the Republic's red, the authority accent */
  --merah: #a51f15;
  --merah-deep: #831710;

  /* rules and margins */
  --rule: #b98e69;
  --rule-strong: #1d1712;

  /* faces */
  --font-display: "Libre Caslon Display", Georgia, serif;
  --font-text: "Source Serif 4", Georgia, serif;
  --font-docket: "Courier Prime", "Courier New", monospace;

  /* rhythm */
  --measure: 42rem;
  --gutter: 1.25rem;
  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.375rem;
  --step-2: 1.75rem;
  --step-3: 2.375rem;
  --step-4: clamp(2.75rem, 6vw, 3.75rem);
  --step-5: clamp(3.25rem, 10vw, 6rem);
}

/* ---------- Reset and ground ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* the hidden attribute always wins over author display rules */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--step-0);
  line-height: 1.62;
  text-underline-offset: 0.22em;
}

/* browser surfaces belong to the design */
::selection {
  background: var(--merah);
  color: var(--paper-raise);
}

:focus-visible {
  outline: 2px solid var(--merah);
  outline-offset: 2px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--rule) var(--paper);
}

img, svg {
  display: inline-block;
  vertical-align: baseline;
}

a {
  color: var(--merah);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--merah-deep);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

/* ---------- Docket language (typewriter) ---------- */
.docket {
  font-family: var(--font-docket);
  font-size: 0.75rem;
  line-height: 1.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.docket b {
  font-weight: 700;
  color: var(--ink);
}

/* sentence-case docket lines (full sentences read better lowercase) */
.docket.docket--lc {
  text-transform: none;
  letter-spacing: 0.02em;
}

.docket .num {
  color: var(--merah);
  font-weight: 700;
}

/* ---------- Rules ---------- */
.rule-double {
  border-top: 3px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
  height: 4px;
}

.rule-hairline {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.7em 1.35em;
  background: var(--ink);
  color: var(--paper-raise);
  border: 1px solid var(--rule-strong);
  font-family: var(--font-docket);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background 140ms ease-out, color 140ms ease-out;
}

.btn:hover {
  background: var(--merah);
  border-color: var(--merah-deep);
  color: var(--paper-raise);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.btn .arr {
  transition: transform 140ms ease-out;
}

.btn:hover .arr {
  transform: translateX(0.25em);
}

/* ---------- Icons (authored, one stroke weight) ---------- */
.ico {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ============================================================
   Landing — the day's gazette
   ============================================================ */

.sheet {
  max-width: 74rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* masthead */
.masthead {
  padding-top: 0.75rem;
}

.masthead-strip {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}

.masthead-title {
  margin: 1.1rem 0 0.35rem;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-5);
  line-height: 1.02;
  letter-spacing: -0.015em;
}

.masthead-title .ku {
  color: var(--merah);
}

.masthead-sub {
  margin: 0 auto 1rem;
  max-width: var(--measure);
  text-align: center;
  font-style: italic;
  font-size: var(--step-0);
  color: var(--ink-soft);
}

.edition-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4em 1.5em;
  padding: 0.5rem 0;
}

/* the lead — the working question field */
.lead {
  padding: 2.5rem 0 3rem;
  display: grid;
  justify-content: center;
}

.lead-form {
  width: min(46rem, 100%);
}

.lead-headline {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-4);
  line-height: 1.08;
  text-wrap: balance;
}

.lead-note {
  margin: 0 0 1.4rem;
  color: var(--ink-soft);
  font-size: var(--step-0);
}

.lead-field {
  display: block;
  width: 100%;
  min-height: 3.4rem;
  padding: 0.85rem 0.2rem;
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--rule-strong);
  resize: none;
  font-family: var(--font-text);
  font-size: var(--step-1);
  line-height: 1.45;
  caret-color: var(--merah);
}

.lead-field, .panel-field { max-height: 18rem; overflow-y: auto; }
.lead-disclaimer { font-size: var(--step--1); color: var(--ink-soft); margin: 1rem 0 0; }

.lead-field::placeholder {
  color: var(--ink-soft);
  font-style: italic;
}

.lead-field:focus {
  border-bottom-color: var(--merah);
}

.lead-field:focus:not(:focus-visible) {
  outline: none;
}

.lead-submit {
  margin-top: 1.1rem;
}

/* sample leads — printed like specimen lines */
.samples {
  margin-top: 2.2rem;
}

.sample {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 0.75rem 0.2rem;
  font-family: var(--font-text);
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink);
  transition: color 120ms ease-out;
}

.sample:first-of-type {
  border-top: 1px solid var(--rule);
}

.sample:hover {
  color: var(--merah);
}

.sample .no {
  font-family: var(--font-docket);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--merah);
  margin-right: 0.75em;
}

/* cara kerja — gazette entries in ruled columns */
.entries {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 2.5rem;
  padding: 2.5rem 0;
}

.entry + .entry {
  border-left: 1px solid var(--rule);
  padding-left: 2.5rem;
}

.entry .no {
  font-family: var(--font-docket);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--merah);
  display: block;
  margin-bottom: 0.5rem;
}

.entry h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-2);
  line-height: 1.15;
}

.entry p {
  margin: 0;
  color: var(--ink-soft);
  font-size: var(--step-0);
}

/* worked example — a framed specimen */
.specimen {
  background: var(--paper-raise);
  border: 1px solid var(--rule);
  padding: 1.5rem;
  margin: 1.5rem 0 3rem;
}

@media (min-width: 56rem) {
  .specimen {
    padding: 2.75rem;
  }
}

.specimen-docket {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.6rem;
  margin-bottom: 1.4rem;
}

.specimen-q {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-3);
  line-height: 1.3;
  text-wrap: balance;
}

.specimen-a {
  margin: 0 0 1.6rem;
  max-width: var(--measure);
  font-size: var(--step-0);
}

.specimen-a + .sources-list {
  max-width: var(--measure);
}

/* inline citation numeral — the merah stamp */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  height: 1.5em;
  padding: 0 0.25em;
  margin: 0 0.12em;
  border: 1px solid var(--merah);
  border-radius: 50%;
  background: transparent;
  color: var(--merah);
  font-family: var(--font-docket);
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1;
  vertical-align: 0.28em;
  text-decoration: none;
  transition: background 120ms ease-out, color 120ms ease-out;
}

a.cite:hover, button.cite:hover {
  background: var(--merah);
  color: var(--paper-raise);
}

/* ---------- Source entries (shared with app) ---------- */
.source {
  border: 1px solid var(--rule);
  background: var(--paper-raise);
  padding: 1.1rem 1.25rem 1.05rem;
}

.source + .source {
  margin-top: 0.9rem;
}

.source-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.source-title {
  margin: 0;
  font-family: var(--font-text);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.35;
}

.source-docket {
  white-space: normal;
}

.source-snippet {
  margin: 0.55rem 0 0.8rem;
  color: var(--ink-soft);
  font-size: var(--step--1);
  line-height: 1.55;
}

.source-link {
  font-family: var(--font-docket);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--merah);
}

.source-link:hover {
  color: var(--merah-deep);
}

span.source-link { color: var(--ink-soft); }
.source:focus-visible { outline: 2px solid var(--merah); outline-offset: 2px; }
.source, .answer-body, .answer-head { overflow-wrap: anywhere; }

/* flash highlight when navigated from a citation */
.source:target, .source.flash {
  outline: 2px solid var(--merah);
  outline-offset: 2px;
}

/* FAQ */
.faq {
  padding: 1rem 0 3rem;
  display: grid;
  gap: 1.4rem;
}

.faq-item {
  border-top: 1px solid var(--rule);
  padding-top: 0.9rem;
}

.faq-item h2 {
  margin: 0 0 0.4rem;
  font-family: var(--font-text);
  font-weight: 600;
  font-size: var(--step-1);
  line-height: 1.3;
}

.faq-item p {
  margin: 0;
  color: var(--ink-soft);
  max-width: var(--measure);
}

/* footer */
.colophon {
  border-top: 3px solid var(--rule-strong);
  margin-top: 1rem;
  padding: 1.5rem 0 2.5rem;
}

.colophon-inner {
  display: grid;
  gap: 1rem;
  justify-items: center;
  text-align: center;
}

.colophon .disclaimer {
  max-width: var(--measure);
  margin: 0;
  font-size: var(--step--1);
  color: var(--ink-soft);
  font-style: italic;
}

/* ============================================================
   Research app — a working product in the world's clothes
   ============================================================ */

.app-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.app-header-inner {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0.85rem var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 1.45rem;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
}

.wordmark .ku {
  color: var(--merah);
}

.wordmark:hover .ku {
  color: var(--merah-deep);
}

.app-main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.75rem var(--gutter) 3rem;
}

/* search panel */
.panel {
  border: 1px solid var(--rule);
  background: var(--paper-raise);
  padding: 1.1rem 1.2rem 1rem;
}

.panel-field {
  display: block;
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.15rem;
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--rule-strong);
  resize: none;
  font-family: var(--font-text);
  font-size: var(--step-1);
  line-height: 1.45;
  caret-color: var(--merah);
}

.panel-field::placeholder {
  color: var(--ink-soft);
  font-style: italic;
}

.panel-field:focus {
  border-bottom-color: var(--merah);
}

.panel-field:focus:not(:focus-visible) {
  outline: none;
}

.panel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem 1rem;
  margin-top: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  padding: 0.32em 0.85em;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: var(--font-docket);
  font-size: 0.875rem;
  min-height: 44px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: border-color 120ms ease-out, color 120ms ease-out, background 120ms ease-out;
}

.chip:hover {
  border-color: var(--merah);
  color: var(--merah);
}

.chip[aria-pressed="true"] {
  background: var(--merah);
  border-color: var(--merah-deep);
  color: var(--paper-raise);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
}

.mode-switch button {
  padding: 0.5em 1em;
  background: transparent;
  border: 0;
  font-family: var(--font-docket);
  font-size: 0.875rem;
  min-height: 44px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: background 120ms ease-out, color 120ms ease-out;
}

.mode-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper-raise);
}

/* limit docket under the panel */
.limit-line {
  margin: 0.7rem 0 0;
}

/* results */
.results {
  margin-top: 2.25rem;
}

.answer-head {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-3);
  line-height: 1.14;
  text-wrap: balance;
}

.answer-meta {
  margin-bottom: 1.1rem;
}

.answer-body {
  margin: 0;
  font-size: var(--step-0);
  max-width: var(--measure);
}

.answer-body p {
  margin: 0 0 1em;
}

.answer-body h3,
.answer-body h4,
.answer-body h5,
.answer-body h6 {
  margin: 1.6em 0 0.55em;
  font-family: var(--font-text);
  font-size: 1.15em;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.answer-body h4,
.answer-body h5,
.answer-body h6 {
  font-size: 1em;
}

.answer-body > :first-child {
  margin-top: 0;
}

.answer-body ul,
.answer-body ol {
  margin: 0 0 1em;
  padding-inline-start: 1.5em;
}

.answer-body li {
  margin-bottom: 0.4em;
  overflow-wrap: anywhere;
}

.answer-body strong {
  font-weight: 600;
}

.answer-body > :last-child {
  margin-bottom: 0;
}

/* the type being set — streaming caret */
.typing::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.15em;
  background: var(--merah);
  vertical-align: -0.15em;
  animation: caret 1s steps(2, start) infinite;
}

@keyframes caret {
  to { visibility: hidden; }
}

/* citation numeral stamps in as they arrive */
.answer-body .cite {
  animation: stamp 260ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.answer-body.typing .cite { animation: none; }

@keyframes stamp {
  from {
    transform: scale(1.5) rotate(-6deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.answer-disclaimer {
  margin: 1.2rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
}

.sources-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  border-bottom: 3px solid var(--rule-strong);
  margin: 2.5rem 0 1.1rem;
  padding-bottom: 0.4rem;
}

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

/* margin note — system states print inline, never modal */
.margin-note {
  border-top: 1px solid var(--rule);
  margin-top: 2rem;
  padding-top: 0.9rem;
  display: grid;
  gap: 0.5rem;
}

.margin-note .msg {
  font-family: var(--font-docket);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  color: var(--merah);
}

.margin-note .msg::before {
  content: "» ";
  color: var(--ink-soft);
}

.margin-note .rec {
  margin: 0;
  color: var(--ink-soft);
  font-size: var(--step--1);
}

.retry {
  justify-self: start;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}

.retry:hover {
  background: var(--merah);
  color: var(--paper-raise);
}

/* loading line while retrieving */
.setting {
  margin: 1.5rem 0 0;
  font-family: var(--font-docket);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.setting .dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "·"; }
  50% { content: "· ·"; }
  75% { content: "· · ·"; }
}

/* app footer */
.app-footer {
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-top: 1.1rem;
}

.app-footer p {
  margin: 0;
  font-size: var(--step--1);
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- Responsive ---------- */
@media (max-width: 56rem) {
  .entries {
    grid-template-columns: 1fr;
    gap: 1.8rem;
  }

  .entry + .entry {
    border-left: 0;
    padding-left: 0;
  }
}

@media (max-width: 40rem) {
  :root {
    --gutter: 1rem;
  }

  .masthead-title {
    font-size: clamp(2.6rem, 13vw, 4rem);
  }

  .edition-line {
    gap: 0.3em 1em;
    font-size: 0.875rem;
  }

  .panel-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-actions {
    justify-content: space-between;
  }

  .mode-switch { flex: 1; }
  .mode-switch button { flex: 1; }
  .panel-actions > .btn { width: 100%; }

  .source-head {
    flex-direction: column;
    gap: 0.2rem;
  }
}

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

  .typing::after {
    display: none;
  }
}
