:root {
  /* Crisp Minimalist Light Theme */
  --bg-main: #f0f0f0;
  --bg-image: url('lightmode_bg.png');
  --bg-rotate: 0deg;
  --bg-opacity: 1;
  --text-primary: #000000;
  --text-primary-rgb: 17, 17, 17;
  --text-secondary: #a65a85;
  --border: #cccccc;
  --error-border: #ff0000;

  /* Brutally bright, Highly Saturated Red/Orange range for Light Mode */
  --h-color-1: hsla(10, 100%, 65%, 1.0);
  --h-color-2: hsla(25, 100%, 65%, 1.0);
  --h-color-3: hsla(0, 100%, 65%, 1.0);
  --h-color-4: hsla(35, 100%, 65%, 1.0);
  --h-color-5: hsla(5, 100%, 65%, 1.0);
  --h-color-6: hsla(20, 100%, 65%, 1.0);
}

/* Crisp Minimalist Dark Theme */
[data-theme="dark"] {
  --bg-main: #121212;
  --bg-image: url('darkmode_bg.jpg');
  --bg-rotate: 0deg;
  --bg-opacity: 0.4;
  --text-primary: #f5f5f5;
  --text-primary-rgb: 245, 245, 245;
  --text-secondary: #a9e6d9;
  --border: #444444;
  --error-border: #ff6666;
  /* Brighter warning glow */

  /* Intensely Saturated Red/Orange range for Dark Mode */
  --h-color-1: hsla(10, 100%, 65%, 1.0);
  --h-color-2: hsla(25, 100%, 65%, 1.0);
  --h-color-3: hsla(0, 100%, 70%, 1.0);
  --h-color-4: hsla(35, 100%, 60%, 1.0);
  --h-color-5: hsla(5, 100%, 70%, 1.0);
  --h-color-6: hsla(20, 100%, 65%, 1.0);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

html {
  background: var(--bg-main);
  transition: background 0.3s ease;
}

body {
  margin: 0;
  padding: 1.5rem;
  background: transparent;
  color: var(--text-primary);
  font-family: 'Times New Roman', Georgia, serif;
  display: flex;
  justify-content: center;
  align-items: stretch;
  line-height: 1.6;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  transform: rotate(var(--bg-rotate));
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-opacity);
  z-index: -1;
  pointer-events: none;
}

.app-container {
  width: 100%;
  max-width: 1800px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

main.main-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  gap: 4rem;
}

/* On desktop, panel-wrapper is invisible to layout — asides participate in mainRow flex */
.panel-wrapper {
  display: contents;
}

/* Visual order for desktop: left sidebar (1) | editor (2) | right sidebar (3) */
#leftSidebar      { order: 1; flex: 0 0 260px; min-height: 0; }
.editor-container { order: 2; flex: 1;        min-height: 0; }
#rightSidebar     { order: 3; flex: 0 0 320px; min-height: 0; }

/* Mobile toolbar and sidebar toggles hidden on desktop */
.mobile-toolbar { display: none; }
.sidebar-toggle { 
  display: none; 
  cursor: pointer; 
  transition: transform 0.2s, color 0.2s; 
  position: relative; /* Anchor for the badge */
}
.sidebar-toggle:active { transform: scale(0.9); }


.badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--error-border);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.badge.active {
  opacity: 1;
  transform: scale(1);
}

.sidebar-overlay {
  display: none; /* Removed for non-blocking multi-tasking */
}

header {
  border-bottom: none;
  padding-bottom: 0;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

h1 {
  font-family: 'Inter', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-secondary);
}

.icon-btn {
  position: relative; /* Anchor for badges */
  background: transparent;
  border: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Symbol";
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: color 0.2s;
  color: var(--text-secondary);
}

.icon-btn:hover {
  color: var(--text-primary);
}

header p {
  color: var(--text-secondary);
  font-size: 1.15rem;
  margin-top: 0.5rem;
}

.editor-container {
  display: grid;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  overflow: hidden;
  min-height: 0;
}



/* Identical layouts for perfect wrap & overlay */
#poemInput,
#backdrop {
  grid-area: 1 / 1;
  font-family: 'Times New Roman', Times, serif;
  font-size: 1.15rem;
  line-height: 1.6;
  padding: 0;
  margin: 0;
  border: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  text-align: left;
  letter-spacing: 0;
  word-spacing: 0;
  font-kerning: none;
  text-rendering: optimizeSpeed;
}

#poemInput,
#backdrop {
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* Hide scrollbar on backdrop but keep on textarea */
#backdrop::-webkit-scrollbar {
  display: none;
}

