/* =========================================
   1. ROOT VARIABLES (Defaults / Light Mode)
   ========================================= */
:root {
  --version: "v6.3.1";

  /* App Shell Fallbacks (Matches your 'default' JS theme) */
  --bgCol: #eeeeee;
  --txtCol: #4a84b5;
  --dirBgCol: #eeeeee;
  --border-color: #dddddd;

  /* Content Area Variables (Strictly for Display & Notes) */
  --content-bg: #ffffff;
  --content-txt: #222222;
  --content-notes-bg: #f5f5f5;
  --content-notes-txt: #333333;

  /* Typography */
  --font-family:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-base-size: 16px;
  --line-height: 1.5;

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

/* =========================================
   2. DARK MODE OVERRIDES (Content Areas ONLY)
   ========================================= */
/* Auto-detect system preference for reading areas */
@media (prefers-color-scheme: dark) {
  :root {
    --content-bg: #121212;
    --content-txt: #eeeeee;
    --content-notes-bg: #232323;
    --content-notes-txt: #dddddd;
    --border-color: #333333;
  }
}

/* Manual override for explicitly forcing Dark Mode */
[data-theme="dark"] {
  --content-bg: #121212;
  --content-txt: #eeeeee;
  --content-notes-bg: #232323;
  --content-notes-txt: #dddddd;
  --border-color: #333333;
}

/* Manual override for explicitly forcing Light Mode */
[data-theme="light"] {
  --content-bg: #ffffff;
  --content-txt: #222222;
  --content-notes-bg: #eeeeee;
  --content-notes-txt: #333333;
  --border-color: #dddddd;
}

/* =========================================
   3. MODERN CSS RESET
   ========================================= */
*,
*::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;
}

/* =========================================
   4. BASE STYLES & 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);
  height: 100%;
  overflow: hidden;

  /* Hide initially to prevent color flash */
  opacity: 0;
  transition:
    opacity 0.25s ease-in-out,
    background-color 0.3s ease,
    color 0.3s ease;

  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.app-ready {
  opacity: 1;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
}

/* Header Styling */
.main-header {
  display: flex;
  align-items: center;
  min-height: 60px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, var(--spacing-md));
  padding-right: env(safe-area-inset-right, var(--spacing-md));
  padding-bottom: 0;
  font-weight: bold;
}

.header-nav {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 1.5rem;
  padding: 4px 15px 15px;
  width: 100%;
  align-items: center; /* Forces vertical centering for the whole row */
}

.branding {
  font-size: 26px;
  font-weight: 200;
  opacity: 0.6;
  margin: 0;
  display: flex;
  align-items: center; /* Ensures the text inside stays vertically centered */
}

.branding::after {
  content: var(--version);
  margin-left: 5px;
  font-size: 16px;
}

.branding.standalone {
  opacity: 1;
}

.branding.standalone::before {
  content: "SA";
  font-size: 10px;
  margin-right: 4px;
}

/* --- MAIN WRAPPER --- */
.main-content {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  position: relative;
}

/* --- 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);
}

/* --- 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;
}

/* --- 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));
  padding: 0;
  margin-left: -320px;
  opacity: 0;
  transition:
    margin 0.35s ease-in-out,
    opacity 0.3s ease;
}

.app-ready #index-panel {
  opacity: 1;
}

/* --- PANEL ANIMATION STATE CLASSES --- */
.panel-open {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.panel-animated {
  transition: margin 0.35s ease-in-out;
}

/* --- SEARCH & LIST STYLES --- */
#searchbox {
  position: relative;
  background-color: var(--srchBgCol);
}

#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;
  box-sizing: border-box;
}

#search::placeholder {
  color: var(--srchTxtCol);
  opacity: 0.7;
}

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

[data-type="listItem"] {
  position: relative;
  margin-bottom: 1px;
  padding: 12px 15px;
  width: 100%;
  min-height: 80px;
  color: var(--liTxtCol);
  background: var(--liBgCol);
  overflow: hidden;
  z-index: 1;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif !important;
}

[data-type="listItem"].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 OPTIONS POPUP
   ========================================= */
#talkList li,
.list-opt-item {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.list-options-popup {
  position: absolute;
  top: 40px;
  right: 15px;
  font-size: 16px;
  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;
}

.list-opt-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

/* --- EDIT MODE STATE --- */
.main-content.edit-mode #display-panel,
.main-content.edit-mode #notes-panel {
  -webkit-user-select: text;
  user-select: text;
}

#overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: none;
  z-index: 10000;
}

#options {
  position: absolute;
  top: 88px;
  right: 10px;
  font-size: 16px;
  background: var(--modeNotesBgCol);
  z-index: 10001;
}

