* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Arial, sans-serif; }

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --green: #2e7d32;
  --green-dark: #1b5e20;
}

body {
  background: #fdf6e3;
  color: #222;
  padding-bottom: calc(80px + var(--safe-bottom));
  min-height: 100vh;
}

.header {
  background: var(--green);
  color: #fff;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.header h1 { font-size: 18px; }
.header button {
  background: #fff; color: var(--green);
  border: none; padding: 6px 12px;
  border-radius: 6px; font-weight: bold;
  cursor: pointer; font-size: 13px;
}

.sticky-toolbar {
  position: sticky;
  top: 56px;
  z-index: 90;
  background: #f5f5f5;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  flex-wrap: nowrap;
  border-bottom: 2px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
}
.tb-btn {
  width: 36px; height: 36px;
  border: 1px solid #ddd; background: #fff;
  border-radius: 6px; cursor: pointer;
  font-size: 16px; color: #333;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.tb-btn:hover { background: #eee; }
.tb-btn:active { background: var(--green); color: #fff; }
.tb-divider { width: 1px; height: 26px; background: #ccc; margin: 0 4px; flex-shrink: 0; }
.tb-select {
  height: 36px; padding: 0 6px;
  border: 1px solid #ddd; border-radius: 6px;
  font-size: 12px; background: #fff;
  cursor: pointer; flex-shrink: 0; max-width: 110px;
}

.color-picker { position: relative; flex-shrink: 0; }
.color-btn { background: #333 !important; color: #fff !important; }
.color-dropdown {
  position: fixed; top: 100px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid #ddd; border-radius: 12px;
  padding: 12px; display: none;
  grid-template-columns: repeat(4, 1fr); gap: 10px;
  z-index: 500; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  width: 220px; max-height: 70vh; overflow-y: auto;
}
.color-dropdown.show { display: grid; }
.color-swatch {
  width: 40px; height: 40px; border-radius: 8px;
  border: 2px solid #ddd; cursor: pointer;
  transition: transform .15s;
}
.color-swatch:hover { border-color: var(--green); transform: scale(1.1); }
.color-swatch:active { transform: scale(0.95); }

.img-btn { background: #fff !important; color: #2e7d32 !important; }

/* ============ IMAGE STYLES ============ */
.rich-editor img {
  max-width: 100%; height: auto;
  border-radius: 8px; margin: 8px auto;
  display: block;
  cursor: pointer;
  transition: outline .15s;
}
.rich-editor img.selected-img {
  outline: 3px solid var(--green);
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(46,125,50,.4);
}

/* ============ IMAGE OPTIONS MODAL ============ */
.img-modal-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  display: none;
}
.img-modal-bg.show { display: block; }

.img-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  z-index: 600;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  width: 90%;
  max-width: 360px;
  display: none;
  opacity: 0;
  transition: all .2s;
}
.img-modal.show {
  display: block;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.img-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 12px;
  color: #333;
}
.img-modal-close {
  width: 32px; height: 32px;
  border: none; background: #f0f0f0;
  border-radius: 50%;
  font-size: 16px; cursor: pointer;
  color: #666;
}
.img-modal-close:hover { background: #e0e0e0; color: #333; }

.img-modal-section {
  margin-bottom: 14px;
}
.img-modal-label {
  font-size: 13px;
  color: #666;
  font-weight: bold;
  margin-bottom: 8px;
}
.img-modal-row {
  display: flex;
  gap: 6px;
}
.modal-btn {
  flex: 1;
  padding: 10px 6px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  color: #333;
  transition: all .15s;
}
.modal-btn:hover { background: #e8f5e9; border-color: var(--green); }
.modal-btn:active { background: var(--green); color: #fff; }
.modal-btn small { font-size: 10px; color: #888; font-weight: normal; display: block; margin-top: 2px; }
.modal-btn.danger {
  background: #ffebee;
  color: #c62828;
  border-color: #ffcdd2;
}
.modal-btn.danger:hover {
  background: #c62828;
  color: #fff;
  border-color: #c62828;
}

.container { padding: 12px; max-width: 700px; margin: auto; }

.card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

input {
  width: 100%; padding: 12px; margin: 6px 0;
  border: 1px solid #ddd; border-radius: 8px;
  font-size: 15px; background: #fff; font-family: inherit;
}
input:focus { outline: none; border-color: var(--green); }

button.primary {
  width: 100%; padding: 12px;
  background: var(--green); color: #fff;
  border: none; border-radius: 8px;
  font-size: 16px; font-weight: bold;
  margin-top: 8px; cursor: pointer;
}
button.primary:active { background: var(--green-dark); }
button.danger { background: #c62828 !important; }
button.small { padding: 8px 12px; font-size: 13px; width: auto; margin: 2px; }
button.outline { background: transparent; color: var(--green); border: 2px solid var(--green); }

.hidden { display: none !important; }
.center { text-align: center; }

.editor-page {
  background: #fffef7;
  border: 2px solid #e0d5b7;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  transition: border-color .2s;
}
.editor-page.active-page {
  border-color: var(--green);
  box-shadow: 0 2px 8px rgba(46,125,50,.2);
}

.page-number {
  text-align: center;
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
}

.rich-editor {
  min-height: 180px;
  padding: 10px;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #fffef7;
  outline: none;
  font-family: 'Noto Sans Devanagari', 'Mangal', Arial, sans-serif;
  word-wrap: break-word;
  cursor: text;
}
.rich-editor:empty::before {
  content: attr(placeholder);
  color: #999;
  pointer-events: none;
}
.rich-editor:focus { background: #fff; }

.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row button { flex: 1; }

.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  z-index: 999;
  opacity: 0;
  transition: opacity .3s;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; }

img { max-width: 100%; }

.note-card {
  background: #fff;
  border-left: 4px solid var(--green);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.note-card h3 { font-size: 16px; margin-bottom: 4px; color: #222; }
.note-card .meta { font-size: 12px; color: #888; display: flex; justify-content: space-between; }

.tabs { display: flex; background: #eee; border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.tabs button {
  flex: 1; padding: 10px; border: none; background: transparent;
  border-radius: 8px; font-weight: bold; cursor: pointer;
  font-size: 14px; color: #666;
}
.tabs button.active { background: var(--green); color: #fff; }

.empty { text-align: center; padding: 40px 20px; color: #888; }
.empty .icon { font-size: 60px; margin-bottom: 12px; }

.fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--green); color: #fff;
  border: none; font-size: 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  cursor: pointer; z-index: 99;
}
