:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #232019;
  --muted: #6b6558;
  --accent: #7a3b2e;
  --accent-light: #efe2da;
  --border: #e2ddd2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

a { color: var(--accent); }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

header.site {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 18px clamp(14px, 4vw, 36px);
  padding-left: max(clamp(14px, 4vw, 36px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 4vw, 36px), env(safe-area-inset-right));
  box-shadow: 0 1px 3px rgba(35, 32, 25, 0.05);
}

header.site h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

header.site p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px clamp(14px, 4vw, 36px) 60px;
}

.book-tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0 14px;
}

.book-tabs a {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.92rem;
}

.book-tabs a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

input.filter {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 16px;
  background: var(--panel);
}

.lesson {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(35, 32, 25, 0.03);
}

.lesson h3 {
  margin: 0 0 8px;
  font-size: 1.02rem;
}

.lesson form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.lesson label.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  padding: 8px 12px;
  min-height: 38px;
  border-radius: 999px;
  background: var(--accent-light);
  cursor: pointer;
}

.lesson label.chk input {
  margin: 0;
  width: 17px;
  height: 17px;
}

.lesson button {
  padding: 9px 18px;
  min-height: 38px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}

.lesson button:hover { opacity: 0.92; }

.missing-lang {
  opacity: 0.35;
  font-size: 0.9rem;
  padding: 4px 10px;
}

/* --- view.php --- */

.view-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.view-toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px clamp(14px, 4vw, 36px);
  padding-left: max(clamp(14px, 4vw, 36px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 4vw, 36px), env(safe-area-inset-right));
  position: sticky;
  top: 0;
  z-index: 5;
}

.view-toolbar .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.view-toolbar h2 {
  margin: 0;
  font-size: 1.1rem;
}

.view-toolbar .nav a {
  text-decoration: none;
  font-size: 0.9rem;
  margin-left: 12px;
  display: inline-block;
  padding: 4px 2px;
}

.lang-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.lang-form label.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  padding: 7px 12px;
  min-height: 36px;
  border-radius: 999px;
  background: var(--accent-light);
  cursor: pointer;
}

.lang-form label.chk input {
  margin: 0;
  width: 16px;
  height: 16px;
}

.lang-form button {
  padding: 8px 16px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
}

/* One row of tabs per selected language — used on narrow screens only,
   to switch which single pane is showing instead of stacking them. */
.mobile-tabs {
  display: none;
}

.panes {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(320px, 1fr);
  gap: 1px;
  background: var(--border);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  flex: 1;
  min-height: 0;
}

.pane {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 320px;
  scroll-snap-align: start;
}

.pane .pane-head {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.pane .pane-head .name { font-weight: 600; color: var(--ink); }
.pane .pane-head a {
  font-size: 0.8rem;
  margin-left: 8px;
  text-decoration: none;
  padding: 4px;
}
.pane .pane-remove { color: var(--muted); font-weight: 600; }
.pane .pane-remove:hover { color: var(--accent); }

.pane iframe {
  border: none;
  flex: 1;
  width: 100%;
}

.empty-note {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* Narrow screens: show one full-height pane at a time via the tab strip
   above, instead of side-by-side columns (which would force endless
   vertical scrolling to compare two documents on a phone). */
@media (max-width: 760px) {
  .view-page { min-height: 0; }

  .mobile-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px clamp(14px, 4vw, 36px) 0;
    background: var(--panel);
  }

  .mobile-tabs button {
    flex: 0 0 auto;
    padding: 8px 16px;
    min-height: 36px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--ink);
    font-size: 0.88rem;
    white-space: nowrap;
    cursor: pointer;
  }

  .mobile-tabs button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  .panes {
    display: block;
    overflow: visible;
    background: none;
  }

  .pane {
    display: none;
    min-width: unset;
  }

  .pane.is-active { display: flex; }

  .pane iframe {
    /* flex:1 (from the base rule) uses flex-basis:0% and would otherwise
       win over any height set here, since nothing gives .pane a definite
       height to grow into — cancel it so this height actually applies.
       (JS refines this further once it runs; this is just the fallback.) */
    flex: none;
    height: calc(100vh - 205px);
  }

  @supports (height: 100dvh) {
    .pane iframe { height: calc(100dvh - 205px); }
  }
}

@media (min-width: 761px) {
  .view-page { height: 100vh; overflow: hidden; }
}
