/* The Midland Gate — paper & ink, hi-vis highlighter */
:root {
  --bg: #f6f3ea;
  --surface: #fffdf7;
  --ink: #141414;
  --ink-2: #3d3b36;
  --muted: #77736a;
  --line: #e4dfd2;
  --line-2: #d3cdbd;
  --hi: #ffd400;
  --mark: #ffe14d;
  --mark-ink: #141414;
  --plain: #141414;
  --shadow: 0 1px 2px #0000000a, 0 8px 24px #0000000d;
  --display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  --body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --c-perth: #c99700;
  --c-aus: #2f9e5b;
  --c-eshay: #dc4a2c;
  --c-noongar: #b05f2a;
  --c-net: #7b52e8;
  --c-uk: #2a74d6;
  --tabbar-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1b1b19;
    --ink: #f3f0e7;
    --ink-2: #cfcabd;
    --muted: #8e897d;
    --line: #2a2926;
    --line-2: #3a3833;
    --mark: #ffd400;
    --mark-ink: #141414;
    --shadow: 0 1px 2px #0006, 0 8px 24px #0004;
    --c-perth: #ffd400;
    --c-aus: #5ccf8a;
    --c-eshay: #ff7457;
    --c-noongar: #e8925a;
    --c-net: #b39bff;
    --c-uk: #6bb3ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 var(--body); }
body { min-height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); font-size: .85rem; }

/* ---------- Header ---------- */
.top { background: var(--bg); }
.stripe { height: 6px; background: repeating-linear-gradient(-45deg, var(--hi) 0 10px, #141414 10px 20px); }
.top-inner { max-width: 720px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) 20px 0; }
.stripe + .top-inner { padding-top: 22px; }
.brand { display: flex; align-items: center; gap: 12px; }
.mark { width: 34px; height: 34px; border-radius: 9px; flex: none; background:
    linear-gradient(var(--ink), var(--ink)) 50% 100% / 10px 14px no-repeat,
    repeating-linear-gradient(-45deg, var(--hi) 0 6px, #141414 6px 12px); border: 2px solid #141414; }
h1 { margin: 0; font: 800 1.7rem/1 var(--display); letter-spacing: -.02em; }
h1 span { font-weight: 600; color: var(--muted); }
.tag { margin: 8px 0 0; color: var(--muted); font-size: .95rem; }

.tabs { display: flex; gap: 24px; margin-top: 18px; border-bottom: 1px solid var(--line); }
.tab { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 10px 0 12px; color: var(--muted); font-weight: 600; cursor: pointer; position: relative; }
.tab svg { width: 18px; height: 18px; }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--hi); }

/* ---------- Layout ---------- */
main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 20px 20px calc(32px + var(--tabbar-h)); }
.view { display: none; }
.view.active { display: block; }

.label { display: block; font: 600 .78rem/1 var(--body); letter-spacing: .02em; color: var(--muted); }
.section-title { font: 800 1.15rem/1.2 var(--display); letter-spacing: -.01em; margin: 32px 0 6px; }

