/* ===========================================
   Grandpa's Stories - Manuscript Editor Styles
   =========================================== */

/* Base styles from original book */
body {
  font-family: Georgia, serif;
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  padding-top: 80px; /* Space for fixed toolbar */
  line-height: 1.6;
  background: #fafafa;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

h1 {
  text-align: center;
  border-bottom: 2px solid #333;
  padding-bottom: 10px;
}

h2 {
  color: #444;
  margin-top: 2em;
}

.chapter-title {
  page-break-before: always;
  text-align: center;
  margin-top: 3em;
}

.story {
  margin-bottom: 3em;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.story-title {
  color: #333;
  border-left: 4px solid #666;
  padding-left: 15px;
}

.narrative {
  text-align: justify;
  text-indent: 2em;
  outline: none;
  min-height: 50px;
}

.narrative:focus {
  background: #fffef5;
  border-radius: 4px;
}

.narrative p {
  margin: 1em 0;
}

.qr-container {
  text-align: center;
  margin: 1em 0;
}

.qr-container img {
  width: 150px;
  height: 150px;
}

.qr-caption {
  font-style: italic;
  font-size: 0.9em;
  color: #666;
}

.video-container {
  margin: 1em 0;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

.video-container iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  position: relative;
  z-index: 1;
}

.source {
  font-style: italic;
  color: #888;
  font-size: 0.9em;
  margin-top: 1em;
}

.toc {
  margin: 2em 0;
  background: white;
  padding: 20px;
  border-radius: 8px;
}

.toc ul {
  list-style-type: none;
}

.toc li {
  margin: 0.5em 0;
}

.toc a {
  text-decoration: none;
  color: #333;
}

.toc a:hover {
  text-decoration: underline;
}

hr {
  border: none;
  border-top: 1px solid #ddd;
  margin: 2em 0;
}

.footer {
  text-align: center;
  color: #888;
  font-style: italic;
  margin-top: 3em;
}

/* ===========================================
   Password Gate
   =========================================== */

.password-gate {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.password-gate.hidden {
  display: none;
}

.password-modal {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.password-modal h2 {
  margin-top: 0;
  color: #333;
}

.password-modal p {
  color: #666;
  margin-bottom: 20px;
}

.password-modal input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 6px;
  margin-bottom: 15px;
  box-sizing: border-box;
}

.password-modal input:focus {
  outline: none;
  border-color: #4a90d9;
}

.password-modal button {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.password-modal button:hover {
  background: #357abd;
}

.password-modal .error {
  color: #dc3545;
  margin-top: 10px;
  font-size: 14px;
}

/* ===========================================
   Editor Toolbar
   =========================================== */

.editor-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #333;
  color: white;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2147483647;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  transform: translateZ(0);
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.editor-toolbar.hidden {
  display: none;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.editor-toolbar input {
  padding: 8px 12px;
  font-size: 14px;
  border: none;
  border-radius: 4px;
  width: 150px;
}

.editor-toolbar button {
  padding: 8px 16px;
  font-size: 14px;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.editor-toolbar button:hover {
  background: #357abd;
}

.editor-toolbar button.active {
  background: #28a745;
}

#change-count,
#comment-count {
  font-size: 13px;
  color: #aaa;
}

#clear-btn {
  background: #dc3545;
}

#clear-btn:hover {
  background: #c82333;
}

/* ===========================================
   Track Changes Styling
   =========================================== */

/* Deletions - red strikethrough */
del.tc-delete,
.tc-delete {
  text-decoration: line-through;
  color: #dc3545;
  background-color: #ffebee;
  padding: 0 2px;
  border-radius: 2px;
}

/* Insertions - green underline */
ins.tc-insert,
.tc-insert {
  text-decoration: none;
  color: #28a745;
  background-color: #e8f5e9;
  border-bottom: 2px solid #28a745;
  padding: 0 2px;
  border-radius: 2px;
}

/* Change tooltip on hover */
[data-editor]::after {
  content: attr(data-editor) " - " attr(data-time);
  position: absolute;
  background: #333;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  transform: translateY(-100%);
  margin-top: -5px;
}

[data-editor]:hover::after {
  opacity: 1;
}

/* Hide changes mode */
body.hide-changes .tc-delete {
  display: none;
}

body.hide-changes .tc-insert {
  color: inherit;
  background: none;
  border-bottom: none;
}

/* ===========================================
   Comments
   =========================================== */

.tc-comment {
  background-color: #fff3cd;
  border-bottom: 2px dashed #ffc107;
  cursor: pointer;
  position: relative;
}

.tc-comment:hover {
  background-color: #ffe69c;
}

.tc-comment::before {
  content: attr(data-comment-count);
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ffc107;
  color: #333;
  font-size: 10px;
  font-weight: bold;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Comments Sidebar */
.comments-sidebar {
  position: fixed;
  top: 60px;
  right: 0;
  width: 320px;
  height: calc(100vh - 60px);
  background: white;
  box-shadow: -2px 0 10px rgba(0,0,0,0.1);
  z-index: 999;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.comments-sidebar.visible {
  transform: translateX(0);
}

.comments-sidebar.hidden {
  transform: translateX(100%);
}

.comments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: white;
}

.comments-header h3 {
  margin: 0;
  color: #333;
}

.comments-header button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
}

.comments-header button:hover {
  color: #333;
}

.comments-list {
  padding: 15px;
}

.comment-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 15px;
  border-left: 4px solid #ffc107;
}

.comment-item .comment-meta {
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.comment-item .comment-quote {
  font-style: italic;
  color: #888;
  font-size: 13px;
  margin-bottom: 8px;
  padding-left: 10px;
  border-left: 2px solid #ddd;
}

.comment-item .comment-text {
  color: #333;
}

.comment-item .comment-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

.comment-item button {
  padding: 4px 10px;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.comment-item .delete-comment {
  background: #ffebee;
  color: #dc3545;
}

.comment-item .goto-comment {
  background: #e3f2fd;
  color: #1976d2;
}

/* Comment input modal */
.comment-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  z-index: 10001;
  width: 400px;
  max-width: 90%;
}

.comment-modal.hidden {
  display: none;
}

.comment-modal h3 {
  margin-top: 0;
}

.comment-modal .selected-text {
  background: #fff3cd;
  padding: 10px;
  border-radius: 4px;
  margin-bottom: 15px;
  font-style: italic;
}

.comment-modal textarea {
  width: 100%;
  height: 100px;
  padding: 10px;
  font-size: 14px;
  border: 2px solid #ddd;
  border-radius: 6px;
  resize: vertical;
  box-sizing: border-box;
}

.comment-modal textarea:focus {
  outline: none;
  border-color: #ffc107;
}

.comment-modal .modal-actions {
  margin-top: 15px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.comment-modal button {
  padding: 10px 20px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.comment-modal .cancel-btn {
  background: #f0f0f0;
  color: #333;
}

.comment-modal .save-btn {
  background: #ffc107;
  color: #333;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
}

.modal-overlay.hidden {
  display: none;
}

/* ===========================================
   Print Styles
   =========================================== */

@media print {
  .editor-toolbar,
  .comments-sidebar,
  .password-gate {
    display: none !important;
  }

  body {
    padding-top: 20px;
  }

  .chapter-title {
    page-break-before: always;
  }

  .story {
    page-break-inside: avoid;
    box-shadow: none;
  }

  .tc-delete {
    color: #dc3545 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .tc-insert {
    color: #28a745 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ===========================================
   Responsive
   =========================================== */

@media (max-width: 768px) {
  body {
    padding: 10px;
    padding-top: 140px;
  }

  .editor-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    width: 100vw;
    max-width: 100vw;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    z-index: 2147483647;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    min-width: 0;
    gap: 8px;
  }

  .editor-toolbar input {
    width: 100%;
    max-width: 220px;
    min-width: 0;
  }

  .editor-toolbar button {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
  }

  .comments-sidebar {
    width: 100%;
  }

  .story {
    padding: 15px;
  }
}
