/* ===== Fonts (self-hosted, Unicode-complete for Sinhala & Tamil) ===== */
@font-face { font-family: "Outfit"; font-weight: 600; font-display: swap; src: url(../fonts/Outfit-600.woff2) format("woff2"); }
@font-face { font-family: "Outfit"; font-weight: 800; font-display: swap; src: url(../fonts/Outfit-800.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans"; font-weight: 400; font-display: swap; src: url(../fonts/NotoSans-400.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans"; font-weight: 700; font-display: swap; src: url(../fonts/NotoSans-700.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans Sinhala"; font-weight: 400; font-display: swap; src: url(../fonts/NotoSansSinhala-400.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans Sinhala"; font-weight: 700; font-display: swap; src: url(../fonts/NotoSansSinhala-700.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans Tamil"; font-weight: 400; font-display: swap; src: url(../fonts/NotoSansTamil-400.woff2) format("woff2"); }
@font-face { font-family: "Noto Sans Tamil"; font-weight: 700; font-display: swap; src: url(../fonts/NotoSansTamil-700.woff2) format("woff2"); }

/* ===== Tokens ===== */
:root {
  --bg: #eef5e3;
  --bg-2: #e2eed2;
  --surface: #ffffff;
  --ink: #133d20;
  --muted: #4b6150;
  --brand: #7ac143;
  --brand-strong: #2e7a1f;
  --brand-ink: #ffffff;
  --deep: #17502a;
  --line: #cfe2bb;
  --warn: #c9821a;
  --warn-bg: #fff3d9;
  --warn-ink: #5c3a00;
  --focus: #1a73e8;
  --shadow: 0 10px 30px rgba(23, 80, 42, .12);
  --radius: 22px;
  --font-head: "Outfit", "Noto Sans", system-ui, sans-serif;
  --font-body: "Noto Sans", system-ui, sans-serif;
  --lh: 1.5;
  color-scheme: light;
}
:root[lang="si"] { --font-head: "Noto Sans Sinhala", "Outfit", sans-serif; --font-body: "Noto Sans Sinhala", "Noto Sans", sans-serif; --lh: 1.7; }
:root[lang="ta"] { --font-head: "Noto Sans Tamil", "Outfit", sans-serif; --font-body: "Noto Sans Tamil", "Noto Sans", sans-serif; --lh: 1.7; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1a10; --bg-2: #122317; --surface: #17291c; --ink: #e5f1e2; --muted: #a6bea9;
    --brand: #8cc63f; --brand-strong: #9fd463; --brand-ink: #0d1a10; --deep: #0a2412; --line: #2a4430;
    --warn: #f0b14a; --warn-bg: #3a2a0d; --warn-ink: #ffe3ae; --focus: #8ab4f8;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh; min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: var(--lh);
  font-size: 1.0625rem;
}
[hidden] { display: none !important; }
img { max-width: 100%; height: auto; display: block; }
.marker-map img { width: 100%; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.25; margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 12px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Each language button always uses its own script font */
[data-font="en"] { font-family: "Outfit", "Noto Sans", sans-serif; }
[data-font="si"] { font-family: "Noto Sans Sinhala", sans-serif; }
[data-font="ta"] { font-family: "Noto Sans Tamil", sans-serif; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.wordmark { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.wordmark b { font-family: "Outfit", sans-serif; font-weight: 800; letter-spacing: .08em; color: var(--brand-strong); font-size: 1.05rem; }
.wordmark span { font-family: "Outfit", sans-serif; font-weight: 600; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lang-switch { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); flex-shrink: 0; }
.lang-switch button {
  border: 0; background: transparent; border-radius: 999px; min-height: 40px; min-width: 44px; padding: 0 12px;
  font-weight: 700; font-size: .95rem; cursor: pointer; color: var(--muted);
}
.lang-switch button[aria-pressed="true"] { background: var(--deep); color: #fff; }

/* ===== Layout ===== */
main { padding: 8px 16px calc(32px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.screen { animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 16px; }

/* ===== Welcome / language picker ===== */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(150deg, var(--deep), #2e7a1f 70%, var(--brand));
  color: #fff; border-radius: 28px; padding: 26px 22px 24px;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.25), transparent 70%);
}
.hero .brand { font-family: "Outfit", sans-serif; font-weight: 800; letter-spacing: .14em; font-size: .95rem; opacity: .9; }
.hero h1 { font-size: 1.6rem; margin-top: 6px; }
.hero p { margin: 10px 0 0; opacity: .92; }
.hero .ar-chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.18); border-radius: 999px; padding: 4px 12px; font-family: "Outfit", sans-serif; font-weight: 800; font-size: .85rem; margin-top: 12px; }

.lang-title { display: grid; gap: 2px; text-align: center; margin: 26px 0 14px; }
.lang-title span { color: var(--muted); font-size: .95rem; }
.lang-title span:first-child { font-family: "Outfit", sans-serif; font-weight: 800; color: var(--ink); font-size: 1.25rem; }
.lang-grid { display: grid; gap: 12px; }
.lang-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 72px; padding: 14px 20px;
  border: 2px solid var(--line); background: var(--surface); border-radius: 20px;
  font-size: 1.35rem; font-weight: 700; cursor: pointer; text-align: left;
  transition: transform .15s ease, border-color .15s ease;
}
.lang-btn:hover { border-color: var(--brand); }
.lang-btn:active { transform: scale(.98); }
.lang-btn small { font-family: "Noto Sans", sans-serif; font-size: .8rem; color: var(--muted); font-weight: 400; }
.lang-btn .arrow { width: 40px; height: 40px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; flex-shrink: 0; color: var(--brand-strong); }

/* ===== Home ===== */
.marker-preview { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; }
.marker-preview img { border-radius: 16px; box-shadow: var(--shadow); background: #fff; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 58px; padding: 12px 20px; border-radius: 999px; border: 0;
  font-family: var(--font-head); font-weight: 700; font-size: 1.1rem; cursor: pointer; text-align: center;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--deep); color: #fff; box-shadow: 0 8px 22px rgba(23, 80, 42, .35); }
.btn-primary:hover { filter: brightness(1.12); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 2px solid var(--line); }
.btn-small { min-height: 48px; font-size: 1rem; width: auto; padding: 10px 18px; }
.btn svg { flex-shrink: 0; }
.btn-row { display: grid; gap: 12px; }

.howto ol { margin: 10px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 12px; }
.howto li { counter-increment: s; display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; }
.howto li::before { content: counter(s); width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-family: "Outfit", sans-serif; font-weight: 800; }
.howto h2 { font-size: 1.15rem; }

.safety-banner {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start;
  background: var(--warn-bg); color: var(--warn-ink); border: 2px solid var(--warn);
  border-radius: 18px; padding: 14px 16px; font-weight: 700; font-size: .98rem;
}
.fineprint { color: var(--muted); font-size: .85rem; text-align: center; }
.fineprint p { margin: 6px 0; }

/* ===== 2D view ===== */
.view-head { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center; flex-shrink: 0;
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer; color: var(--ink);
}
.marker-map { position: relative; border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); background: #fff; }
.hotspot {
  position: absolute; transform: translate(-50%, -50%);
  width: 56px; height: 56px; border-radius: 50%; border: 3px solid #fff; cursor: pointer;
  background: rgba(23, 80, 42, .82); color: #fff; display: grid; place-items: center;
  box-shadow: 0 0 0 0 rgba(122, 193, 67, .8); animation: ping 1.8s ease-out infinite;
}
.hotspot.is-important { background: rgba(201, 130, 26, .92); }
.hotspot span { position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); white-space: nowrap; background: var(--deep); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 700; pointer-events: none; }
.hotspot.lbl-end span { left: auto; right: -8px; transform: none; }
.hotspot.lbl-start span { left: -8px; transform: none; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(122,193,67,.75); } 80%,100% { box-shadow: 0 0 0 18px rgba(122,193,67,0); } }
.topic-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.topic-list button {
  width: 100%; min-height: 64px; display: grid; grid-template-columns: 44px 1fr 24px; gap: 12px; align-items: center;
  padding: 10px 14px; text-align: left; border: 0; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer; font-weight: 700;
}
.topic-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--bg-2); color: var(--brand-strong); font-family: "Outfit", sans-serif; font-weight: 800; font-size: 1.15rem; }
.is-important .topic-icon { background: var(--warn-bg); color: var(--warn); }

/* ===== AR stage ===== */
#ar-stage { position: fixed; inset: 0; z-index: 40; background: #000; color: #fff; overflow: hidden; }
#ar-scene-host { position: absolute; inset: 0; overflow: hidden; }
#ar-scene-host a-scene { position: absolute; inset: 0; }
.ar-ui { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.ar-ui > * { pointer-events: auto; }
.ar-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  background: linear-gradient(rgba(0,0,0,.55), transparent); pointer-events: none;
}
.ar-top > * { pointer-events: auto; }
.ar-top .lang-switch { box-shadow: none; background: rgba(0,0,0,.45); }
.ar-top .lang-switch button { color: #e8f3e5; }
.ar-top .lang-switch button[aria-pressed="true"] { background: #fff; color: var(--deep); }
.glass-btn {
  min-width: 52px; height: 52px; border-radius: 999px; border: 0; cursor: pointer; color: #fff;
  background: rgba(0,0,0,.5); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; font-weight: 700;
}
.ar-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: grid; justify-items: center; gap: 12px;
  padding: 16px 16px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.6)); pointer-events: none;
}
.ar-bottom > * { pointer-events: auto; }
.ar-status {
  max-width: 520px; text-align: center; background: rgba(0,0,0,.6); border-radius: 999px; padding: 10px 18px;
  font-weight: 700; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.ar-status.is-found { background: rgba(46, 122, 31, .9); }
.ar-controls { display: flex; gap: 10px; }

.scan-frame {
  position: absolute; left: 50%; top: 46%; width: min(66vw, 46vh); aspect-ratio: 1; transform: translate(-50%, -50%);
  pointer-events: none !important;
}
.scan-frame i { position: absolute; width: 42px; height: 42px; border: 5px solid #fff; opacity: .9; }
.scan-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.scan-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.scan-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scan-frame img { position: absolute; inset: 18%; width: 64%; opacity: .32; border-radius: 12px; }
.scan-frame::after {
  content: ""; position: absolute; left: 6%; right: 6%; height: 3px; top: 10%; border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--brand), transparent); animation: sweep 2.2s ease-in-out infinite;
}
@keyframes sweep { 0%,100% { top: 10%; } 50% { top: 88%; } }

.ar-help {
  position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%); margin: 0 auto; max-width: 440px;
  max-height: calc(100% - 180px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--ink); border-radius: 24px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.4);
}
.ar-help h2 { font-size: 1.2rem; }
#ar-stage:has(#ar-help:not([hidden])) .ar-status,
#ar-stage:has(#ar-help:not([hidden])) .scan-frame { display: none; }
#ar-stage:has(#ar-error:not([hidden])) .ar-bottom { display: none; }
.ar-help ul { padding-left: 1.2em; margin: 10px 0 14px; }
.ar-help li + li { margin-top: 6px; }
.ar-help .help-row { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; }
.ar-help .help-row img { border-radius: 12px; }

