/* =============================================================================
 *  tts-ui.css
 *  Layout and spacing only.
 *
 *  Load it last, after style.css and tts-highlight.css:
 *      <link rel="stylesheet" href="style.css">
 *      <link rel="stylesheet" href="tts-highlight.css">
 *      <link rel="stylesheet" href="tts-ui.css">
 *
 *  YOUR COLOURS AND YOUR BACKGROUND ARE NOT TOUCHED. The black, the #FC1212
 *  red and the Matrix canvas are all yours and stay exactly as you wrote them.
 *  Everything below is structure: what goes where, how big, how much room
 *  around it, and what happens when the window is a different size.
 *
 *  What was wrong
 *  --------------
 *  The grid was 2fr 1fr by 1fr 1fr, so the right hand side was cut in half
 *  regardless of what was in it. Three transport buttons were given a quarter
 *  of the screen while the tab panel, which holds the dictionary, was squeezed
 *  into a strip too short to read. On a wide monitor the reading column also
 *  stretched to whatever width was going, and a line of text 1300px wide is
 *  genuinely hard to read: the eye loses its place on the way back to the left
 *  margin.
 *
 *  What it is now
 *  --------------
 *  A fixed header, a reading column with a comfortable measure, and a sidebar
 *  of a fixed sensible width. Inside the sidebar the panel takes all the room
 *  that is going and the transport is a compact strip at the bottom, because
 *  that is the space each actually needs. Your arrow key focus modes still
 *  work, they just resize to proportions that look deliberate.
 * ========================================================================== */


/* ---------------------------------------------------------------------------
 *  1. Spacing scale
 *  One set of numbers used everywhere, so nothing is arbitrary.
 * ------------------------------------------------------------------------ */
:root{
  --gap:        16px;
  --gap-sm:      8px;
  --gap-lg:     24px;
  --header-h:   64px;
  --sidebar-w: 400px;
  --measure:   780px;   /* the reading column, wide enough but not tiring */
  --radius:      8px;
}


/* ---------------------------------------------------------------------------
 *  1b. Phone dictionary panel
 *
 *  On a phone the dictionary slides up over the text. It inherits the 72%
 *  black surface, so the article shows through behind the definitions and
 *  the two fight for the eye. A near solid surface reads cleanly; the little
 *  transparency left keeps the rounded panel feeling like it sits on the page.
 * ------------------------------------------------------------------------ */
@media (max-width: 700px){
  /* Uses the theme's solid surface colour, so light themes stay light. The
     selector is one step more specific than the theme rule in page8.html
     (body .wrapper .box-right-1) or that rule would win. */
  body .wrapper .box-right-1.mobile-panel-open{
    /* The theme's panel colour can itself be translucent, so paint it over the
       theme's opaque page background: keeps the theme's tint, never see-through. */
    background:
      linear-gradient(var(--theme-panel, rgba(0,0,0,.9)), var(--theme-panel, rgba(0,0,0,.9))),
      var(--theme-background, #000) !important;
  }
}


/* ---------------------------------------------------------------------------
 *  2. The shell
 * ------------------------------------------------------------------------ */

.wrapper{
  /* Room for the fixed header, and breathing space at the edges. dvh follows
     the phone's real visible area as the address bar shows and hides; the vh
     line before it is the fallback for browsers without dvh. */
  height: 100vh !important;
  height: 100dvh !important;
  padding: calc(var(--header-h) + var(--gap)) var(--gap) var(--gap) !important;
  gap: var(--gap) !important;

  /* minmax(0,...) stops a long word forcing the column wider than the screen,
     which is what makes grids overflow sideways. */
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w) !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
}

/* Your focus modes, kept working, with proportions that look intentional. */
.wrapper.the_left  { grid-template-columns: minmax(0, 1fr) 62% !important; }
.wrapper.the_mid   { grid-template-columns: minmax(0, 1fr) 45% !important; }
.wrapper.the_right { grid-template-columns: minmax(0, 1fr) 0 !important; gap: 0 !important; }
.wrapper.the_right .box-right-1,
.wrapper.the_right .box-right-2{ display: none !important; }

/* Up and down collapse the transport strip rather than gutting the panel. */
.wrapper.collapsed_Down,
.wrapper.collapsed_up{ grid-template-rows: minmax(0, 1fr) auto !important; }
.wrapper.collapsed_up .box-right-2{ display: none !important; }


/* ---------------------------------------------------------------------------
 *  3. Header
 * ------------------------------------------------------------------------ */

#ui-bar{
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 1000;

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

  border-bottom: 1px solid var(--ui-red-line, rgba(252,18,18,.38));
  background: rgba(0,0,0,.82);
  backdrop-filter: blur(6px);
}

