@import url("https://fonts.googleapis.com/css2?family=Frank+Ruhl+Libre:wght@400;500;700&family=Assistant:wght@400;600;700&family=Noto+Rashi+Hebrew:wght@400;600&family=Noto+Serif+Hebrew:wght@400;600&display=swap");

:root {
  --bg-0: #f5f0e4;
  --bg-1: #f2dfc7;
  --bg-2: #d9e7f0;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #1f2430;
  --muted: #5f6776;
  --brand: #a4472f;
  --brand-2: #1f5f7a;
  --line: #dfd3bd;
  --shadow: 0 14px 40px rgba(57, 41, 23, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Assistant", "Arial", sans-serif;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 12% -8%, #f8d7a6 0%, transparent 58%),
    radial-gradient(1000px 450px at 84% -6%, #b8d5e8 0%, transparent 56%),
    linear-gradient(160deg, var(--bg-0) 0%, #f8f5ee 44%, #f4f0e6 100%);
}

.hero {
  margin: 16px 16px 0;
  padding: 14px 22px;
  border: 1px solid rgba(223, 211, 189, 0.85);
  border-radius: 18px;
  background: linear-gradient(110deg, rgba(255, 252, 246, 0.93) 0%, rgba(247, 239, 225, 0.86) 58%, rgba(236, 244, 248, 0.9) 100%);
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 0;
  font-family: "Frank Ruhl Libre", serif;
  font-size: 2rem;
  line-height: 1.1;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(560px, 1.35fr) minmax(360px, 1.1fr);
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "controls controls controls"
    "left center right"
    "left centerBottom right";
  gap: 12px;
  padding: 14px 16px 16px;
  height: 100vh;
}

.panel {
  background: linear-gradient(180deg, var(--paper-strong) 0%, var(--paper) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 8px 26px rgba(74, 51, 25, 0.09);
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.panel h2 {
  margin: 0 0 8px;
  font-family: "Frank Ruhl Libre", serif;
  font-size: 1.45rem;
  line-height: 1.12;
  letter-spacing: 0.2px;
}

.controls-panel {
  grid-area: controls;
  background: linear-gradient(100deg, #fff8ec 0%, #f6efe2 55%, #eef6fa 100%);
  display: block;
  padding: 8px 12px;
}

.controls-top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.controls-top h1 {
  margin: 0;
  font-family: "Frank Ruhl Libre", serif;
  font-size: 1.9rem;
  line-height: 1.1;
  white-space: nowrap;
}

.controls-meta {
  margin: 0;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  text-align: right;
  flex: 0 1 auto;
  max-width: 100%;
}

.controls-meta a {
  color: var(--brand-2);
  text-decoration: underline;
}

.meta-sep {
  margin: 0 4px;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.side-left {
  grid-area: left;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.center-panel {
  grid-area: center;
  background: linear-gradient(180deg, #fffaf1 0%, #fff 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-right {
  grid-area: right;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.center-bottom-panel {
  grid-area: centerBottom;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.manuscript-panel {
  grid-area: right;
  padding: 10px;
}

.controls {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.controls label {
  font-weight: 700;
  color: #3f433f;
}

.controls-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  flex-wrap: nowrap;
}

.ref-select-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

input,
select,
button {
  font-family: "Assistant", sans-serif;
  font-size: 0.9rem;
  border-radius: 12px;
  padding: 6px 10px;
}

select,
input {
  min-width: 82px;
  border: 1px solid #d8cab0;
  background: #fffef9;
  color: #232734;
}

.ref-select-group select,
.ref-select-group input {
  min-width: 56px;
  width: 62px;
  text-align: center;
}

#masekhetSelect {
  min-width: 108px;
  width: 114px;
}

#sederSelect {
  min-width: 118px;
  width: 126px;
}

.nav-btn {
  min-width: 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: 0.94rem;
  background: linear-gradient(120deg, #2d677d 0%, #3f819c 100%);
}

button {
  border: 1px solid transparent;
  background: linear-gradient(120deg, var(--brand) 0%, #b05c3c 100%);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(164, 71, 47, 0.24);
}

button:hover {
  filter: brightness(0.96);
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.status:empty {
  display: none;
}

.status-inline {
  min-width: 0;
  font-size: 0.82rem;
  margin-inline-start: 6px;
}

.status[data-error="1"] {
  color: #a13333;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.panel-head a {
  color: var(--brand-2);
  text-decoration: none;
  font-weight: 700;
}

.panel-head a:hover {
  text-decoration: underline;
}

.main-text {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fff;
  border: 1px solid #e7dbc6;
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.main-text h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: #3c414d;
}

.main-text p {
  margin: 0;
  direction: rtl;
  text-align: right;
  line-height: 1.75;
  font-size: 1.22rem;
  font-family: "Frank Ruhl Libre", "Times New Roman", serif;
}

.sage-mention {
  border-bottom: 1px dotted rgba(31, 95, 122, 0.75);
  cursor: help;
  position: relative;
}

.sage-mention:hover {
  color: #1a5871;
}

.sage-tooltip-floating {
  position: fixed;
  z-index: 9999;
  min-width: 220px;
  max-width: 360px;
  white-space: pre-line;
  background: #1f2430;
  color: #fff;
  border-radius: 10px;
  padding: 7px 9px;
  font-family: "Assistant", sans-serif;
  font-size: 0.82rem;
  line-height: 1.35;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  display: none;
}

.counts {
  margin-bottom: 10px;
  color: var(--muted);
}

.side-left > h2,
#commentaryCounts {
  display: none;
}

.commentary-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.commentary-tab {
  border: 1px solid #d8c9b2;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.88rem;
  color: #413b2f;
  background: linear-gradient(180deg, #fff7ea 0%, #f7ecda 100%);
  cursor: pointer;
  box-shadow: none;
}

.commentary-tab.active {
  background: linear-gradient(180deg, #e8f3f8 0%, #d6eaf3 100%);
  border-color: rgba(31, 95, 122, 0.35);
  color: #1f5f7a;
}

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-left: 6px;
  display: grid;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.item {
  background: linear-gradient(180deg, #fff 0%, #fffaf2 100%);
  border: 1px solid #e5d8c2;
  border-radius: 12px;
  padding: 9px;
  box-shadow: 0 4px 14px rgba(68, 52, 28, 0.08);
}

.item h3 {
  margin: 0 0 6px;
  color: var(--brand-2);
  font-weight: 700;
  font-size: 0.92rem;
}

.commentary-item p {
  margin: 0;
  direction: rtl;
  text-align: right;
  line-height: 1.42;
  white-space: pre-line;
  font-family: "Frank Ruhl Libre", serif;
  font-size: 1.03rem;
}

.commentary-item p sup.footnote-marker {
  font-size: 0.72em;
  line-height: 0;
  vertical-align: super;
  color: #2e66b0;
  cursor: help;
}

.commentary-merged strong {
  color: var(--brand);
  font-weight: 700;
}

.commentary-merged h3 a {
  color: var(--brand-2);
  text-decoration: underline;
}

.parallels-group {
  display: grid;
  gap: 8px;
}

.parallels-group + .parallels-group {
  margin-top: 8px;
}

.parallels-group-title {
  margin: 0;
  color: #2d5f78;
  font-size: 1.02rem;
  font-weight: 700;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}

.manuscript-split {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.manuscript-window {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.manuscript-window h2 {
  margin-bottom: 6px;
}

.manuscript-viewer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
}

.manuscript-link {
  color: var(--brand-2);
  text-decoration: underline;
  font-size: 0.86rem;
}

.manuscript-viewport {
  flex: 1;
  min-height: 0;
  border: 1px solid #e5d8c2;
  border-radius: 12px;
  overflow: hidden;
  background: #f7f5ef;
  position: relative;
  cursor: grab;
}

.manuscript-empty {
  margin: 0;
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px solid #e5d8c2;
  border-radius: 12px;
  background: #fffdf8;
}

.manuscript-empty[hidden],
.manuscript-viewer[hidden] {
  display: none;
}

.manuscript-viewport:active {
  cursor: grabbing;
}

.manuscript-image {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: auto;
  transform-origin: top right;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
}

.thumb {
  text-decoration: none;
  color: inherit;
  border: 1px solid #e5d8c2;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #fff 0%, #fffaf2 100%);
}

.thumb img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.thumb-meta {
  padding: 8px;
  font-size: 0.88rem;
}

.badge {
  display: inline-block;
  margin-inline-start: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #f2dfbc;
  font-size: 0.75rem;
}

.empty {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "controls"
      "center"
      "centerBottom"
      "left"
      "right";
    height: 100vh;
  }

  select,
  input,
  button {
    min-width: 0;
    width: 100%;
  }

  .controls-panel {
    gap: 6px;
  }

  .controls-top {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }

  .controls-top h1 {
    white-space: normal;
  }

  .controls-meta {
    white-space: normal;
    margin-inline-start: 0;
  }

  .controls-row {
    display: flex;
    gap: 6px;
    justify-content: stretch;
  }

  .controls-center {
    justify-content: center;
    flex-wrap: wrap;
  }
}
