/* ============ EyeCheck — global styles ============ */
:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #16243a;
  --muted: #5b6b82;
  --primary: #1f6feb;
  --primary-dark: #1857ba;
  --accent: #0ea5a4;
  --danger: #d23b3b;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --ok: #1a9b50;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(22, 36, 58, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", "Noto Sans Hebrew", "Noto Sans Arabic",
          "Segoe UI Historic", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.15rem;
  font-weight: 700;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.brand-eye { font-size: 1.4rem; }

.lang-switch { display: flex; gap: .25rem; flex-wrap: wrap; }
.lang-btn {
  border: 1px solid #d7dfeb;
  background: var(--surface);
  border-radius: 8px;
  padding: .3rem .55rem;
  font-size: .85rem;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---------- screens ---------- */
#screens { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.screen { display: none; animation: fadein .25s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1 { font-size: 1.7rem; margin: .5rem 0 .75rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 .5rem; }
.lead { color: var(--muted); font-size: 1.05rem; margin-top: 0; }
.section-title { margin-top: 2.2rem; }

/* ---------- hero ---------- */
.hero {
  text-align: center;
  padding: 1.5rem 1rem 1rem;
  background: linear-gradient(160deg, #e8f0fe 0%, #f3fbfa 100%);
  border-radius: var(--radius);
}
.hero h1 { font-size: 2rem; }
.hero-actions { margin: 1.25rem 0 .75rem; }
.disclaimer-inline { color: var(--muted); font-size: .85rem; }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1rem;
  border: 0;
  border-radius: 10px;
  padding: .65rem 1.3rem;
  cursor: pointer;
  transition: filter .15s, transform .05s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e3ebf6; color: var(--primary-dark); font-weight: 600; }
.btn-ghost { background: none; color: var(--muted); text-decoration: underline; }
.btn-lg { font-size: 1.15rem; padding: .85rem 1.9rem; }
.btn-sm { font-size: .9rem; padding: .4rem .8rem; }
.btn-choice {
  background: var(--surface);
  border: 2px solid #d7dfeb;
  color: var(--text);
  font-weight: 500;
  width: 100%;
  max-width: 460px;
}
.btn-choice:hover { border-color: var(--primary); }
.btn-choice.selected { border-color: var(--primary); background: #e8f0fe; }
.actions-row { display: flex; gap: .75rem; justify-content: center; margin-top: 1.5rem; flex-wrap: wrap; }

/* ---------- test grid ---------- */
.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: .9rem;
}
.test-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  cursor: pointer;
  border: 2px solid transparent;
  text-align: start;
  font-family: inherit;
  font-size: 1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.test-card:hover { border-color: var(--primary); }
.test-card .tc-icon { font-size: 1.7rem; }
.test-card .tc-name { font-weight: 700; }
.test-card .tc-desc { color: var(--muted); font-size: .88rem; }
.test-card .tc-result { color: var(--ok); font-size: .85rem; font-weight: 600; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-top: 1.5rem;
}
.info-card ul { padding-inline-start: 1.2rem; margin: .5rem 0 1rem; }
.info-card li { margin-bottom: .35rem; }
.calib-status { margin-inline-start: .75rem; font-size: .9rem; color: var(--ok); font-weight: 600; }
.warn-card { background: var(--warn-bg); border: 1px solid var(--warn-border); }
.warn-card h3 { margin-top: 0; }

/* ---------- calibration ---------- */
.calib-area {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.calib-card {
  width: 324px;
  height: 204px;
  background: linear-gradient(135deg, #3b5bdb, #5f3dc4);
  border-radius: 12px;
  color: #fff;
  display: flex;
  align-items: flex-end;
  padding: .8rem;
  font-size: .9rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  max-width: 100%;
}
#calibSlider { width: 100%; max-width: 480px; }
.calib-fine { display: flex; gap: .6rem; }
.dist-options { display: flex; gap: .6rem; flex-wrap: wrap; }
.dist-options .btn-choice { width: auto; min-width: 84px; }

/* ---------- instructions ---------- */
.instr-icon { font-size: 3rem; text-align: center; }
#screen-instructions h1 { text-align: center; }
.instr-body {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  max-width: 620px;
  margin: 0 auto;
}
.instr-body p { margin: .5rem 0; }
.eye-banner {
  margin: 1.25rem auto 0;
  max-width: 620px;
  background: #e8f0fe;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: .9rem 1.2rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

/* ---------- generic test layout ---------- */
.screen-test { text-align: center; }
.test-topinfo { display: flex; justify-content: center; gap: .6rem; margin-bottom: .5rem; }
.eye-chip, .level-chip {
  display: inline-block;
  border-radius: 999px;
  padding: .25rem .8rem;
  font-size: .85rem;
  font-weight: 600;
}
.eye-chip { background: #e8f0fe; color: var(--primary-dark); }
.level-chip { background: #e6f7f0; color: var(--ok); }
.test-question { font-size: 1.1rem; font-weight: 600; margin: .75rem 0; }

.optotype-stage {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
  max-width: 640px;
  overflow: hidden;
}

/* direction pad */
.dirpad {
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: 72px 72px 72px;
  grid-template-rows: 64px 64px 64px;
  gap: .4rem;
  justify-content: center;
  direction: ltr; /* keep physical directions in RTL languages */
}
.dir-btn {
  font-size: 1.5rem;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.dir-btn:active { background: var(--primary-dark); }
.dir-up { grid-area: up; }
.dir-down { grid-area: down; }
.dir-left { grid-area: left; }
.dir-right { grid-area: right; }

/* ---------- color plates ---------- */
.plate-wrap { display: flex; justify-content: center; margin-bottom: 1.25rem; }
#colorPlate {
  width: min(80vw, 340px);
  height: min(80vw, 340px);
  border-radius: 50%;
  box-shadow: var(--shadow);
  background: #fff;
}
.answer-row {
  display: flex;
  gap: .6rem;
  justify-content: center;
  flex-wrap: wrap;
  direction: ltr;
}
.answer-row .btn-choice { width: auto; min-width: 72px; font-size: 1.25rem; font-weight: 700; }
.answer-col { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin-top: .5rem; }

/* ---------- astigmatism / amsler ---------- */
#astigDial, #amslerGrid {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 88vw;
  height: auto;
}
.amsler-q { font-weight: 600; font-size: 1.05rem; margin: .25rem 0 .25rem; }

/* ---------- duochrome ---------- */
.duo-wrap {
  display: flex;
  justify-content: center;
  margin: 0 auto 1.25rem;
  max-width: 560px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  direction: ltr;
}
.duo-half { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.2rem .5rem; }
.duo-red { background: #e0201b; }
.duo-green { background: #0f9d36; }
.duo-rings { width: min(28vw, 120px); height: auto; }

/* ---------- near vision ---------- */
.near-blocks { display: flex; flex-direction: column; gap: .9rem; max-width: 640px; margin: 0 auto 1.25rem; }
.near-block {
  background: var(--surface);
  border: 2px solid #d7dfeb;
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  cursor: pointer;
  text-align: start;
  font-family: inherit;
  color: var(--text);
}
.near-block:hover { border-color: var(--primary); }
.near-block .nb-label { font-size: .75rem; color: var(--muted); display: block; margin-bottom: .3rem; }

/* light stage for contrast test */
.stage-light { background: #fff; }

/* ---------- results ---------- */
.results-list { display: flex; flex-direction: column; gap: .9rem; margin-top: 1rem; }
.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.2rem;
  border-inline-start: 6px solid var(--muted);
}
.result-card.status-good { border-inline-start-color: var(--ok); }
.result-card.status-borderline { border-inline-start-color: #e0a800; }
.result-card.status-refer { border-inline-start-color: var(--danger); }
.result-card h3 { margin: 0 0 .3rem; display: flex; align-items: center; gap: .5rem; }
.result-card .rc-value { font-weight: 700; font-size: 1.05rem; }
.result-card .rc-note { color: var(--muted); font-size: .92rem; margin: .3rem 0 0; }
.result-card .rc-status { font-size: .8rem; font-weight: 700; border-radius: 999px; padding: .15rem .6rem; }
.status-good .rc-status { background: #e6f7f0; color: var(--ok); }
.status-borderline .rc-status { background: #fff4d6; color: #8a6d00; }
.status-refer .rc-status { background: #fdeaea; color: var(--danger); }

/* ---------- footer / toast ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  padding: 1rem;
}
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: 999px;
  font-size: .95rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  z-index: 50;
}

/* ---------- responsive ---------- */
@media (max-width: 540px) {
  h1 { font-size: 1.45rem; }
  .hero h1 { font-size: 1.6rem; }
  .optotype-stage { height: 230px; }
  .dirpad { grid-template-columns: 64px 64px 64px; grid-template-rows: 56px 56px 56px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .lang-switch { justify-content: center; }
}

/* RTL: flip nothing physical; logical properties handle text flow */
[dir="rtl"] .answer-row { direction: ltr; }