/* The native file input renders as a grey OS button reading "No file chosen"
   and cannot be styled. Hidden, and driven by the label instead. It keeps its
   id, so anything already listening to #file-picker is unaffected. */
#file-picker{
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.ui-btn{
  display: inline-flex;
  align-items: center;
  gap: var(--gap-sm);

  padding: 8px 16px;
  border-radius: var(--radius);

  font-family: monospace;
  font-size: 13px;
  letter-spacing: .3px;

  cursor: pointer;
  user-select: none;
  white-space: nowrap;

  color: #FC1212;
  background: rgba(252,18,18,.10);
  border: 1px solid rgba(252,18,18,.38);
  transition: background .18s, box-shadow .18s;
}
.ui-btn:hover{ background: rgba(252,18,18,.20); box-shadow: 0 0 12px rgba(252,18,18,.4); }

#ui-filename{
  flex: 1;
  min-width: 0;

  font-family: monospace;
  font-size: 12px;
  color: rgba(255,255,255,.45);

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#ui-filename.has-file{ color: rgba(255,255,255,.8); }

/* Read Page belongs in the header with the other global control, not floating
   over the text. */
.voice-btn{
  position: static !important;
  transform: none !important;
  flex: 0 0 auto;

  margin: 0 !important;
  padding: 8px 18px !important;
  border-radius: var(--radius) !important;

  font-family: monospace;
  font-size: 13px;
  letter-spacing: .3px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .18s, box-shadow .18s;
}
.voice-btn.is-reading{ box-shadow: 0 0 18px rgba(252,18,18,.5); }


/* ---------------------------------------------------------------------------
 *  4. Panels
 *
 *  All three sit on the same surface, which is the rgba(0,0,0,.75) already in
 *  your own .page rule. No new colour. It matters because the panels were
 *  partly transparent, so the Matrix rain showed through the control strips and
 *  everything read as clutter. The rain now shows in the gaps between panels,
 *  where it looks deliberate, instead of behind the text you are trying to use.
 * ------------------------------------------------------------------------ */

.container-left,
.box-right-1,
.box-right-2,
#controls{
  background: rgba(0, 0, 0, .75);
}
.container-left > .page{ background: transparent !important; }


.container-left{
  grid-column: 1;
  grid-row: 1 / span 2;

  display: flex !important;
  flex-direction: column;
  min-height: 0;
  min-width: 0;

  border-radius: var(--radius);
  overflow: hidden !important;
}

/* The sheet takes whatever is left after the page controls have had theirs.
   Without min-height:0 a flex child refuses to shrink below its content, which
   is what pushed the controls out through the bottom of the panel. */
.container-left > .page{ flex: 1 1 auto; min-height: 0; }
.container-left > #controls{ flex: 0 0 auto; }

/* Leftover scaffolding. It still contains the literal word "testing" from
   before, and it was taking up vertical space at the bottom of the reader,
   which is what squeezed the page controls off the edge. Hidden rather than
   deleted, in case you still want it for something. */
#word-container{ display: none !important; }

.page{
  /* The 1.02 scale pushed the sheet past its own container, which is what put
     the edges under the scrollbar. */
  transform: none !important;

  flex: 1;
  min-height: 0;
  width: 100% !important;
  height: auto !important;

  margin: 0 !important;
  padding: var(--gap-lg) var(--gap-lg) 0 !important;
  border: 0 !important;
  border-radius: var(--radius);

  display: flex;
  flex-direction: column;
}

.chapter-title{
  flex: 0 0 auto;
  max-width: var(--measure);
  width: 100%;
  margin: 0 auto 4px !important;
  font-size: 22px !important;

  /* Book titles come from the filename, and filenames have no spaces to break
     at, so a long one ran straight off the edge of the panel. */
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.3;
}
.divider{ flex: 0 0 auto; margin: 0 auto var(--gap-lg) !important; }

/* The measure. A line much wider than this is tiring to read, because the eye
   has to hunt for the start of the next line. */
.content{
  flex: 1;
  min-height: 0;

  width: 100%;
  max-width: var(--measure);
  margin: 0 auto !important;

  padding: 0 var(--gap-sm) var(--gap-lg) 0;
  font-size: 17px !important;
  line-height: 1.75 !important;
}

/* Page controls sit under the text instead of floating over it. */
#controls{
  position: static !important;
  transform: none !important;

  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-lg);

  padding: 12px 0;
  margin: 0 auto;
  width: 100%;
  max-width: var(--measure);

  border-top: 1px solid rgba(252,18,18,.18);
}