.ar-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 16px; text-align: center; background: #0b140d; z-index: 5; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid rgba(255,255,255,.2); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Info sheet (dialog) ===== */
dialog.sheet {
  width: 100%; max-width: 640px; max-height: 82vh; max-height: 82dvh;
  margin: auto auto 0; padding: 0; border: 0; border-radius: 28px 28px 0 0;
  background: var(--surface); color: var(--ink); box-shadow: 0 -10px 40px rgba(0,0,0,.25);
  overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheetUp .3s cubic-bezier(.2,.8,.2,1); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .35); }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: grid; grid-template-columns: 1fr 48px; gap: 12px; align-items: start; padding: 10px 20px 12px; position: relative; }
.sheet-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 44px; height: 5px; border-radius: 5px; background: var(--line); transform: translateX(-50%); }
.sheet-head h2 { font-size: 1.3rem; padding-top: 18px; }
:root[lang="si"] .sheet-head h2, :root[lang="ta"] .sheet-head h2 { font-size: 1.12rem; }
.sheet-head .icon-btn { margin-top: 12px; box-shadow: none; background: var(--bg); }
.sheet-body { overflow-y: auto; padding: 0 20px 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-body > * + * { margin-top: 16px; }
.sheet-intro { font-weight: 700; color: var(--warn); }
.sheet-media { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
.sheet-media > * { flex: 0 0 auto; height: 170px; width: auto; max-width: 88%; border-radius: 16px; scroll-snap-align: start; background: var(--bg); object-fit: contain; }
.sheet-media video { aspect-ratio: 1; }
.sheet-section h3 { font-size: 1.05rem; color: var(--brand-strong); }
.sheet-section ol, .sheet-section ul { margin: 8px 0 0; padding-left: 1.6em; }
.sheet-section li + li { margin-top: 8px; }
.sheet-section ol li::marker { font-family: "Outfit", sans-serif; font-weight: 800; color: var(--brand-strong); }
.sheet-note { background: var(--bg); border-left: 5px solid var(--brand); border-radius: 12px; padding: 12px 14px; font-size: .95rem; }
.sheet.is-important .sheet-note { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); font-weight: 700; }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 20px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1 1 180px; }
.sheet-foot .narration-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: .85rem; }

