@font-face {
  font-family: 'Noto Sans Sinhala';
  src: url('/fonts/NotoSansSinhala-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0D80-0DFF, U+200C-200D;
}
@font-face {
  font-family: 'Noto Sans Sinhala';
  src: url('/fonts/NotoSansSinhala-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
  unicode-range: U+0D80-0DFF, U+200C-200D;
}

:root {
  --bg: #f7f3ec;
  --surface: #ffffff;
  --surface-2: #efe9df;
  --text: #1d1a16;
  --muted: #5f574c;
  --line: #ddd4c6;
  --accent: #8a3b12;
  --accent-text: #ffffff;
  --ok: #1d7a3e;
  --ok-soft: #e3f3e8;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --unsure: #6b5a1e;
  --unsure-soft: #f5edd2;
  --focus: #1a5fb4;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #171512;
    --surface: #23201b;
    --surface-2: #2e2a24;
    --text: #f4efe7;
    --muted: #bdb3a4;
    --line: #3e382f;
    --accent: #f0a46c;
    --accent-text: #1d1a16;
    --ok: #6fd18f;
    --ok-soft: #1c3324;
    --bad: #ff8a80;
    --bad-soft: #3d1f1c;
    --unsure: #e6cf7a;
    --unsure-soft: #3a3320;
    --focus: #8ab4f8;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #171512;
  --surface: #23201b;
  --surface-2: #2e2a24;
  --text: #f4efe7;
  --muted: #bdb3a4;
  --line: #3e382f;
  --accent: #f0a46c;
  --accent-text: #1d1a16;
  --ok: #6fd18f;
  --ok-soft: #1c3324;
  --bad: #ff8a80;
  --bad-soft: #3d1f1c;
  --unsure: #e6cf7a;
  --unsure-soft: #3a3320;
  --focus: #8ab4f8;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Sinhala', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Noto Sans Sinhala only covers Sinhala (see unicode-range); English uses the phone's own font. */
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

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

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

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.si {
  display: block;
}
.en {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.3;
  margin: 8px 0 4px;
}
h2 {
  font-size: 1.1rem;
  margin: 28px 0 10px;
}

p {
  margin: 0 0 12px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.3;
}
.topbar-title strong {
  color: var(--text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.counter {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 12px 18px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active {
  transform: scale(0.98);
}
.btn[disabled] {
  opacity: 0.55;
  cursor: default;
}
.btn .label {
  flex: 1;
  line-height: 1.25;
}
.btn .icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  line-height: 1;
}
.btn + .btn {
  margin-top: 12px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary .en {
  color: inherit;
  opacity: 0.85;
}
.btn-ok {
  background: var(--ok-soft);
  border-color: var(--ok);
}
.btn-ok .icon {
  background: var(--ok);
  color: var(--surface);
}
.btn-bad {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.btn-bad .icon {
  background: var(--bad);
  color: var(--surface);
}
.btn-unsure {
  background: var(--unsure-soft);
  border-color: transparent;
  min-height: 60px;
  font-size: 1rem;
}
.btn-unsure .icon {
  background: var(--unsure);
  color: var(--surface);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
}
.btn.selected {
  outline: 4px solid var(--text);
  outline-offset: 2px;
}
.btn-quiet {
  background: transparent;
  box-shadow: none;
  border-color: var(--line);
  min-height: 56px;
  font-size: 1rem;
  font-weight: 400;
}
.btn-small {
  width: auto;
  min-height: 48px;
  padding: 6px 14px;
  font-size: 0.9rem;
  border-radius: 14px;
}
.row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.row .btn {
  margin-top: 0;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin: 12px 0 18px;
}
.field-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 2px;
}
.english {
  font-size: 1.15rem;
  margin: 0 0 14px;
}
.sinhala {
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.45;
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.tip-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 8px;
}
.tip-body {
  font-size: 1.1rem;
  line-height: 1.65;
  margin: 0;
  white-space: pre-line;
}
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.cue {
  font-size: 1.6rem;
  float: right;
  margin-left: 8px;
}
.question {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 8px 0 14px;
}
.notice {
  background: var(--unsure-soft);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin: 0 0 14px;
}
.your-answer {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 12px;
}
.sinhala-small {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 4px 0 0;
  white-space: pre-line;
}

.pairs {
  list-style: none;
  padding: 0;
  margin: 0;
}
.pairs li + li {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

.option-letter {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-weight: 600;
}
.btn-option {
  border-color: var(--line);
  font-size: 1.3rem;
}

/* ---------- Correction form ---------- */

.fix label {
  display: block;
  font-weight: 600;
  margin: 14px 0 6px;
}
.fix textarea,
.fix input,
.admin input {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 12px 14px;
  font-size: 1.2rem;
  line-height: 1.5;
}
.fix textarea {
  min-height: 140px;
  resize: vertical;
}
.fix textarea:focus,
.fix input:focus {
  border-color: var(--focus);
  outline: none;
}
.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 6px 0 0;
}

/* ---------- Home ---------- */

.progress {
  height: 16px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 6px;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--ok);
  border-radius: 999px;
  width: 0;
  transition: width 0.3s;
}
.progress-text {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 20px;
}
.section-btn {
  font-size: 1rem;
  min-height: 64px;
}
.section-btn .count {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}
.section-btn.complete .count {
  color: var(--ok);
  font-weight: 600;
}
.section-list .btn + .btn {
  margin-top: 10px;
}

/* ---------- Login ---------- */

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 18px 0 8px;
}
.pin-dots span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--text);
}
.pin-dots span.filled {
  background: var(--text);
}
.pin-message {
  text-align: center;
  min-height: 5em;
  margin: 0;
  font-size: 0.95rem;
}
.pin-message.error {
  color: var(--bad);
  font-weight: 600;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.keypad button {
  min-height: 72px;
  border: none;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.8rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.keypad button:active {
  background: var(--surface-2);
}
.keypad button.blank {
  visibility: hidden;
}
.shake {
  animation: shake 0.4s;
}
@keyframes shake {
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

/* ---------- Celebration ---------- */

.center {
  text-align: center;
}
.big-emoji {
  font-size: 4rem;
  line-height: 1.2;
  margin: 32px 0 8px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  max-width: calc(100% - 32px);
  text-align: center;
  white-space: pre-line;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.error {
  background: var(--bad);
  color: #fff;
}

.loading {
  text-align: center;
  color: var(--muted);
  margin-top: 30vh;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