.key{
  width: 38px !important;
  height: 38px !important;
  border-radius: var(--radius) !important;
  font-family: monospace;
  font-size: 15px;
  transition: background .18s, box-shadow .18s;
}

#page-number{
  min-width: 78px !important;
  font-family: monospace;
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(255,255,255,.45);
}

/* Those floating chevrons overlapped the text and duplicated the page keys. */
.arrow{ display: none !important; }


/* ---------------------------------------------------------------------------
 *  5. Sidebar
 * ------------------------------------------------------------------------ */

.box-right-1{
  grid-column: 2;
  grid-row: 1;

  display: flex !important;
  flex-direction: column;
  min-height: 0;

  padding: var(--gap) !important;
  border-radius: var(--radius);
  overflow: hidden;
}

.box-right-2{
  grid-column: 2;
  grid-row: 2;

  /* A strip the size of its buttons. It used to take a quarter of the screen
     to hold three of them. */
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: var(--gap-lg);

  padding: 10px !important;
  border-radius: var(--radius);
}

.tabs{
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  margin: 0 0 var(--gap) !important;
  padding-bottom: var(--gap-sm);
  border-bottom: 1px solid rgba(252,18,18,.25);
}

.tabButton{
  flex: 1;
  padding: 8px 4px !important;
  border-radius: 6px !important;

  font-family: monospace;
  font-size: 11.5px;
  letter-spacing: .6px;
  text-transform: uppercase;

  cursor: pointer;
  background: transparent !important;
  border: 1px solid transparent !important;
  color: rgba(255,255,255,.45) !important;
  transition: color .18s, background .18s, border-color .18s;
}
.tabButton:hover{
  color: #FC1212 !important;
  background: rgba(252,18,18,.10) !important;
  border-color: rgba(252,18,18,.30) !important;
}
.tabButton.is-active{
  color: #FC1212 !important;
  background: rgba(252,18,18,.12) !important;
  border-color: rgba(252,18,18,.55) !important;
}

/* Whichever panel is open fills the sidebar and scrolls inside itself. */
.tabContent{
  flex: 1;
  min-height: 0;
  max-height: none !important;
  overflow-y: auto;
  border-radius: 6px;
}

#tab2{ padding: var(--gap) !important; }

#chatHistory{ flex: 1; min-height: 0; border-radius: 6px; }
.chatbox{ flex: 0 0 auto; border-radius: 6px; gap: var(--gap-sm); }
.chatbox input{ flex: 1; min-width: 0; }

/* These were invisible. .box-right-2 sets color:black and the buttons inherit
   it, so three black icons were sitting on a black panel. Same red you already
   use everywhere else, nothing new introduced. */
.box-right-2 .buttonsound,
.box-right-2 .buttonsound i{
  color: #FC1212 !important;
  font-size: 18px;
}
.buttonsound{
  padding: 8px 14px;
  border-radius: 6px;
  line-height: 1;
  transition: background .18s, box-shadow .18s, transform .1s;
}
.buttonsound:hover{ background: rgba(252,18,18,.14); }
.buttonsound:active{ transform: translateY(1px); }


/* ---------------------------------------------------------------------------
 *  6. Right click menu
 * ------------------------------------------------------------------------ */

/* Your rule gives this a white background. With white labels everywhere that
   left white on white, so the Define item vanished. Dark, like every other
   surface in the app. */
#contextMenu{
  background: rgba(12, 4, 4, .97) !important;
  border: 1px solid rgba(252, 18, 18, .45) !important;
  border-radius: 5px;
  overflow: hidden;
  font-family: monospace;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .8);
}
#defineItem{
  padding: 9px 18px !important;
  cursor: pointer;
  transition: background .15s;
}
#defineItem:hover{ background: rgba(252, 18, 18, .22); }


/* ---------------------------------------------------------------------------
 *  7. Smaller screens
 *  Below a laptop width, side by side stops working: neither column gets
 *  enough room. The sidebar moves under the reader instead.
 * ------------------------------------------------------------------------ */

@media (max-width: 1100px){
  :root{ --sidebar-w: 340px; --measure: 640px; }
}

