/* =========================================
   1. ROOT VARIABLES (Defaults / Light Mode)
   ========================================= */
:root {
  /* System Font Lock (Used for UI elements that shouldn't change with themes) */
  --sys-font:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;

  /* Typography Settings */
  --font-family: var(--sys-font);
  --font-base-size: 16px;
  --line-height: 1.5;

  /* App Shell Colors */
  --bgCol: #eef2f7;
  --txtCol: #0e5a82;
  --dirBgCol: #ededed;
  --border-color: #dddddd;

  /* Content Area Colors */
  --content-bg: #ffffff;
  --content-txt: #222222;
  --content-notes-bg: #f5f5f5;
  --content-notes-txt: #333333;

  /* Spacing */
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 2rem;

  --col1: hsl(38, 84%, 40%);
  --col2: hsl(122, 34%, 40%);
  --col3: hsl(341, 73%, 43%);
  --col4: hsl(202, 94%, 60%);
  --col5: hsl(202, 100%, 24%);
  --col6: hsl(84, 49%, 52%);
  --col7: hsl(59, 100%, 75%);
}

/* =========================================
   2. DARK & LIGHT MODE OVERRIDES
   ========================================= */
@media (prefers-color-scheme: dark) {
  :root {
    --content-bg: #121212;
    --content-txt: #eeeeee;
    --content-notes-bg: #232323;
    --content-notes-txt: #dddddd;
    --border-color: #333333;
  }
}

/* Added 'html' to guarantee higher specificity than :root */
html[data-theme="dark"] {
  --content-bg: #121212;
  --content-txt: #eeeeee;
  --content-notes-bg: #232323;
  --content-notes-txt: #dddddd;
  --border-color: #333333;
}

/* Added 'html' to guarantee higher specificity than :root */
html[data-theme="light"] {
  --content-bg: #ffffff;
  --content-txt: #222222;
  --content-notes-bg: #eeeeee;
  --content-notes-txt: #333333;
  --border-color: #dddddd;
}

/* =========================================
   3. MODERN CSS RESET & UTILITIES
   ========================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  height: 100%;
  overflow: hidden;
}

ul,
ol {
  list-style: none;
}
img,
picture,
svg {
  display: block;
  max-width: 100%;
}
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

.flex {
  display: flex;
}
.fl-col {
  flex-direction: column;
}
.fl-middle {
  align-items: center;
}
.fl-space-between {
  justify-content: space-between;
}
.fl-wrap {
  flex-wrap: wrap;
}
.fl1 {
  flex: 1;
}
.hidden {
  display: none !important;
}

/* =========================================
   4. BASE STYLES & APP LAYOUT
   ========================================= */
body {
  background-color: var(--bgCol);
  color: var(--txtCol);
  font-family: var(--font-family);
  font-size: var(--font-base-size);
  line-height: var(--line-height);
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-container {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100%;
}

.main-content {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* =========================================
   5. FOOTER & BRANDING
   ========================================= */
.main-footer * {
  color: var(--txtCol);
  -webkit-user-select: none;
  user-select: none;
}

.footer-nav {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.5rem;
  padding: 5px 20px;
  width: 100%;
}

/* Update the branding to sit naturally in the layout */
.branding {
  font-size: 22px;
  font-weight: 200;
  letter-spacing: 2px;
  opacity: 0.6;
  margin: 0 0 15px 15px; /* Adds space under it and aligns it with the list */
  display: flex;
  align-items: center;
  flex-shrink: 0; /* Prevents it from getting squished */
  color: var(--txtCol);
}
.branding::after {
  content: var(--version);
  margin-left: 8px;
  font-size: 16px;
}
.branding.standalone {
  opacity: 1;
}
.branding.standalone::before {
  content: "SA";
  font-size: 12px;
  margin-right: 4px;
}

/* =========================================
   6. SHARED PANEL STYLES
   ========================================= */
#index-panel,
#display-panel,
#notes-panel {
  overflow-y: auto;
  height: 100%;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  padding: 1rem;
}

/* --- DISPLAY PANEL (Center) --- */
#display-panel {
  position: relative;
  flex: 1;
  min-width: 0;
  transition: all 0.35s ease-in-out;
  background-color: var(--content-bg);
  color: var(--content-txt);
  padding-top: 65px; /* SAFE AREA: Prevents text from hiding under floating pillbox */
}

