:root {
  /* Custom App Alert Colors (Pastel) */
  --color-green: #a7f3d0;      /* Soft pastel mint green */
  --color-red: #fca5a5;        /* Soft pastel coral red */

  /* Default (Light) Theme - Off-white, Warm Dark Blue & Pastels */
  --bg: #faf9f6;               /* Clean off-white background */
  --accent-bg: #f1f5f9;   
  --header-bg: #ccdded;       
  --text: #1a2d42;             /* Warm dark blue primary text */
  --text-light: #5a6e85;       /* Muted gray-blue for secondary text */
  --border: #cbd5e1;           /* Pastel gray border */
  --accent: #93c5fd;           /* Soft pastel blue for links/primary accents */
  --accent-hover: #60a5fa;     /* Slightly darker pastel blue for hover states */
  --accent-text: #1a2d42;      /* Warm dark blue text for readable contrast on accent backgrounds */
  --code: #f472b6;             /* Pastel pink for code snippets */
  --preformatted: #334155;     /* Dark slate for pre blocks */
  --marked: #fef08a;           /* Soft pastel yellow highlight */
  --disabled: #e2e8f0;         /* Soft muted gray for disabled elements */
  
  /* Search Specific Colors mapped for Light Mode */
  --search-input-bg: #ffffff;
  --search-clear-color: #999999;
  --search-highlight-bg: #ffeb3b; 
  --search-highlight-text: #1a2d42;

  --overlay-toolbar-height: 80px;
}

/* Dark Theme - Warm Dark Slate & De-saturated Accents */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    
    /* Custom App Alert Colors (Slightly deeper for dark contrast) */
    --color-green: #34d399;    
    --color-red: #f87171;      

    /* Core Theme Colors */
    --bg: #111827;             /* Deep warm dark slate background */
    --accent-bg: #374151;      /* Subtle dark gray-blue for cards/notices */
    --header-bg: #213952;      
    --text: #f3f4f6;           /* Crisp, soft white for readability */
    --text-light: #9ca3af;     /* Soft slate gray for secondary text */
    --border: #374151;         /* Muted dark border line */
    --accent: #60a5fa;         /* Vibrant but comfortable pastel blue for links */
    --accent-hover: #3b82f6;   /* Deeper blue accent for hover states */
    --accent-text: #111827;    /* Deep dark slate text over accent fields */
    --code: #f472b6;           /* Kept soft pink code for high contrast */
    --preformatted: #e5e7eb;   /* Light gray text inside dark pre blocks */
    --disabled: #1f2937;       /* Dull dark gray for disabled buttons */
    
    /* Search Specific Colors mapped for Dark Mode */
    --search-input-bg: #1f2937;       /* Darker background input field */
    --search-clear-color: #9ca3af;     /* Uses slate gray to blend into dark layout */
    --search-highlight-bg: #ca8a04;    /* De-saturated dark-gold highlight for eye safety */
    --search-highlight-text: #ffffff;
  }
  
  /* Add a bit of transparency so light media isn't so glaring in dark mode */
  img,
  video {
    opacity: 0.8;
  }
}

p {
  margin: 0;
  margin-bottom: 1rem;
}

hr {
  display: block;
  height: 0;
  border: 0;
  border-top: var(--border-width, 1px) solid var(--border);
  margin: 1.5rem auto;
  width: 100%;
}

html, body {
  height: 100dvh; 
  width: 100vw;
  margin: 0;
  padding: 0;
  position: relative;
  overflow: hidden;
  min-height: -webkit-fill-available;
}

/* Prevent pull-to-refresh gesture completely */
body.no-pull-refresh {
  overscroll-behavior-y: contain;
  overflow: hidden; /* Optional: locks scrolling bounce on mobile wrappers */
}

.page {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  min-height: -webkit-fill-available;
  box-sizing: border-box;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

#msg-area {
  box-sizing: border-box;
  width: 100%;
  height: auto; 
  padding-bottom: 16px;
  padding-left: 16px;
  padding-right: 16px;
  
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: relative; 
  z-index: 10;
  flex-shrink: 0;
}

.msg { 
  flex: 1; 
  text-align: center; 
  color: var(--color-green); 
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.msg.error { 
  color: var(--color-red); 
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px 16px 16px; 
}

#container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px;
  width: 100%;
  align-items: start;
}

.note {
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  padding: 8px;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.note:hover { 
  transform: translateY(-2px); 
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); 
}

.note-header {
  background-color: var(--header-bg);
  padding: 8px 8px;
  display: flex;
  justify-content: flex-end; 
}