@media (max-width: 900px){

  /* Your stylesheet locks the document with overflow:hidden, which is right
     for the side by side desktop view: each panel scrolls inside itself and
     the page never moves. Stacked on a phone it is fatal. The three panels
     together are taller than the screen, and with the document unable to
     scroll they had nowhere to go, so the reader spilled straight over the
     dictionary. On a narrow screen the page itself has to scroll. */
  html, body{
    overflow: auto !important;
    height: auto !important;
  }

  .wrapper{
    height: auto !important;
    min-height: 100vh;
    min-height: 100dvh;

    grid-template-columns: minmax(0, 1fr) !important;
    /* auto, not 1fr. Each panel is as tall as it needs and the page scrolls,
       rather than three panels fighting over one screen. */
    grid-template-rows: auto auto auto !important;
  }

  .wrapper.the_left,
  .wrapper.the_mid,
  .wrapper.the_right{ grid-template-columns: minmax(0, 1fr) !important; }
  .wrapper.the_right .box-right-1,
  .wrapper.the_right .box-right-2{ display: flex !important; }

  .container-left{ grid-column: 1; grid-row: 1; height: 72vh; }
  .box-right-1{ grid-column: 1; grid-row: 2; height: 62vh; }
  .box-right-2{ grid-column: 1; grid-row: 3; }

  /* The Matrix canvas is already position:fixed, so it stays put behind the
     content while the page scrolls. */

  #ui-bar{ gap: var(--gap-sm); }
  #ui-filename{ display: none; }
}

@media (max-width: 560px){
  :root{ --gap: 10px; --gap-lg: 14px; --header-h: 56px; }
  .page{ padding: var(--gap) var(--gap) 0 !important; }
  .content{ font-size: 16px !important; }
  .ui-btn, .voice-btn{ padding: 7px 12px !important; font-size: 12px !important; }
}

/* ---------------------------------------------------------------------------
 *  8. Buttons, one rule for all of them
 *
 *  5px corners, 14px, bold, everywhere. Kept in a single block at the end so
 *  there is one place to change it, rather than the same three values repeated
 *  across six selectors and drifting apart later.
 * ------------------------------------------------------------------------ */

.ui-btn,
.voice-btn,
.tabButton,
.key,
.buttonsound,
.buttonsound i,
#defineItem,
.dictionary-audio-button,
.chatbox button,
#sendBtn,
#chat_history,
.tabButton.is-active,
.box-right-2 .buttonsound,
.box-right-2 .buttonsound i{
  border-radius: 5px !important;
  font-size: 14px !important;
  font-weight: 700 !important;

  /* White label on every button. The red is kept for the borders, the fills
     and the glow, which is where it does the work of tying the interface
     together. On the text itself it was costing legibility for nothing:
     #FC1212 on a near black panel is a weak contrast to read a word through,
     and it made the buttons compete with the highlighted word in the text,
     which is the one thing on screen that should be pulling the eye. */
  color: #fff !important;
}

/* The icon buttons carry Font Awesome glyphs rather than text, and a glyph set
   to 14px reads noticeably smaller than a letter at 14px. Nudged so they sit at
   the same visual weight as everything else. */
.box-right-2 .buttonsound,
.box-right-2 .buttonsound i,
.key{
  font-size: 16px !important;
  color: #fff !important;
}

/* Placeholder stays dimmed. It is not a label, it is a hint, and at full white
   it reads as text someone already typed. */
.chatbox input::placeholder,
#userInput::placeholder{ color: rgba(255, 255, 255, .38) !important; }

/* ---------------------------------------------------------------------------
 *  9. Chat panel
 *
 *  Two problems. The history box was #f5f5f5 with dark text, so a light card
 *  was sitting inside a black app, and the input row was raw browser default:
 *  a white box and two grey OS buttons of different sizes.
 *
 *  Both panels are dark now with white text, so Chat and Dictionary match each
 *  other instead of one looking borrowed from another site.
 * ------------------------------------------------------------------------ */

#chatHistory{
  background: rgba(0, 0, 0, .45) !important;
  border: 1px solid rgba(252, 18, 18, .22) !important;
  border-radius: 5px;
  box-shadow: none !important;

  padding: 14px !important;
  color: #fff;
  font-size: 14px;
  line-height: 1.6;
}

/* Speech bubbles, so the two sides of a conversation are distinguishable. */
.speechBubble{
  max-width: 88%;
  margin: 0 0 10px !important;
  padding: 10px 13px !important;
  border-radius: 5px;

  color: #fff;
  font-size: 14px;
  line-height: 1.55;
}
.speechBubble.assistant{
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .10);
}
.speechBubble.user{
  margin-left: auto !important;
  background: rgba(252, 18, 18, .16);
  border: 1px solid rgba(252, 18, 18, .35);
}

/* ---- the input row ---- */