/* --- NOTES PANEL (Right Side) --- */
#notes-panel {
  position: relative;
  width: 320px;
  max-width: 100%;
  flex-shrink: 0;
  z-index: 5;
  background-color: var(--content-notes-bg);
  color: var(--content-notes-txt);
  margin-right: -320px;
  padding-top: 65px; /* SAFE AREA: Prevents text from hiding under floating pillbox */
}

/* --- INDEX PANEL (Left Side) --- */
#index-panel {
  position: relative;
  width: 320px;
  max-width: 100%;
  flex-shrink: 0;
  z-index: 5;
  background-color: var(--dirBgCol, var(--bgCol));

  /* CHANGED: Reduced from 50px to 20px so the branding perfectly aligns with the right-side pillbox */
  padding: 45px 0 0 0;
  margin-left: -320px;
  opacity: 0;
  transition:
    margin 0.35s ease-in-out,
    opacity 0.3s ease;

  /* Flexbox layout to lock the search bar and scroll the list */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-ready #index-panel {
  opacity: 1;
}
.panel-open {
  margin-left: 0 !important;
  margin-right: 0 !important;
}
.panel-animated {
  transition: margin 0.35s ease-in-out;
}

/* =========================================
   7. SEARCH & LIST ITEMS
   ========================================= */
#searchbox {
  position: relative;
  background-color: var(--srchBgCol);
  flex-shrink: 0;
}

#search {
  padding: 8px 40px 8px 15px;
  width: 100%;
  color: var(--srchTxtCol);
  border: none;
  outline: none;
  font-size: 20px;
  font-family: var(--defFont);
  background: inherit;
  border-radius: 0;
}
#search::placeholder {
  opacity: 0.7;
  color: var(--srchTxtCol);
}

#talkList {
  margin: 0;
  padding: 2px 0 1px;
  width: 100%;
  background: var(--tlBgCol);
  flex: 1;
  overflow-y: auto;
}

#talkList li {
  position: relative;
  margin-bottom: 1px;
  padding: 12px 15px;
  width: 100%;
  min-height: 80px;
  color: var(--liTxtCol);
  background: var(--liBgCol);
  overflow: hidden;
  z-index: 1;
  -webkit-touch-callout: none;
  user-select: none;
}

#talkList li.sel {
  color: var(--liTxtColSel);
  background: var(--liBgColSel);
}

.listttl {
  width: 100%;
  height: 100%;
  font-size: 18px !important;
  line-height: 1.2em;
  color: inherit;
  background: inherit;
  pointer-events: none;
}

/* --- List Item Popup Overlay --- */
#talkList li.popup-active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.08);
  border: 2px dashed var(--txtCol);
  pointer-events: none;
  z-index: 10;
}

/* =========================================
   8. EDITOR & MARKDOWN
   ========================================= */
#talkttl {
  margin-top: 0;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  outline: none;
}
#talkttl:empty:before {
  content: attr(placeholder);
  color: var(--text-muted);
}

#talkmain-edit,
#notesmain-edit {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  padding: 0;
}

.main-content.edit-mode #display-panel,
.main-content.edit-mode #notes-panel {
  -webkit-user-select: text;
  user-select: text;
}

.main-content.edit-mode #talkttl,
.main-content.edit-mode #talkmain-edit,
.main-content.edit-mode #notesmain-edit {
  border: 1px dotted #4a84b5;
  border-radius: 6px;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.02);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

/* --- THE FIX: Solid border & inset shadow on focus --- */
.main-content.edit-mode #talkttl:focus,
.main-content.edit-mode #talkmain-edit:focus,
.main-content.edit-mode #notesmain-edit:focus {
  border: 1px solid var(--txtCol);
  box-shadow: inset 0 0 0 1px var(--txtCol);
  outline: none;
  background-color: transparent;
}

#talkmain-view h1,
#talkmain-view h2,
#talkmain-view h3,
#notesmain-view h1,
#notesmain-view h2,
#notesmain-view h3 {
  margin-top: 15px;
  margin-bottom: 10px;
  color: var(--col4);
}

