:root {
  --brand: #f4801f;
  --brand-dark: #d9660a;
  --bg: #1b1b1e;
  --panel: #ffffff;
  --text: #1b1b1e;
  --muted: #6b7280;
  --bar-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ---------- Reader / carousel ---------- */
.reader {
  position: fixed;
  inset: 0 0 calc(var(--bar-h) + var(--safe-b)) 0;
  overflow: hidden;
}

.track {
  display: flex;
  height: 100%;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.track::-webkit-scrollbar { display: none; }

.slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}
.slide img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,.45);
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Page counter ---------- */
.counter {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .5px;
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 5;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--bar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--brand);
  box-shadow: 0 -2px 12px rgba(0,0,0,.3);
  z-index: 10;
}
.tool {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background .15s;
}
.tool:active { background: var(--brand-dark); }
.tool svg { width: 24px; height: 24px; fill: #fff; }
.tool-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}
.tool-lang { flex: 1.3; }
.tool-lang .tool-label { font-size: 12.5px; }

/* ---------- Language sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
}
.sheet-panel {
  width: 100%;
  max-height: 85vh;
  background: var(--panel);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
}
.search {
  flex: 1;
  font-size: 16px;
  padding: 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  outline: none;
}
.search:focus { border-color: var(--brand); }
.sheet-close {
  border: none;
  background: #f3f4f6;
  color: var(--muted);
  width: 46px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
}
.lang-list {
  list-style: none;
  margin: 0;
  padding: 6px 0 max(14px, var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.lang-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 18px;
  cursor: pointer;
  border-bottom: 1px solid #f4f4f5;
}
.lang-item:active { background: #fff3e8; }
.lang-item.active { background: #fff3e8; }
.lang-item.active::after { content: "✓"; color: var(--brand); margin-left: auto; font-weight: 700; }
.lang-native { font-size: 17px; font-weight: 600; }
.lang-en { font-size: 13px; color: var(--muted); }
.lang-empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- QR modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-panel {
  background: var(--panel);
  color: var(--text);
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  max-width: 340px;
  width: 100%;
}
.qr-holder {
  display: flex;
  justify-content: center;
  margin: 0 auto 14px;
}
.qr-holder img, .qr-holder canvas, .qr-holder table {
  width: 240px !important;
  height: 240px !important;
  image-rendering: pixelated;
}
.qr-text { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.btn-primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
}
.btn-primary:active { background: var(--brand-dark); }

/* ---------- Settings modal content ---------- */
.modal-panel-left { text-align: left; }
.settings-title {
  margin: 0 0 12px;
  font-size: 20px;
  color: var(--brand-dark);
}
.settings-note {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.5;
  color: #374151;
}
.settings-link {
  display: block;
  text-align: center;
  margin: 4px 0 18px;
  padding: 12px;
  border: 2px solid var(--brand);
  border-radius: 12px;
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: none;
}
.settings-link:active { background: #fff3e8; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--bar-h) + var(--safe-b) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 70;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

[hidden] { display: none !important; }