.chatbox{
  display: flex;
  align-items: stretch;
  gap: 8px;

  margin-top: 12px !important;
  padding: 0 !important;

  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.chatbox input,
#userInput{
  flex: 1;
  min-width: 0;

  height: 38px;
  padding: 0 12px;

  background: rgba(0, 0, 0, .55);
  border: 1px solid rgba(252, 18, 18, .28);
  border-radius: 5px;

  color: #fff;
  font-family: monospace;
  font-size: 14px;

  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.chatbox input::placeholder,
#userInput::placeholder{ color: rgba(255, 255, 255, .35); }

.chatbox input:focus,
#userInput:focus{
  border-color: rgba(252, 18, 18, .75);
  box-shadow: 0 0 0 3px rgba(252, 18, 18, .14);
}

/* One filled button for the main action, one outlined for the secondary one,
   so it is obvious which is which. They were identical grey before. */
.chatbox button{
  height: 38px;
  padding: 0 16px;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
  font-family: monospace;
  transition: background .18s, box-shadow .18s, transform .1s;
}
.chatbox button:active{ transform: translateY(1px); }

#sendBtn{
  background: #FC1212 !important;
  border: 1px solid #FC1212 !important;
  color: #fff !important;
}
#sendBtn:hover{ box-shadow: 0 0 14px rgba(252, 18, 18, .5); }

#chat_history{
  background: rgba(252, 18, 18, .10) !important;
  border: 1px solid rgba(252, 18, 18, .38) !important;
  color: #fff !important;
}
#chat_history:hover{ background: rgba(252, 18, 18, .20) !important; }


/* ---------------------------------------------------------------------------
 *  10. Dictionary panel
 *
 *  Same reasoning as the chat history. It was a light card in a dark app.
 *  Dark surface, white text, and his .dictionary-* structure untouched.
 * ------------------------------------------------------------------------ */

#tab2{
  background: rgba(0, 0, 0, .45) !important;
  border: 1px solid rgba(252, 18, 18, .22);
  border-radius: 5px;
  color: #fff;
}

#tab2 .dictionary-entry h2{
  color: #fff;
  font-size: 19px;
  margin-bottom: 10px !important;
}
#tab2 .dictionary-sense-group{
  border-bottom-color: rgba(255, 255, 255, .12) !important;
}
#tab2 .dictionary-sense-group h3{
  color: #FC1212;
  font-size: 13px;
  letter-spacing: .5px;
}
#tab2 .dictionary-section strong{ color: rgba(255, 255, 255, .95); }
#tab2 .dictionary-section,
#tab2 .dictionary-section p,
#tab2 .dictionary-section li{
  color: rgba(255, 255, 255, .88);
  font-size: 14px;
  line-height: 1.6;
}
#tab2 .dictionary-tags span{
  background: rgba(255, 255, 255, .10) !important;
  color: rgba(255, 255, 255, .75);
  border-radius: 5px;
  font-size: 12px;
}
#tab2 .dictionary-examples blockquote{
  border-left-color: rgba(252, 18, 18, .5) !important;
  color: rgba(255, 255, 255, .88);
}
#tab2 .dictionary-examples blockquote div{ color: rgba(255, 255, 255, .55); }
/* This one had no background of its own, so it fell back to the browser's
   default light grey button, and white text on light grey is unreadable.
   Same dark treatment as every other secondary button. */
#tab2 .dictionary-audio-button,
.dictionary-audio-button{
  background: rgba(252, 18, 18, .12) !important;
  border: 1px solid rgba(252, 18, 18, .38) !important;
  padding: 7px 12px !important;
  cursor: pointer;
  transition: background .18s;
}
#tab2 .dictionary-audio-button:hover,
.dictionary-audio-button:hover{ background: rgba(252, 18, 18, .24) !important; }

#tab2 em{ color: rgba(255, 255, 255, .6); }
#tab2 code{ color: #FC1212; }

/* ---------------------------------------------------------------------------
   Getting out of the reader and into practice.

   Deliberately quiet. It sits with the read button rather than competing with
   it, because the reading is the point and the practice is what you do when
   you decide to stop reading.
   ------------------------------------------------------------------------ */
.reader-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-left: auto;
}

.reader-nav a {
  padding: 6px 12px;
  border: 1px solid rgba(252, 18, 18, .45);
  border-radius: 5px;
  color: #fff;
  background: rgba(0, 0, 0, .6);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: .18s;
}

.reader-nav a:hover,
.reader-nav a:focus-visible {
  background: #FC1212;
  box-shadow: 0 0 12px rgba(252, 18, 18, .8);
  outline: none;
}

#deckCount { opacity: .7; font-weight: 400; }

@media (max-width: 560px) {
  .reader-nav { width: 100%; margin-left: 0; }
  .reader-nav a { flex: 1; text-align: center; }
}