.note-header time {
  font-weight: 700;
  color: var(--text-light); 
}

.note-body {
  line-height: 1.4;
  word-break: break-word;
  padding: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 10;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre-wrap;
  max-height: 13rem; 
}

#fullscreenOverlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  padding-top:
    calc(
      var(--overlay-toolbar-height)
      + env(safe-area-inset-top, 0px)
    );

  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
}

.fullscreen-inner {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.text-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
}

#edittext, #showtext {
  position: relative;
  z-index: 1;
}

#editform {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 16px;
  overflow: hidden;
}

#edittext {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  resize: none;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#showtext {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  word-break: break-word;
}

.fullscreen-textarea,
#showtext {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  outline: none;
  border-radius: 8px;
  line-height: 1.6;
  padding: 12px;
  box-sizing: border-box;
  font-family: inherit;
}

.fullscreen-textarea[readonly] {
  border-radius: 8px;
  padding: 12px;
  cursor: default;
}

.search-container {
  position: relative;
}

#search-input {
  width: 100%;
  padding: 10px 35px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 16px;
  background: var(--search-input-bg);
  color: var(--text);
}

#search-clear {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--search-clear-color);
}

.search-highlight {
  background-color: var(--search-highlight-bg);
  color: var(--search-highlight-text);
  border-radius: 2px;
  padding: 0 2px;
}

.search-snippet {
  font-size: 0.9em;
  color: var(--text-light);
  margin-top: 8px;
  padding: 8px;
  background: var(--accent-bg);
  border-radius: 4px;
}

.no-results {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
  font-size: 1.1em;
}

#login-popup { 
  z-index: 2000; 
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background-color: rgba(0, 0, 0, 0.4); /* Subtle dimming overlay behind login */
  backdrop-filter: blur(4px); /* Blurs out the main app interface elements */
}

.popup-content {
  /* Dynamically reads --accent-bg (#f1f5f9 in light / #374151 in dark) */
  background-color: var(--accent-bg);
  /* Uses your theme-defined text colors */
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 2rem 2.5rem;
  width: 90%; 
  max-width: 400px;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.3);
}

.popup-content h3 { 
  margin: 0 0 1.5rem; 
  font-weight: 700;
}

.popup-content input {
  width: 100%; 
  padding: 12px; 
  margin-bottom: 1rem;
  box-sizing: border-box;
  border-radius: 8px; 
   
  /* Inputs inside dark containers need dynamic backgrounds and borders */
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.popup-content input:focus { 
  outline: none; 
  /* Highlight input border with your brand accent line */
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--header-bg); 
}

.popup-content input::placeholder {
  color: var(--text-light);
  opacity: 0.6;
}

.popup-content .error-message { 
  color: var(--color-red); /* Automatically changes color depths via theme */
  margin: -0.5rem 0 1rem; 
  min-height: 1.2rem; 
  font-size: 0.875rem;
}

.popup-content button {
  border: none; 
  border-radius: 40px;
  padding: 12px 20px; 
  font-weight: 600; 
  width: 100%; 
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
   
  /* Maps button style structure to your primary brand accent properties */
  background-color: var(--accent);
  color: var(--accent-text);
}

.popup-content button:hover { 
  background-color: var(--accent-hover); 
}

.popup-content button:active { 
  transform: scale(0.98); 
}

.hidden { 
  display: none !important; 
}

.new-btn,
.close-btn,
.save-btn, 
.del-btn,
.drop-zone {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  padding: 0 !important;
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  min-height: 48px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 3001;
  border: none;
  cursor: pointer;  
  background: var(--accent);
  color: var(--accent-text);  
  backdrop-filter: blur(8px);
  transition: background 0.2s, transform 0.1s;
}

.new-btn svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

.new-btn:hover, .close-btn:hover, .save-btn:hover, .del-btn:hover, .drop-zone:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.drop-zone {
  left: 16px;
}

.drop-zone--over {
  border-style: solid;
  background-color: var(--accent-hover);
}

.drop-zone__input {
  display: none;
}

.new-btn {
  right: 16px;
}

@media (max-width: 959px) {
  .close-btn { right: 16px; }    
  .save-btn  { right: 72px; } 
  .del-btn   { right: 128px; }        
}

@media (min-width: 960px) {
  .close-btn {right: 16px;}
  .save-btn {right: 66px;}
  .del-btn {right: 116px;}       
}


@media (max-width: 600px) {
  #container { grid-template-columns: 1fr; }
}