/* =========================================================
   ui.css — KOSUTH VARIANT (DEFINITION PANELS)
   Conceptual, didactic, text-as-object.
   White gallery walls, black rules, monospaced taxonomy.
   No translucent overlays. No images under text.
   Mobile: tabs + theme switcher never overflow screen.
   ========================================================= */


/* =========================
   TOKENS / BASE
   ========================= */

:root {
  /* Kosuth: text is the medium → monospace */
  --font-body: ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace;

  /* Gallery palette */
  --wall: #ffffff;
  --ink: #111111;

  /* Accents (sparingly used for state) */
  --accent: #111111;      /* active black */
  --hover:  #e6e6e6;      /* paper gray */

  /* Scale */
  --ui-border: 2px;       /* strict line */
  --ui-gap: 12px;

  --ui-h: 48px;
  --ui-h-mobile: 42px;

  --ui-pad: 18px;
  --ui-pad-mobile: 14px;

  --content-max: 820px;

  /* Tabs bar (fixed) */
  --tabs-pad-y: 8px;
  --tabs-pad-x: 16px;
  --tabs-h: var(--ui-h);
  --tabs-rule-gap: 8px;
  --tabs-bar-h: calc(
    (var(--tabs-pad-y) * 2) + var(--tabs-h) + var(--tabs-rule-gap) + var(--ui-border)
  );

  /* Tool sizing + hard safety so it can never exceed viewport */
  --tabs-tool-w: 132px;
  --tabs-tool-gap: 10px;
  --tabs-safe-pad: 6px;
  --tabs-tool-max: calc(100vw - (var(--tabs-safe-pad) * 2));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wall);
  font: 400 16px/1.6 var(--font-body);
  letter-spacing: 0.01em;
}

/* No decorative wallpapers in Kosuth mode */
body::before,
body::after {
  content: none !important;
}

/* Content layer — keep close to the fixed “label” (tabs) */
#root {
  min-height: 100vh;
  padding: calc(var(--tabs-bar-h) + 6px) 16px 28px;
}


/* =========================
   TABS — “LABELS FOR WORKS”
   Fixed, opaque, like museum labels in a row.
   ========================= */

.custom-tabs .nav-tabs,
.custom-tabs.nav-tabs {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;

  margin: 0 !important;
  padding: var(--tabs-pad-y) var(--tabs-pad-x) 0 !important;

  display: flex;
  align-items: center;
  gap: var(--ui-gap);

  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;

  background: var(--wall); /* opaque */
  border-bottom: 0 !important;

  /* underline = assertion line */
  box-shadow: 0 var(--ui-border) 0 0 var(--ink);
  scrollbar-width: none;

  /* keep sticky-right tools clipped inside the bar */
  max-width: 100vw;
  box-sizing: border-box;
  contain: layout paint;
}

.custom-tabs .nav-tabs::-webkit-scrollbar,
.custom-tabs.nav-tabs::-webkit-scrollbar {
  display: none;
}

/* additional bottom rule */
.custom-tabs .nav-tabs::after,
.custom-tabs.nav-tabs::after {
  content: "";
  display: block;
  width: 100%;
  height: var(--ui-border);
  margin-top: var(--tabs-rule-gap);
  background: var(--ink);
  flex: 0 0 100%;
}

/* Each tab = a catalogue card */
.custom-tabs .nav-tabs > .nav-item,
.custom-tabs.nav-tabs > .nav-item {
  flex: 0 0 auto;
}

.custom-tabs .nav-link,
.custom-tabs .nav-link:visited {
  background: var(--wall);
  color: var(--ink) !important; /* override Bootstrap blue */
  border: var(--ui-border) solid var(--ink) !important;
  border-radius: 0 !important;

  height: var(--tabs-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 0 14px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Inactive hover: gray paper, still black text (no blue) */
.custom-tabs .nav-link:not(.active):hover,
.custom-tabs .nav-link:not(.active):focus {
  background: var(--hover);
  color: var(--ink) !important;
  text-decoration: none;
}

/* Active: solid black with white text */
.custom-tabs .nav-link.active,
.custom-tabs .nav-link.active:hover,
.custom-tabs .nav-link.active:focus {
  background: var(--accent) !important;
  color: #ffffff !important;
  text-decoration: none;
}

@media (max-width: 576px) {
  :root {
    --tabs-h: var(--ui-h-mobile);
    --tabs-bar-h: calc(
      (var(--tabs-pad-y) * 2) + var(--tabs-h) + var(--tabs-rule-gap) + var(--ui-border)
    );
    --tabs-tool-w: 118px; /* tighter tool on phones */
  }

  .custom-tabs .nav-tabs,
  .custom-tabs.nav-tabs {
    padding-left: 8px !important;
    padding-right: 8px !important;
    gap: 8px;
  }

  .custom-tabs .nav-link,
  .custom-tabs .nav-link:visited {
    padding: 0 10px;
    font-size: 0.9rem;
  }
}


/* =========================
   VERSE BOX — “DEFINITION PANEL”
   A bordered panel with title line and body text.
   ========================= */

.verseBox {
  width: min(100%, var(--content-max));
  margin: clamp(6px, 2vh, 20px) auto 0;
  padding: var(--ui-pad);

  background: var(--wall);
  border: var(--ui-border) solid var(--ink);
  border-radius: 0;

  position: relative;
}

/* Top rule = title separator */
.verseBox::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--ui-border);
  background: var(--ink);
}