/* ---------- Translator ---------- */
.translator { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.pane { padding: 16px 18px; }
.pane-out { border-top: 1px dashed var(--line-2); background: linear-gradient(var(--surface), var(--surface)); }
.pane-head { display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
textarea { display: block; width: 100%; margin-top: 8px; padding: 0; border: 0; background: transparent; color: var(--ink); font: 500 1.2rem/1.45 var(--body); resize: none; min-height: 3.2em; }
textarea:focus { outline: none; }
textarea::placeholder { color: var(--muted); opacity: .7; }
.pane-in:focus-within { box-shadow: inset 3px 0 0 var(--hi); }
.row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.count { margin-left: auto; color: var(--muted); font-size: .78rem; }

.btn { background: transparent; border: 1px solid var(--line-2); border-radius: 999px; padding: 5px 12px; font-size: .85rem; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; }
#copy:not(:disabled) { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.output { margin: 8px 0 2px; font: 600 1.35rem/1.5 var(--body); white-space: pre-wrap; overflow-wrap: anywhere; }
.output.empty { font-weight: 400; font-size: 1rem; color: var(--muted); }
.hit { background: var(--mark); color: var(--mark-ink); padding: .04em .22em; margin: 0 -.06em; border-radius: .3em; box-decoration-break: clone; -webkit-box-decoration-break: clone; cursor: pointer; }
.hit:hover { filter: brightness(.95); }
.hit.maybe { background: none; color: inherit; padding: 0; margin: 0; text-decoration: underline dotted var(--muted) 2px; text-underline-offset: 5px; }

/* ---------- Term lists ---------- */
.terms { list-style: none; margin: 0; padding: 0; }
.term-row { display: block; padding: 14px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.term-row:last-child { border-bottom: 0; }
.term-row:hover .term { text-decoration: underline; text-decoration-color: var(--hi); text-decoration-thickness: 3px; text-underline-offset: 3px; }
.term-line { display: flex; align-items: baseline; gap: 8px; }
.term-words { flex: 1; min-width: 0; }
.term { font: 800 1.08rem/1.25 var(--display); letter-spacing: -.01em; }
.arrow { color: var(--muted); margin: 0 4px; font-size: .9rem; }
.plain { font-weight: 600; color: var(--ink-2); }
.meaning { display: block; margin-top: 3px; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.region-chip { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.region-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--rc, var(--muted)); }
.empty-row { list-style: none; color: var(--muted); padding: 14px 0; }

[data-region=perth]   { --rc: var(--c-perth); }
[data-region=aus]     { --rc: var(--c-aus); }
[data-region=eshay]   { --rc: var(--c-eshay); }
[data-region=noongar] { --rc: var(--c-noongar); }
[data-region=net]     { --rc: var(--c-net); }
[data-region=uk]      { --rc: var(--c-uk); }

.explain .section-title { margin-top: 28px; }

/* ---------- Word of the day + samples: only before you type ---------- */
body.has-text .wotd, body.has-text .samples { display: none; }
.wotd { margin-top: 28px; padding: 18px 18px 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); cursor: pointer; position: relative; overflow: hidden; }
.wotd::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: repeating-linear-gradient(-45deg, var(--hi) 0 6px, #141414 6px 12px); }
.wotd .k { font-size: .78rem; font-weight: 600; color: var(--muted); }
.wotd .w { font: 800 1.9rem/1.05 var(--display); letter-spacing: -.02em; margin: 6px 0 4px; }
.wotd .p { font-weight: 600; color: var(--ink-2); }
.wotd .e { margin-top: 8px; color: var(--muted); font-style: italic; }

.samples .section-title { margin-bottom: 4px; }
.sample-list { display: block; }
.sample { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 13px 2px; color: var(--ink-2); font-size: 1rem; cursor: pointer; }
.sample:last-child { border-bottom: 0; }
.sample::after { content: " →"; color: var(--muted); }
.sample:hover { color: var(--ink); }

/* ---------- Glossary ---------- */
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
input[type=search] { width: 100%; padding: 12px 14px 12px 42px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; font: 500 1rem/1.4 var(--body); box-shadow: var(--shadow); }
input[type=search]:focus { outline: none; border-color: var(--ink); }
.filters { display: flex; gap: 6px; margin: 14px -20px 4px; padding: 0 20px 4px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter { flex: none; display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid var(--line-2); border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.filter .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rc, var(--muted)); }
.filter.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filter .muted { color: inherit; opacity: .6; font-size: inherit; }
#glossary-count { margin: 10px 0 0; }
.letter { position: sticky; top: 0; z-index: 1; font: 800 1.1rem/1 var(--display); padding: 18px 0 8px; background: var(--bg); border-bottom: 2px solid var(--ink); }

/* ---------- Sheet ---------- */
.sheet { position: fixed; inset: 0; background: #0007; display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet-card { position: relative; width: 100%; max-width: 600px; max-height: 85dvh; overflow: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 22px calc(28px + env(safe-area-inset-bottom)); }
.grab { width: 36px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 0 auto 16px; }
.sheet-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; display: grid; place-items: center; background: var(--bg); border: 0; border-radius: 50%; color: var(--ink-2); cursor: pointer; }
.sheet-close svg { width: 16px; height: 16px; }
.sheet-card .region-chip { font-size: .8rem; }
.sheet-card h3 { margin: 10px 0 0; font: 800 2.1rem/1.05 var(--display); letter-spacing: -.02em; }
.sheet-also { margin: 6px 0 0; }
.sheet-plain { margin: 16px 0 6px; font-size: 1.2rem; font-weight: 700; }
.sheet-plain::before { content: "Means "; font-weight: 500; color: var(--muted); }
.sheet-meaning { margin: 0; color: var(--ink-2); line-height: 1.55; }
.sheet-example { margin: 16px 0 0; padding: 12px 14px; background: var(--bg); border-left: 4px solid var(--hi); border-radius: 0 10px 10px 0; font-style: italic; }
.sheet-example:empty, .sheet-note:empty, .sheet-also:empty { display: none; }
.sheet-note { margin: 12px 0 0; font-size: .85rem; color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: .75rem; padding: 18px 20px calc(18px + var(--tabbar-h)); }

/* ---------- Phone ---------- */
@media (max-width: 640px) {
  :root { --tabbar-h: calc(58px + env(safe-area-inset-bottom)); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0; gap: 0; border: 0; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding: 0 0 env(safe-area-inset-bottom); }
  .tab { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: .7rem; padding: 8px 0 7px; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active::after { left: 35%; right: 35%; top: 0; bottom: auto; border-radius: 0 0 3px 3px; }
  .top-inner { padding-bottom: 4px; }
  h1 { font-size: 1.55rem; }
  main { padding-top: 14px; }
}
@media (min-width: 720px) {
  h1 { font-size: 2rem; }
  .output { font-size: 1.5rem; }
}

/* ---------- Layout helpers (all sizes) ---------- */
.tr-intro { display: none; }
.gl-side .filters { flex-wrap: nowrap; }

/* ---------- Tablet ---------- */
@media (min-width: 720px) and (max-width: 959px) {
  .translator { display: grid; grid-template-columns: 1fr 1fr; }
  .pane-out { border-top: 0; border-left: 1px dashed var(--line-2); }
  .sample-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .sample:nth-last-child(2) { border-bottom: 0; }
}

/* ---------- Desktop / web ---------- */
@media (min-width: 960px) {
  .top-inner, main { max-width: 1200px; padding-left: 40px; padding-right: 40px; }
  .top-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; padding-top: 26px; border-bottom: 1px solid var(--line); }
  .stripe + .top-inner { padding-top: 26px; }
  .brand-block { padding-bottom: 18px; }
  h1 { font-size: 2.1rem; }
  .tag { margin-top: 6px; }
  .tabs { margin: 0; border-bottom: 0; gap: 32px; }
  .tab { padding: 0 2px 20px; font-size: 1rem; }
  .tab.active::after { bottom: 0; }

  main { padding-top: 32px; padding-bottom: 56px; }

  /* Translator: side by side, roomy */
  .translator { display: grid; grid-template-columns: 1fr 1fr; min-height: 260px; border-radius: 22px; }
  .pane { padding: 22px 26px 20px; display: flex; flex-direction: column; }
  .pane-out { border-top: 0; border-left: 1px dashed var(--line-2); background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
  textarea { flex: 1; font-size: 1.35rem; min-height: 150px; margin-top: 12px; }
  .output { font-size: 1.5rem; margin-top: 12px; }
  .output.empty { font-size: 1.05rem; }
  .row { margin-top: 14px; }

  /* Results + sidebar */
  .tr-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 48px; align-items: start; margin-top: 8px; }
  .tr-side { position: sticky; top: 24px; }
  .tr-side .wotd { margin-top: 32px; }
  .explain .section-title, .tr-intro .section-title { margin-top: 32px; }
  body:not(.has-text) .tr-intro { display: block; }
  .tr-intro p { font-size: 1rem; line-height: 1.6; max-width: 56ch; }
  body.has-text .wotd, body.has-text .samples { display: block; }
  .explain .term-row { padding: 16px 2px; }
  .explain .meaning { max-width: 64ch; }
  .sample { font-size: .95rem; padding: 12px 2px; }

  /* Glossary: sticky sidebar + two-column list */
  .gl-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 48px; align-items: start; }
  .gl-side { position: sticky; top: 24px; }
  .gl-side .filters { flex-direction: column; align-items: stretch; margin: 16px 0 0; padding: 0; overflow: visible; gap: 2px; }
  .gl-side .filter { justify-content: flex-start; border: 0; border-radius: 10px; padding: 9px 12px; font-size: .92rem; background: transparent; }
  .gl-side .filter:hover { background: var(--surface); }
  .gl-side .filter .muted { margin-left: auto; }
  .gl-side .filter.active { background: var(--ink); color: var(--bg); }
  #glossary-count { margin: 14px 12px 0; }
  .glossary .terms { display: grid; grid-template-columns: 1fr 1fr; column-gap: 40px; align-items: start; }
  .glossary .term-row:last-child { border-bottom: 1px solid var(--line); }
  .glossary .term-row:nth-last-child(2):nth-child(odd) { border-bottom: 1px solid var(--line); }
  .letter { font-size: 1.5rem; padding-top: 26px; }
  .letter:first-child { padding-top: 0; }

  /* Sheet becomes a centred dialog */
  .sheet { align-items: center; }
  .sheet-card { border-radius: 22px; max-width: 560px; padding: 26px 30px 30px; box-shadow: 0 24px 80px #0005; }
  .grab { display: none; }

  .foot { max-width: 1200px; margin: 0 auto; width: 100%; text-align: left; padding: 22px 40px; border-top: 1px solid var(--line); }
}
@media (min-width: 1280px) {
  .tr-grid { grid-template-columns: minmax(0, 1fr) 400px; }
}
