:root {
  --bg: #f2f2f7;
  --panel: #ffffff;
  --muted: #6b6b72;
  --text: #111111;
  --accent: #0a84ff;
  --danger: #ff3b30;
  --border: #e5e5ea;
  --shadow: 0 8px 24px rgba(0,0,0,0.08);
  --shadowStrong: 0 18px 52px rgba(0,0,0,0.18);
  --radius: 14px;
}

* { box-sizing: border-box; }

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

/* iOS tap polish */
* { -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, Roboto, Helvetica, Arial;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

a:hover { text-decoration: underline; }

/* App shell (ChatGPT-ish) */
.appShell {
  height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top top"
    "side main";
}

.topBar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(242,242,247,0.92);
  backdrop-filter: saturate(140%) blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topTitle {
  flex: 1;
  min-width: 0;
}

.topTitleMain {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topTitleSub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconBtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: #111;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}

.iconBtn:hover { filter: brightness(0.98); }
.iconBtn:active { transform: scale(0.98); }

/* Splash */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 800px at 50% 0%, rgba(10,132,255,0.10), transparent 50%), var(--bg);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.splashVisible {
  opacity: 1;
  pointer-events: auto;
}

.splashCard {
  width: min(360px, 92vw);
  text-align: center;
  padding: 18px 18px 16px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.65);
  background: rgba(255,255,255,0.75);
  backdrop-filter: saturate(140%) blur(18px);
  box-shadow: var(--shadowStrong);
}

/* Back-compat with existing HTML classnames */
.splashInner {
  width: min(360px, 92vw);
  text-align: center;
  padding: 18px 18px 16px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.65);
  background: rgba(255,255,255,0.75);
  backdrop-filter: saturate(140%) blur(18px);
  box-shadow: var(--shadowStrong);
}

.splashIcon {
  width: 74px;
  height: 74px;
}

.splashName {
  font-weight: 800;
  font-size: 22px;
  margin-top: 10px;
}

.splashLogo {
  width: 74px;
  height: 74px;
}

.splashTitle {
  font-weight: 800;
  font-size: 22px;
  margin-top: 10px;
}

.splashSub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.langSelect {
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

.sidebar {
  grid-area: side;
  border-right: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
  z-index: 30;
}

.sidebarTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebarBrand { font-weight: 800; letter-spacing: 0.2px; }

.sidebarActions {
  display: flex;
  gap: 10px;
}

.sidebarSectionTitle {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0;
}

.docList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.docItem {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.docItem:active {
  transform: scale(0.99);
}

.docItemActive {
  border-color: rgba(10,132,255,0.45);
  box-shadow: 0 0 0 4px rgba(10,132,255,0.10) inset;
}

.docItemTitle {
  font-weight: 650;
  margin: 0;
}

.docItemMeta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.docItemActions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.sidebarFooter {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.22);
  z-index: 25;
}

.main {
  grid-area: main;
  overflow: auto;
  padding: 14px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.view { display: none; }
.viewActive { display: block; }

.readerPanel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.readerText {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

/* legacy layout bits: keep for minimal reuse */
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.col { flex: 1 1 320px; }

label { display:block; margin: 10px 0 6px; color: var(--muted); font-size: 13px; }

input, select, textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 14px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(10,132,255,0.55);
  box-shadow: 0 0 0 4px rgba(10,132,255,0.14);
}

textarea { min-height: 110px; resize: vertical; }

button {
  background: #f2f2f7;
  border: 1px solid var(--border);
  color: #111;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}

button:hover { filter: brightness(0.98); }
button:active { transform: scale(0.985); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.secondary {
  background: #f2f2f7;
  color: #111;
  border: 1px solid var(--border);
}

button.danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid rgba(0,0,0,0.06);
}

.small { font-size: 13px; color: var(--muted); }

.list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #f2f2f7;
  color: #111;
  border: 1px solid var(--border);
.card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  background: #f2f2f7;
  color: #111;
  border: 1px solid var(--border);
.pill {
  display: inline-block;
.playerBar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 8px 10px;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

.playerBar button {
  min-width: 44px;
  height: 40px;
  border-radius: 999px;
  padding: 0 12px;
}
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #f2f2f7;
}

.segment {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  transition: transform 140ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.segment:active {
  transform: scale(0.995);
}

.segment.active {
  border-color: rgba(10,132,255,0.45);
  box-shadow: 0 0 0 4px rgba(10,132,255,0.10) inset;
}

.segment .meta {
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.segment .text {
  white-space: normal;
  line-height: 1.6;
  font-size: 17px;
}

.toolbar {
  display:flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.notice {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(760px, calc(100% - 24px));
  border: 1px solid rgba(255,255,255,0.65);
  border-radius: 16px;
  padding: 10px 12px;
  color: #111;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(140%) blur(18px);
  box-shadow: var(--shadowStrong);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 40;
}

.noticeVisible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(-2px);
}

/* Mobile: make it feel like a single-screen app */
@media (max-width: 820px) {
  .appShell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main";
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(340px, 92vw);
    transform: translateX(-105%);
    transition: transform 260ms cubic-bezier(.2,.9,.2,1);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadowStrong);
  }

  .sidebarOpen { transform: translateX(0); }

  .backdrop {
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 180ms ease;
    backdrop-filter: saturate(120%) blur(10px);
  }

  .backdropOpen {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .main { padding: 12px; }
  .toolbar > input[type="search"] { flex: 1 1 auto; }
}

/* Simple modal */
.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.22);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 60;
}

.modalOverlay.isOpen {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  width: min(740px, 100%);
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 22px 60px rgba(0,0,0,0.25);
  padding: 14px;
  transform: translateY(14px) scale(0.995);
  transition: transform 220ms cubic-bezier(.2,.9,.2,1);
}

/* iOS sheet handle */
.modal::before {
  content: "";
  display: block;
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgba(0,0,0,0.16);
  margin: 2px auto 10px;
}

.modalOverlay.isOpen .modal {
  transform: translateY(0) scale(1);
}

body.modalOpen {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .splash,
  .notice,
  .modalOverlay,
  .modal,
  .iconBtn,
  button {
    transition: none !important;
    animation: none !important;
  }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.viewActive .readerPanel,
.viewActive .panel {
  animation: fadeUp 220ms ease;
}

.modalTitle {
  font-weight: 700;
  margin: 0 0 8px;
}

.modalActions {
  display:flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

mark {
  background: rgba(10,132,255,0.18);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}