/* No corner decorations; conceptual austerity */
.verseBox::after {
  content: none;
}

.verseTitle {
  margin: 0 0 8px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0.02em;
  /* emulate a dictionary headword */
}

.verseText {
  line-height: 1.75;
  word-wrap: break-word;
}
/* Verse tab: no-wrap + horizontal scroll only when needed */
.verseBox--nowrap .verseText{
  white-space: nowrap;
  overflow-x: auto;
}

.verseTop {
  margin-top: 6px;
}
.verseBottom {
  margin-top: 12px;
}


/* =========================
   BUTTONS — “INSTRUCTION PLAQUES”
   ========================= */

.u-btn {
  border-radius: 0 !important;
  box-shadow: none !important;

  background: var(--wall) !important;
  color: var(--ink) !important;
  border: var(--ui-border) solid var(--ink) !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;

  width: 100%;
  max-width: min(92vw, 900px);
  height: var(--ui-h);
  padding: 0 14px;
}

.u-btn:hover {
  background: var(--hover) !important;
}

.u-btn:active {
  background: var(--accent) !important;
  color: #ffffff !important;
}

.u-btn--wide {
  max-width: min(92vw, 1040px);
}

.u-btn--square {
  width: var(--ui-h);
  max-width: var(--ui-h);
  padding: 0;
}

@media (max-width: 576px) {
  .u-btn {
    height: var(--ui-h-mobile);
  }
  .u-btn--square {
    width: var(--ui-h-mobile);
    max-width: var(--ui-h-mobile);
  }
}


/* =========================
   TRIANGLE BUTTON — “DIRECTION MARK”
   ========================= */