/* While AR is running, keep the camera visible behind the sheet */
body.in-ar { overflow: hidden; }
body.in-ar .timer-chip { bottom: auto; top: calc(max(12px, env(safe-area-inset-top)) + 64px); }
body:has(.timer-chip:not([hidden])) .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
body:has(.timer-chip:not([hidden])) main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
body.in-ar dialog.sheet { max-height: 58vh; max-height: 58dvh; }
body.in-ar dialog.sheet::backdrop { background: rgba(0, 0, 0, .12); }

/* ===== Timer chip & toast ===== */
.timer-chip {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom)); white-space: nowrap;
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 16px; border-radius: 999px;
  background: var(--deep); color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.3); font-weight: 700;
}
.timer-chip time { font-family: "Outfit", sans-serif; font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.timer-chip button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; cursor: pointer; display: grid; place-items: center; }
.timer-chip.is-done { background: var(--warn); animation: shake .6s ease 3; }
@keyframes shake { 0%,100% { transform: translateX(-50%); } 25% { transform: translateX(calc(-50% - 6px)); } 75% { transform: translateX(calc(-50% + 6px)); } }
.toast {
  position: fixed; z-index: 70; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: #1b2a1e; color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
.toast.is-visible { opacity: 1; }

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

/* Larger phones / tablets */
@media (min-width: 560px) {
  .btn-row { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 1.9rem; }
}