#talkmain-view ul,
#notesmain-view ul {
  list-style-type: disc;
  margin-left: 25px;
  margin-bottom: 15px;
}
#talkmain-view ol,
#notesmain-view ol {
  list-style-type: decimal;
  margin-left: 25px;
  margin-bottom: 15px;
}
#talkmain-view li,
#notesmain-view li {
  margin-bottom: 8px;
  list-style: inherit;
}

mark {
  background: hsl(60, 85%, 85%);
  color: hsl(0, 0%, 0%);
  padding: 0 4px;
  border-radius: 3px;
}
mark.hl-red {
  background: hsl(355, 85%, 88%);
}
mark.hl-green {
  background: hsl(135, 75%, 85%);
}
mark.hl-blue {
  background: hsl(200, 85%, 85%);
}
mark.hl-purple {
  background: hsl(275, 85%, 88%);
}

.scripture {
  margin: 15px 0;
  padding: 12px 15px;
  border-left: 4px solid var(--col4);
  background: var(--content-notes-bg);
  border-radius: 4px;
}
.scr-ref {
  display: block;
  font-weight: bold;
  color: var(--col4);
  font-size: 1.6rem;
  margin-bottom: 4px;
}
.scr-text {
  display: block;
  font-style: italic;
}
.scr-btn {
  color: var(--col4);
  font-weight: bold;
  cursor: pointer;
  border-bottom: 1px dashed var(--col4);
  padding-bottom: 1px;
}
.scr-btn:hover {
  opacity: 0.7;
}

/* Dark Mode Combos for Edit Tints & Popups */
@media (prefers-color-scheme: dark) {
  #talkList li.popup-active::after {
    background: rgba(255, 255, 255, 0.08);
  }
  .main-content.edit-mode #talkttl,
  .main-content.edit-mode #talkmain-edit,
  .main-content.edit-mode #notesmain-edit {
    background-color: rgba(255, 255, 255, 0.03);
  }
}
[data-theme="dark"] #talkList li.popup-active::after {
  background: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .main-content.edit-mode #talkttl,
[data-theme="dark"] .main-content.edit-mode #talkmain-edit,
[data-theme="dark"] .main-content.edit-mode #notesmain-edit {
  background-color: rgba(255, 255, 255, 0.03);
}

/* =========================================
   9. ICONS, STOPWATCH & UTILITIES
   ========================================= */
.icon-button {
  position: relative;
  width: 50px;
  height: 50px;
  padding: 5px;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  outline: none;
}
.icon-button:focus-visible {
  outline: 1px solid var(--txtCol);
  outline-offset: 4px;
}
.icon-button svg {
  width: 100%;
  height: 100%;
  transition: transform 0.35s ease-in-out;
}
.icon-button * {
  pointer-events: none;
}
#dirBtn.open svg {
  transform: rotate(20deg);
}
#notesBtn.open svg {
  transform: rotate(-20deg);
}

.display-area {
  margin: 0 auto;
  padding-left: 15px;
  display: grid;
  gap: 5px;
  grid-template-columns: 1fr auto;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 9px;
  height: 100%;
  -webkit-user-select: none;
  user-select: none;
}
.timer-display {
  display: flex;
  align-items: center;
  font-size: 28px;
  font-family: "ui-monospace", "SFMono-Regular", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 200;
  -webkit-user-select: none;
  user-select: none;
}
#swControl {
  width: 45px;
  height: 100%;
  padding: 0;
}

@keyframes swSpin {
  100% {
    transform: rotate(360deg);
  }
}
.sw-spin {
  animation: swSpin 4s linear infinite;
}
.sw-spin-paused {
  animation-play-state: paused;
}

/* --- SYSTEM FONT LOCK FOR UI ELEMENTS --- */
.modal-box,
.main-footer,
.options-popup,
#talkList {
  font-family: var(--sys-font) !important;
}
.modal-box .setbtn,
#talkList .listttl,
.options-popup {
  font-size: 16px !important;
}

/* =========================================
   10. MODALS & POPUPS
   ========================================= */
.modal-overlay,
.confirm-overlay,
#scrModalOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bgCol);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
}
.confirm-overlay,
#scrModalOverlay {
  background: rgba(0, 0, 0, 0.7);
  touch-action: none;
}

