:root {
  --gold: #E3B04B;
  --navy: #12203D;
  --navy-soft: #1d2f55;
  --white: #FFFFFF;
  --bg: #F6F4EE;
  --text: #1b2333;
  --muted: #5b6376;
  --line: #e4e0d4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* ---------- Sign in ---------- */
.login {
  min-height: 100vh;
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
}
.login .wrap { width: 100%; padding-top: 32px; padding-bottom: 32px; }
.brand-mark {
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-weight: 800; letter-spacing: 1px;
  margin-bottom: 20px;
}
.login h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; }
.login h1 span { color: var(--gold); }
.login p { color: #c9d0e0; margin: 0 0 24px; }
.field {
  width: 100%; padding: 14px 16px; border-radius: 12px;
  border: 2px solid transparent; background: var(--white); color: var(--text);
  margin-bottom: 12px;
}
.field:focus { outline: none; border-color: var(--gold); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 0;
  background: var(--gold); color: var(--navy); font-weight: 700; cursor: pointer;
}
a.btn { text-decoration: none; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--navy); border: 2px solid var(--navy); }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 14px; }
.btn.saved { background: #eef1f7; color: var(--navy); border: 2px solid #c9d0e0; }
.btn:disabled { opacity: .6; cursor: default; }
.note { font-size: 13px; color: #9ba6bd; margin-top: 16px; }
.error { color: #ffb4a8; font-size: 14px; min-height: 20px; margin: 0 0 8px; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--navy); color: var(--white);
  position: sticky; top: 0; z-index: 5;
  padding-top: env(safe-area-inset-top);
}
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 58px; }
.topbar .title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; overflow: hidden; text-overflow: ellipsis; font-weight: 400; color: var(--gold); font-size: 12px; }
.linkbtn { background: none; border: 0; color: var(--gold); font-weight: 600; cursor: pointer; padding: 10px 4px; min-height: 44px; }
.lbl { display: block; font-weight: 600; margin-bottom: 6px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:focus-visible, .tab:focus-visible, .textbtn:focus-visible { outline-color: #1a73e8; }
.namebox .btn + .btn { margin-left: 8px; }

/* ---------- Library ---------- */
.banner {
  background: #fff7e2; border: 1px solid #f0dca6; border-radius: 12px;
  padding: 12px 14px; margin: 16px 0 0; font-size: 14px;
  display: flex; align-items: center; gap: 12px;
}
.banner div { flex: 1; }
.offline-pill {
  background: var(--gold); color: var(--navy); font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 3px 10px;
}
.tabs { display: flex; gap: 8px; margin: 16px 0; }
.tab {
  flex: 1; min-height: 44px; border-radius: 999px; border: 2px solid var(--navy);
  background: transparent; color: var(--navy); font-weight: 700; cursor: pointer;
}
.tab.on { background: var(--navy); color: var(--white); }
h2 { font-size: 18px; margin: 20px 0 10px; }
.empty { color: var(--muted); padding: 8px 0 16px; }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; margin-bottom: 12px; display: flex; gap: 14px;
}
.cover {
  flex: 0 0 84px; height: 118px; border-radius: 8px;
  background: linear-gradient(160deg, var(--navy), var(--navy-soft));
  border-left: 5px solid var(--gold);
  color: var(--gold); font-size: 11px; font-weight: 700; line-height: 1.25;
  padding: 10px 8px; overflow: hidden;
}
.cover { position: relative; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 0 8px 8px 0; }
.logo { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 0 12px -10px; }
.mark { height: 30px; width: auto; }
.cover.locked { filter: grayscale(.4); opacity: .8; }
.card .body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.card h3 { font-size: 16px; margin: 0 0 2px; }
.card .by { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.card .actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 40px; }

/* ---------- Certificates ---------- */
.tab { font-size: 14px; padding: 0 4px; }
.tabs { gap: 6px; }
.cert-thumb { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
.cert-thumb span { font-size: 30px; line-height: 1; }
.namebox { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.namebox label { display: block; margin-bottom: 12px; }
.namebox .field { border-color: var(--line); }
.namebox .field:focus { border-color: var(--gold); }
.error.dark { color: #b3261e; }
.smallnote { font-size: 13px; color: var(--muted); margin: 12px 0; }
.smallnote.center { text-align: center; }
.textbtn { background: none; border: 0; padding: 4px 8px; min-height: 44px; color: var(--navy); font-weight: 700; text-decoration: underline; cursor: pointer; }
.certbox { margin: 16px 0; background: var(--white); border-radius: 8px; box-shadow: 0 2px 12px rgba(18,32,61,.18); overflow: hidden; }
.certbox canvas { display: block; width: 100%; height: auto; }
.certbox .empty { padding: 40px 16px; text-align: center; }

/* ---------- Reader ---------- */
.reader { background: #232b3d; min-height: 100vh; }
.pages { max-width: 860px; margin: 0 auto; padding: 10px 0 40px; }
.page {
  background: var(--white); margin: 0 auto 10px; width: 100%;
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.page canvas { display: block; width: 100%; height: auto; pointer-events: none; }
.reader-msg { color: var(--white); text-align: center; padding: 60px 20px; }

@media print { body { display: none; } }
.textbtn.light { color: var(--gold); min-height: 0; padding: 0; }
.card .about { font-size: 14px; color: var(--text); margin: 0 0 12px; }
.card .by { margin-bottom: 6px; }

/* ---------- Language choice ---------- */
.langpick { display: flex; gap: 8px; margin: 0 0 20px; }
.langbtn { flex: 1; min-height: 44px; border-radius: 999px; border: 2px solid var(--gold); background: transparent; color: var(--gold); font-weight: 700; cursor: pointer; }
.langbtn.on { background: var(--gold); color: var(--navy); }
.langbtn:focus-visible { outline-color: var(--white); }
.soon { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; font-weight: 700; color: var(--muted); }
.foot .textbtn { font-size: 13px; }

.banner.share { margin-top: 22px; }

.banner.phone { margin-top: 22px; flex-wrap: wrap; }
.banner.phone input { flex: 1 1 150px; min-width: 0; padding: 10px 12px; border: 1px solid #c9b47a; border-radius: 10px; font: inherit; background: #fff; }
.banner.phone > div { flex: 1 1 100%; }
.phonemsg { display: block; font-weight: 600; margin-top: 4px; }
.banner.phone + .banner.share { margin-top: 12px; }
