:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --mask: #1c1c1a;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
main {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.screen { display: none; width: 100%; }
.screen.active { display: block; }

.card {
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 40px;
}
.card.center { text-align: center; }
h1 { font-size: 24px; margin: 0 0 16px; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

kbd {
  display: inline-block;
  font: 600 13px/1 var(--sans);
  padding: 4px 8px;
  border: 1px solid #c9c9c3;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fafaf8;
  color: var(--text);
}

.notice {
  background: #fff4e5;
  border: 1px solid #f0cf9c;
  color: #6b4400;
  padding: 12px 14px;
  border-radius: 8px;
  margin: 12px 0;
}

.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
.actions.center { justify-content: center; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: 600 16px/1 var(--sans);
  padding: 12px 22px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: #bdbdb6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.answer { min-width: 120px; font-size: 18px; padding: 14px 26px; }
.btn:focus-visible { outline: 3px solid #9cc3b6; outline-offset: 2px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  font: 16px var(--sans);
  padding: 10px 12px;
  border: 1px solid #cfcfc9;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid #9cc3b6; border-color: var(--accent); }

.steps { padding-left: 20px; margin: 0 0 18px; }
.steps li { margin-bottom: 10px; }
.press { text-align: center; margin-top: 26px; font-weight: 600; }

/* ---------- Reading display ---------- */
.sentence, .demo-line {
  font-family: var(--mono);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}
.sentence {
  max-width: 1000px;
  margin: 0 auto;
  min-height: 3.4em;
  font-size: 26px;
  line-height: 1.7;
  word-spacing: 0.25em;
  text-align: left;
  padding: 0 8px;
}
.sentence.center-mode { text-align: center; font-size: 32px; }
.w { white-space: pre; }
.w.masked {
  color: transparent;
  border-bottom: 2px solid var(--mask);
}
.demo-line {
  font-size: 20px;
  text-align: center;
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  word-spacing: 0.25em;
}
.hint { text-align: center; color: var(--muted); font-size: 14px; margin-top: 48px; }

.q-text { font-size: 22px; font-weight: 600; margin: 6px 0 4px; }

.code {
  font: 700 28px/1 var(--mono);
  letter-spacing: 0.08em;
  background: var(--bg);
  display: inline-block;
  padding: 12px 20px;
  border-radius: 8px;
  user-select: all;
}

#progress { position: fixed; top: 0; left: 0; right: 0; height: 4px; background: var(--line); }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

@media (max-width: 600px) {
  .card { padding: 24px 20px; }
  .sentence { font-size: 20px; }
}

.card.center .actions + .small { margin-top: 18px; }

/* ---------- Touch / mobile ---------- */
.t-only { display: none; }
body.touch .t-only { display: revert; }
body.touch .k-only { display: none; }
body.touch div.t-only.actions { display: flex; }

html, body { -webkit-text-size-adjust: 100%; }
button, .btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.btn.big { font-size: 18px; padding: 16px 40px; min-width: 200px; }

/* Màn đọc chiếm toàn màn hình, chạm ở đâu cũng được, không cuộn/zoom */
body.touch #s-trial.active {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  cursor: pointer;
}
body.touch #progress { z-index: 2; }
body.touch .hint { margin-top: 32px; }
.tap-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  height: 60px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 20px/60px var(--sans);
  text-align: center;
  pointer-events: none;           /* chỉ là gợi ý; cú chạm được bắt bởi cả màn hình */
  opacity: .92;
}
body.touch #s-trial:active .tap-bar { opacity: 1; }

/* Câu hỏi: khoá 0.4 s đầu để cú chạm cuối câu không bấm nhầm */
#s-question.locked .btn.answer { opacity: .45; pointer-events: none; }

@media (max-width: 600px) {
  main { padding: 20px 12px; align-items: flex-start; }
  .card { padding: 22px 18px; }
  h1 { font-size: 21px; }
  .sentence { font-size: 21px; line-height: 2; word-spacing: .2em; padding: 0; }
  .sentence.center-mode { font-size: 28px; }
  .demo-line { font-size: 17px; }
  .q-text { font-size: 20px; }
  #s-question .actions { gap: 12px; }
  #s-question .btn.answer { flex: 1; min-width: 0; min-height: 60px; font-size: 20px; }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1; }
}