#printtalk {
  margin-top: 3px;
  fill: var(--col1);
  border-top: 1px solid #cccccc;
}

#backuptalk {
  margin-top: 3px;
  padding: 6px;
  fill: var(--col4);
  border-top: 1px solid #cccccc;
}

/* --- FOOTER & ICONS --- */
.main-footer {
  color: var(--txtCol);
}

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

.icon-button {
  position: relative;
  width: 45px;
  height: 45px;
  padding: 5px;
  opacity: 1;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  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;
}

.icon-button::after {
  content: attr(data-text);
  text-transform: uppercase;
  font-size: 10px;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

#dirBtn.open svg {
  transform: rotate(20deg);
}

#notesBtn.open svg {
  transform: rotate(-20deg);
}

.display-area {
  margin: 4px auto 0;
  padding-left: 15px;
  display: grid;
  gap: 5px;
  grid-template-columns: 1fr auto;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.timer-display {
  font-size: 32px;
  font-family:
    "ui-monospace", "SFMono-Regular", "Consolas", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

#swControl {
  width: 50px;
  height: 50px;
  padding: 0;
}

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

.grid-sr {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
}
.hidden {
  display: none !important;
}

/* =========================================
   5. SETTINGS MODAL & OVERLAYS
   ========================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bgCol);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
}

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

#modHdr {
  padding: 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;
}

.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;
}

.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;
}

/* --- EXEMPT UI FROM VARIABLE FONTS & SIZES --- */
.modal-box,
.main-header,
.main-footer,
#talkList,
#talkList li,
#talkList .listttl {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif !important;
  font-size: 16px !important;
}

.modal-box .setbtn {
  font-size: 16px !important;
}

/* --- TITLE & TEXTAREA STYLING --- */
#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;
}

/* =========================================
   EDIT MODE VISUAL CUES
   ========================================= */
.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;
}

@media (prefers-color-scheme: dark) {
  .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"] .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);
}

.main-content.edit-mode #talkttl:focus,
.main-content.edit-mode #talkmain-edit:focus,
.main-content.edit-mode #notesmain-edit:focus {
  border-color: var(--txtCol);
  box-shadow: 0 0 0 1px var(--txtCol);
  outline: none;
}

/* =========================================
   CUSTOM CONFIRM MODAL
   ========================================= */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  touch-action: none;
}

.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); /* FIXED TYPO HERE */
  border: none;
}

/* =========================================
   OPTIONS POPUP MENU
   ========================================= */
.options-popup {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bgCol);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 180px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif !important;
  font-size: 16px !important;
}

.options-popup.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

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

.opt-item:first-child {
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.opt-item:last-child {
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.opt-item:hover {
  background: var(--liBgColSel);
}

@media print {
  .options-wrapper {
    display: none !important;
  }
}

.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;
}

/* --- MOBILE SPECIFIC OVERRIDES --- */
@media (max-width: 500px) {
  #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: 40px;
    height: 40px;
  }
  .icon-button::after {
    font-size: 10px;
  }
  .display-area {
    margin: 8px auto 0;
    padding-left: 10px;
  }
  .timer-display {
    font-size: 28px;
  }
}

/* =========================================
   MARKDOWN & SCRIPTURE STYLES
   ========================================= */
#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);
}

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(--modeNotesBgCol);
  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;
}

#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;
}

.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;
}

/* SCRIPTURE MODAL STYLES */
#scrModalOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px;
  background: rgba(0, 0, 0, 0.4);
  z-index: 6000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scr-modal-box {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 85%;
  padding: 25px 20px 35px;
  color: var(--txtCol);
  background: var(--bgCol);
  font-family: var(--defFont);
  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;
}

@media print {
  @page {
    size: letter;
  }
  html,
  body {
    margin: 0;
    padding: 0;
    width: 215.9mm;
    height: auto;
    color: #000;
    background: #fff;
    overflow: auto;
  }
  .noprint {
    display: none;
  }
  .app-container,
  #main {
    margin: 0;
    padding: 0;
    position: relative !important;
    width: 100%;
    height: auto;
    overflow: auto;
    display: block;
  }
  #content {
    margin: 0;
    padding: 0;
    color: #000;
    background: #fff;
  }
  #talkttl {
    margin: 0 0 25px 0;
    padding: 0 0 6px 0;
    width: 100%;
    color: #000;
    background: #fff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 18pt;
    border-bottom: 1px solid #000;
  }
  #talkmain-view {
    margin: 0;
    padding: 0;
    color: #000;
    background: #fff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14pt;
  }
}