.modal-box {
  background: var(--content-bg);
  color: var(--content-txt);
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Modals Core */
#modHdr {
  /* CHANGED: Increased top padding to 50px to clear the iOS status bar */
  padding: 50px 1.5rem 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bgCol);
  color: var(--txtCol);
}
#modHdr h2 {
  font-size: 1.2rem;
  margin: 0;
}
#modMain {
  padding: 1.5rem;
  overflow-y: auto;
}
#modMain h3 {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
#modMain h3:first-child {
  margin-top: 0;
}
.modblock {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

/* Settings Buttons */
.setbtn {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  user-select: none;
  background: var(--content-bg);
}
.setbtn:hover {
  border-color: var(--text-muted);
}
.setbtn.setsel {
  border-color: var(--accent-color);
  background: rgba(0, 102, 204, 0.1);
  box-shadow: 0 0 0 1px var(--accent-color);
}
.mode-btn {
  padding: 15px 10px;
  font-weight: bold;
}

/* Swatches & Previews */
.theme-title {
  font-size: 0.9rem;
  font-weight: bold;
  margin-bottom: 8px;
}
.theme-swatch {
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.1);
  display: grid !important;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
}
.font-title {
  font-size: 0.9rem;
  font-weight: bold;
  margin-bottom: 5px;
}
.font-preview {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.8;
}

/* Confirm / Scripture Specific Boxes */
.confirm-box {
  background: var(--bgCol);
  padding: 25px;
  border-radius: 12px;
  max-width: 320px;
  width: 85%;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.confirm-title {
  margin-top: 0;
  margin-bottom: 25px;
  font-size: 18px;
  font-weight: normal;
  color: var(--txtCol);
  line-height: 1.4;
}
.confirm-btn-group {
  display: flex;
  gap: 15px;
}
#confirmCancelBtn {
  margin: 0;
  opacity: 0.8;
  color: var(--liBgColSel);
  background: var(--liTxtColSel);
  border: none;
}
#confirmActionBtn {
  margin: 0;
  color: #ff5555;
  background: var(--content-bg);
  border: none;
}

.scr-modal-box {
  width: 100%;
  max-width: 500px;
  max-height: 85%;
  padding: 25px 20px 35px;
  color: var(--content-txt);
  background: var(--content-bg);
  border-radius: 8px;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.scr-modal-hdr {
  font-size: 22px;
  color: var(--col4);
  border-bottom: 1px dotted var(--col4);
  flex-shrink: 0;
}
.scr-modal-main {
  font-size: 18px;
  line-height: 1.6;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-grow: 1;
}

/* List Options Popup */
.options-popup,
.list-options-popup {
  position: absolute;
  background: var(--bgCol);
  z-index: 10001;
  border-radius: 6px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  min-width: 170px;
  overflow: hidden;
}
.options-popup {
  top: 100%;
  right: 0;
  margin-top: 8px;
  border: 1px solid var(--border-color);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}
.options-popup.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.opt-item,
.list-opt-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--txtCol);
  transition: background 0.2s ease;
  user-select: none;
}
.opt-item:hover,
.list-opt-item:hover {
  background: var(--liBgColSel);
}

/* =========================================
   11. RESPONSIVE BREAKPOINTS
   ========================================= */
@media (max-width: 768px) {
  #index-panel,
  #notes-panel {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
  }
  #index-panel {
    left: 0;
    margin-left: -100%;
  }
  #notes-panel {
    right: 0;
    margin-right: -100%;
  }
  .icon-button {
    width: 50px;
    height: 50px;
    padding: 0;
  }
  .display-area {
    margin: 8px auto 0;
    padding-left: 10px;
  }
  .timer-display {
    font-size: 28px;
  }
}

/* =========================================
   12. PRINT STYLES
   ========================================= */
@media print {
  @page {
    size: letter;
    margin: 0.75in;
  }

  html,
  body,
  .app-container,
  .main-content,
  #display-panel {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    background: #fff !important;
    color: #000 !important;
    margin: 0;
    padding: 0;
  }

  /* Hide the entire App UI wrapper except the display panel */
  .noprint,
  #index-panel,
  #notes-panel,
  .main-footer,
  .options-wrapper {
    display: none !important;
  }

  /* Format the core text for physical printing */
  #talkttl {
    margin: 0 0 20px 0;
    padding: 0 0 6px 0;
    width: 100%;
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 24pt;
    border-bottom: 2px solid #000;
  }

  #talkmain-view {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14pt;
    line-height: 1.6;
    color: #000;
  }
}