.tri-btn {
  --box: var(--ui-h);

  width: var(--box);
  height: var(--box);
  border: var(--ui-border) solid var(--ink);
  border-radius: 0;
  background: var(--wall);
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tri-btn::before {
  content: "";
  width: 0;
  height: 0;
  border-top: calc(var(--box) * 0.26) solid transparent;
  border-bottom: calc(var(--box) * 0.26) solid transparent;
}

.tri-btn--left::before {
  border-right: calc(var(--box) * 0.36) solid var(--ink);
}
.tri-btn--right::before {
  border-left: calc(var(--box) * 0.36) solid var(--ink);
}

.tri-btn:hover {
  background: var(--hover);
}

.tri-btn:active {
  background: var(--accent);
}

.tri-btn:active.tri-btn--left::before,
.tri-btn:active.tri-btn--right::before {
  border-color: #ffffff;
}

@media (max-width: 576px) {
  .tri-btn {
    --box: var(--ui-h-mobile);
  }
}


/* =========================
   AUDIO — “REFERENCE OBJECT”
   ========================= */

.audio-box {
  width: 100%;
}

.audio-frame {
  width: 100%;
  border: var(--ui-border) solid var(--ink);
  border-radius: 0;
  overflow: hidden;
  background: var(--wall);
}

.audio-frame:hover {
  background: var(--hover);
}

.audio-frame:focus-within {
  outline: var(--ui-border) solid var(--ink);
  outline-offset: -2px;
}

.square-audio {
  width: 100%;
  display: block;
  border-radius: 0 !important;
}

.square-audio::-webkit-media-controls-enclosure,
.square-audio::-webkit-media-controls-panel {
  border-radius: 0 !important;
}


/* =========================
   CONTROLS BAR — “FOOTNOTE RULE”
   ========================= */

.controlsBar {
  display: grid;
  grid-template-columns: var(--ui-h) minmax(0, 1fr) var(--ui-h);
  gap: var(--ui-gap);
  align-items: center;
  width: 100%;

  margin-top: 12px;
  padding-top: 10px;

  border-top: var(--ui-border) solid var(--ink);
  position: relative;
}

.controlsBar > * {
  min-width: 0;
}

.controlsBar .u-btn {
  max-width: none;
  width: 100%;
  justify-self: stretch;
}

@media (max-width: 576px) {
  .controlsBar {
    grid-template-columns: var(--ui-h-mobile) minmax(0, 1fr) var(--ui-h-mobile);
    padding-top: 8px;
    margin-top: 10px;
  }
}


/* =========================
   TABS + TOOLS (Theme switcher)
   Mobile-safe: never overflow viewport
   ========================= */

.tabsWithTools {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  width: 100%;
}

/* The tool container (not a tab) — sticky-right, clipped */
.tabsWithTools .tabsTool {
  flex: 0 0 auto;
  display: flex;
  align-items: center;

  margin-left: var(--tabs-tool-gap);

  position: sticky;
  right: 0;

  background: var(--wall);
  padding-left: var(--tabs-tool-gap);
  padding-right: var(--tabs-safe-pad);

  max-width: var(--tabs-tool-max);
  overflow: hidden;
}

/* Give sticky tool space so it doesn't cover the last tab */
.custom-tabs .nav-tabs.tabsWithTools,
.custom-tabs.nav-tabs.tabsWithTools {
  padding-right: calc(
    var(--tabs-pad-x) + min(var(--tabs-tool-w), var(--tabs-tool-max)) + var(--tabs-tool-gap)
  ) !important;
}


/* =========================
   THEME SWITCHER (KOSUTH) — refined + mobile-safe
   ========================= */

.themeSwitch {
  /* Never exceed viewport */
  width: min(var(--tabs-tool-w), var(--tabs-tool-max));
  max-width: 100%;

  height: var(--tabs-h);

  border-radius: 0;
  border: var(--ui-border) solid var(--ink);
  background: var(--wall);
  color: var(--ink);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1;

  cursor: pointer;
  user-select: none;

  padding: 0 12px;

  /* Don't let label force overflow */
  min-width: 0;
  overflow: hidden;

  transition:
    background-color 120ms linear,
    color 120ms linear,
    transform 90ms linear,
    outline-color 120ms linear;
  -webkit-tap-highlight-color: transparent;
}

/* Minimal “index mark” square — conceptual pointer */
.themeSwitch::before {
  content: "";
  width: 10px;
  height: 10px;
  background: var(--ink);
  display: inline-block;
  flex: 0 0 auto;
}

/* Hover: gray paper */
.themeSwitch:hover {
  background: var(--hover);
}

/* Active: invert (black label) */
.themeSwitch:active {
  background: var(--accent);
  color: #ffffff;
  transform: translate(2px, 2px);
}

.themeSwitch:active::before {
  background: #ffffff;
}

/* Keyboard focus: strict outline, no glow */
.themeSwitch:focus-visible {
  outline: var(--ui-border) solid var(--ink);
  outline-offset: 3px;
}

.themeSwitch__label {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile: tighten a bit */
@media (max-width: 576px) {
  .themeSwitch {
    gap: 8px;
    padding: 0 10px;
  }

  .themeSwitch__label {
    font-size: 0.9rem;
  }
}

/* =========================================================
   UNIFIED LAYOUT CONTRACT
   Keeps each theme’s visuals intact; standardizes page padding
   and VerseBox placement across themes.
   Requested: VerseBox left edge ~15vw (not 25vw).
   ========================================================= */

:root{
  /* Unified reading width (used by VerseBox) */
  --content-max: 820px;

  /* Unified page side padding */
  --page-pad-x: 32px;
  --page-pad-x-mobile: 14px;

  /* VerseBox anchor */
  --versebox-edge: 15vw;
  --versebox-left: clamp(0px, calc(var(--versebox-edge) - var(--page-pad-x)), 240px);
  --versebox-top: clamp(0px, 6vh, 56px);
}

@media (max-width: 576px){
  :root{ --page-pad-x: var(--page-pad-x-mobile); }
}

/* Normalize root side padding without touching top/bottom reserves */
#root{
  padding-left: var(--page-pad-x);
  padding-right: var(--page-pad-x);
}

/* VerseBox: unified width + consistent top spacing */
.verseBox{
  width: min(100%, var(--content-max));
  margin-top: var(--versebox-top);
}

/* Desktop: anchor from the left (edge starts ~15vw) */
@media (min-width: 992px){
  .verseBox{
    margin-left: var(--versebox-left);
    margin-right: auto;
  }
}

/* Phones: no horizontal offset */
@media (max-width: 576px){
  .verseBox{
    margin-left: 0;
    margin-right: 0;
    margin-top: 0;
  }
}


/* =========================================================
   MOBILE TIGHTENING — TAB GAPS (UNIFIED)
   Narrower gaps between tabs, and between tabs & theme switch,
   only on smartphone screens.
   ========================================================= */

@media (max-width: 576px) {
  :root{
    /* unify the “tool reserve” math while keeping theme visuals intact */
    --tabs-tool-gap: 6px;
  }

  /* Narrower gaps between tab buttons */
  .custom-tabs .nav-tabs,
  .custom-tabs.nav-tabs{
    gap: 6px !important;
  }

  /* Narrower gap between tabs row and the tool area (theme switch) */
  .tabsWithTools .tabsTool{
    margin-left: 0 !important;  /* avoid double-spacing on mobile */
    padding-left: 6px !important;
  }

  /* Keep end-of-row reserve consistent with the new tool gap */
  .custom-tabs .nav-tabs.tabsWithTools,
  .custom-tabs.nav-tabs.tabsWithTools{
    padding-right: calc(
      var(--tabs-pad-x, 12px)
      + min(var(--tabs-tool-w, 116px), var(--tabs-tool-max, 100vw))
      + var(--tabs-tool-gap, 6px)
    ) !important;
  }
}

/* =========================================================
   FIXED READER FRAME — TABS + BOTTOM CONTROLS (UNIFIED)
   Goal:
   - Tabs already fixed at top.
   - Fix bottom navigation + “This is not poetry” to viewport bottom
     (wide → smartphone).
   - Make the VerseBox the scroll container so the frame/background stays fixed.
   Notes:
   - Visual style (colors/textures) is NOT changed here — only layout behavior.
   ========================================================= */

:root{
  /* iOS/Android safe areas */
  --safe-top: max(env(safe-area-inset-top), 0px);
  --safe-bottom: max(env(safe-area-inset-bottom), 0px);

  /* Left anchor for fixed-position elements (true viewport coordinates) */
  --frame-left: clamp(var(--page-pad-x), var(--versebox-edge, 20vw), 360px);

  /* Estimated rails height for the fixed tabs bar (safe, theme-agnostic) */
  --tabs-rail-h: calc(var(--ui-h, 52px) + (var(--tabs-pad-y, 8px) * 2));
  --tabs-rail-h-mobile: calc(var(--ui-h-mobile, 44px) + (var(--tabs-pad-y, 8px) * 2));

  /* Bottom controls bar occupies roughly a control height + rule/padding */
  --controls-rail-h: calc(var(--ui-h, 52px) + 16px + var(--ui-border, 2px));
  --controls-rail-h-mobile: calc(var(--ui-h-mobile, 44px) + 14px + var(--ui-border, 2px));

  /* Frame top offset: tabs rail + small breathing room */
  --frame-top: calc(var(--tabs-rail-h) + 8px + var(--safe-top));
  --frame-bottom-pad: calc(var(--controls-rail-h) + env(safe-area-inset-bottom));
}

@media (max-width: 576px){
  :root{
    --frame-left: var(--page-pad-x);
    --frame-top: calc(var(--tabs-rail-h-mobile) + 6px);
    --frame-bottom-pad: calc(var(--controls-rail-h-mobile) + env(safe-area-inset-bottom));
  }
}

/* Lock the page: scrolling happens inside the VerseBox */
html, body, #root{
  height: 100%;
}