#poemInput::-webkit-scrollbar {
  width: 8px;
}

#poemInput::-webkit-scrollbar-track {
  background: transparent;
}

#poemInput::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

#backdrop {
  grid-area: 1 / 1;
  z-index: 0;
  color: var(--text-primary);
  pointer-events: none;
}

#poemInput {
  grid-area: 1 / 1;
  z-index: 1;
  background: transparent;
  color: transparent; /* Makes text markers invisible */
  -webkit-text-fill-color: transparent; /* Essential for mobile Safari/Chrome */
  caret-color: var(--text-primary); /* Keeps cursor visible */
  outline: none;
  resize: none;
}

/* Ensure selection highlights are visible even if text is transparent */
#poemInput::selection {
  background: rgba(var(--text-primary-rgb), 0.2);
  color: transparent;
  -webkit-text-fill-color: transparent;
}

#poemInput::placeholder {
  color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
  opacity: 1;
}

mark {
  color: inherit;
  border-radius: 0;
  padding: 0;
  margin: 0;
}

.status-panel {
  position: sticky;
  top: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: transparent;
  border: none;
  min-height: 0;
}

/* Sleek scrollbar for the side lists */
.word-list::-webkit-scrollbar,
.repeated-list::-webkit-scrollbar {
  width: 8px;
}

.word-list::-webkit-scrollbar-track,
.repeated-list::-webkit-scrollbar-track {
  background: transparent;
}

.word-list::-webkit-scrollbar-thumb,
.repeated-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

h3 {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.05rem;
}

.stat {
  font-size: 1.15rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.repeated-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  overflow-y: auto;
  flex: 1;
  align-content: flex-start;
  align-items: flex-start;
}

.pill {
  border-radius: 0;
  font-size: 1.15rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.1s;
}

.pill:hover {
  background: var(--text-primary);
  color: var(--bg-main);
}

.pill .word-text {
  padding: 0 0.6rem;
  display: flex;
  align-items: center;
}

.pill .count-block {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.6em;
  height: 1.6em;
  border-left: none;
}

/* Vocabulary List on the left */
.search-container {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex: 1;
}

#vocabSearch {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.1rem 0;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
  outline: none;
  transition: border-color 0.2s;
}

#vocabSearch:focus {
  border-bottom-color: var(--text-primary);
}

#vocabSearch::placeholder {
  color: var(--text-secondary);
  opacity: 1;
  font-size: 0.8rem;
}

.word-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  flex: 1;
  align-items: stretch;
  width: 100%;
}

#filteredVocabList {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.vocab-item {
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--text-primary);
  padding: 0.2rem 0;
  border-bottom: none;
  cursor: pointer;
  border-left: none;
  display: flex;
  align-items: center;
  transition: all 0.1s;
}

.vocab-item span {
  padding: 0;
  transition: background-color 0s;
}

.vocab-item:hover span {
  background: var(--text-primary);
  color: var(--bg-main);
}

/* Animations for Ctrl+F visual hook */
@keyframes flashFocus {

  0%,
  15% {
    background-color: var(--text-primary);
    color: var(--bg-main);
    border-radius: 0;
  }
}

.flash-highlight {
  position: relative;
  z-index: 10;
  animation: flashFocus 0.8s ease-out;
}

/* ── Mobile: vertical flex column ── */
@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100dvh;
  }

  .app-container {
    height: auto;
    min-height: calc(100dvh - 3rem);
  }

  h1 {
    font-size: 1.5rem;
  }

  main.main-layout {
    flex-direction: column;
    height: 100%;
    gap: 0;
  }

  /* Editor stays at the top */
  .editor-container {
    order: 1;
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  /* Panel wrapper acts as the carousel container */
  .panel-wrapper {
    order: 2;
    display: flex;
    flex-shrink: 0;
    width: 100%;
    height: 0;
    overflow: hidden;
    scroll-behavior: smooth;
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .panel-wrapper.is-open {
    height: 40vh;
  }

  /* Each sidebar takes full width of the wrapper on mobile */
  #leftSidebar,
  #rightSidebar {
    flex: 0 0 100%;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
    background: transparent;
    box-shadow: none;
    border: none;
    transition: none; /* Transition is handled by scrollLeft */
  }

  /* ── Mobile toolbar row: always at the very bottom ── */
  .mobile-toolbar {
    order: 3;
    display: flex;
    flex-shrink: 0;
    height: 3rem;
    justify-content: space-between;
    align-items: center;
  }

  .sidebar-toggle {
    position: relative !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
  }

  .sidebar-toggle .badge {
    position: absolute;
    top: 4px;
    right: 4px;
  }
}