body{
  overflow: hidden;
}

/* VerseBox becomes the fixed reading frame (scroll container) */
.verseBox{
  position: fixed !important;

  top: var(--frame-top) !important;
  bottom: var(--safe-bottom) !important;

  left: var(--frame-left) !important;
  width: min(calc(100vw - var(--frame-left) - var(--page-pad-x)), var(--content-max)) !important;

  margin: 0 !important;

  /* scrolling content, fixed background/frame */
  overflow: auto !important;
  overscroll-behavior: contain;

  /* keep last lines visible above the fixed bottom controls */
  padding-bottom: calc(var(--ui-pad, 20px) + var(--frame-bottom-pad)) !important;

  /* smooth iOS scroll */
  -webkit-overflow-scrolling: touch;
}

/* Bottom controls: pinned to viewport bottom and aligned with the VerseBox */
.controlsBar{
  position: fixed !important;
  bottom: var(--safe-bottom) !important;

  left: var(--frame-left) !important;
  width: min(calc(100vw - var(--frame-left) - var(--page-pad-x)), var(--content-max)) !important;

  margin: 0 !important;

  z-index: 1050;

  padding: 12px 0 14px;
  /* OPAQUE PLATE (prevents text showing through) */
  background: var(--wall) !important;
  isolation: isolate;
  border-top: var(--ui-border) solid var(--ink);

  opacity: 1;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;

  box-sizing: border-box;
  max-width: 100vw;
}
/* =========================================================
   WIDE-SCREEN CONTROLS LAYOUT — VARIANT 3
   Sticky bottom rail: controls stay reachable while reading.
   ========================================================= */

@media (min-width: 768px) {
  .controlsBar {
    position: sticky;
    bottom: 0;
    z-index: 30;

    margin-top: 18px;
    padding: 12px 0 14px;

    background: var(--wall);
    border-top: 0;

    /* Subtle separation from content while keeping themes intact */
    box-shadow: 0 -10px 0 rgba(0,0,0,0.04);
  }

  .controlsBar::before {
    display: none;
  }

  .controlsBar .u-btn {
    width: 100%;
  }
}
