/* ========================================
   GRAND LINE XML EDITOR — Wanted Poster Theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Pirata+One&family=Crimson+Text:ital,wght@0,400;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  /* Colors - Slightly Darker Vibe */
  --parchment: #c8b99e;
  --parchment-dark: #ad9a7a;
  --ink: #1a1008;
  --ink-light: #3a2618;
  --marine-blue: #132a40;
  --wanted-red: #7a1515;
  --gold: #9c7207;
  
  /* Typography */
  --font-title: 'Pirata One', cursive;
  --font-ui: 'Crimson Text', serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Wood background for the desk */
  --wood-1: #2a1b10;
  --wood-2: #1c1109;
}

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

html, body {
  height: 100vh;
  width: 100vw;
  overflow: hidden; /* Fixed, no scrollable approach */
  font-family: var(--font-ui);
  background: var(--wood-1);
  background-image: 
    linear-gradient(90deg, transparent 50%, rgba(255,255,255,.05) 50%),
    linear-gradient(90deg, rgba(255,255,255,.02) 20%, transparent 20%, transparent 80%, rgba(255,255,255,.02) 80%),
    radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(0,0,0,0.5) 100%);
  background-size: 100px 100%, 50px 100%, 100% 100%;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- The Parchment Document ---------- */
.app-container {
  width: 95vw;
  height: 95vh;
  max-width: 1200px;
  background-color: var(--parchment);
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(0,0,0,0.02) 0%, transparent 50%),
    radial-gradient(circle at 90% 90%, rgba(0,0,0,0.04) 0%, transparent 50%);
  border: 2px solid var(--ink-light);
  box-shadow: 
    0 0 10px rgba(0,0,0,0.5),
    inset 0 0 40px rgba(139, 69, 19, 0.2);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Ragged Edges Effect via pseudo-elements */
.app-container::before, .app-container::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 6px;
  background: inherit;
  z-index: 10;
}
.app-container::before {
  top: -3px;
  border-bottom: 1px dashed rgba(0,0,0,0.1);
}
.app-container::after {
  bottom: -3px;
  border-top: 1px dashed rgba(0,0,0,0.1);
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 2px solid var(--ink-light);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.straw-hat-icon {
  font-size: 28px;
  line-height: 1;
}

.header-title h1 {
  font-family: var(--font-title);
  font-size: 2rem;
  letter-spacing: 2px;
  color: var(--wanted-red);
  text-transform: uppercase;
  line-height: 1;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

.header-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-light);
  margin-top: -2px;
}

/* Bounty Badge */
.bounty-badge {
  text-align: right;
  border: 2px solid var(--ink);
  padding: 2px 10px;
  background: rgba(0,0,0,0.03);
  transform: rotate(-2deg);
}

.bounty-label {
  display: block;
  font-family: var(--font-title);
  font-size: 1rem;
  color: var(--ink);
  letter-spacing: 1px;
}

.bounty-value {
  font-family: var(--font-title);
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--wanted-red);
}

.bounty-unit {
  font-size: 1rem;
  font-style: italic;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid rgba(44, 30, 22, 0.2);
  background: var(--parchment-dark);
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-label {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--ink);
}

.tag-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Artistic Buttons */
button {
  font-family: var(--font-ui);
  background: var(--parchment);
  border: 1px solid var(--ink-light);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink-light);
  transition: all 0.1s ease;
}

button:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--ink-light);
}

.tag-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.tag-btn kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(0,0,0,0.05);
  padding: 2px 4px;
  border: 1px solid rgba(0,0,0,0.2);
}

.tag-user { border-left: 3px solid var(--marine-blue); }
.tag-assistant { border-left: 3px solid var(--gold); }
.tag-thinking { border-left: 3px solid var(--wanted-red); }
.tag-custom { border-left: 3px solid var(--ink); }

.tag-remove {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--wanted-red);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 4px;
}
.tag-remove:active { transform: none; color: var(--ink); }

.add-tag-btn, .ai-generate-btn {
  padding: 4px 10px;
  font-weight: 600;
  font-size: 0.9rem;
}
.add-tag-btn {
  font-style: italic;
  border-style: dashed;
}

.sail-mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-right: 10px;
}

/* ---------- Editor Area ---------- */
.editor-wrapper {
  flex: 1; /* Takes remaining height */
  display: flex;
  position: relative;
  min-height: 0; /* Important for nested flex scrolling */
  background: var(--parchment);
  margin: 15px 30px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.4), inset 0 0 40px rgba(139, 69, 19, 0.1);
  border-radius: 2px;
  animation: unrollEditor 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes unrollEditor {
  0% {
    max-height: 0;
    opacity: 0;
    transform: scale(0.95);
  }
  15% {
    max-height: 0;
    opacity: 1;
    transform: scale(1);
  }
  100% {
    max-height: 2000px;
    opacity: 1;
    transform: scale(1);
  }
}

/* Scroll Rollers */
.editor-wrapper::before, .editor-wrapper::after {
  content: '';
  position: absolute;
  left: -15px;
  right: -15px;
  height: 20px;
  background: linear-gradient(to bottom, #3b230d, #704721, #251406);
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.1);
  z-index: 10;
}
.editor-wrapper::before {
  top: -10px;
}
.editor-wrapper::after {
  bottom: -10px;
}

.editor-textarea {
  flex: 1;
  padding: 15px 25px;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  font-family: var(--font-ui);
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: hidden;
  overflow-y: auto;
  animation: fadeInText 1.5s ease forwards;
}

@keyframes fadeInText {
  0%, 40% { opacity: 0; }
  100% { opacity: 1; }
}

/* AI Suggestion Widget */
.ai-suggestion-widget {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--parchment-dark);
  border: 1px solid var(--ink);
  padding: 8px 12px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 2px 2px 0px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 50;
}
.ai-suggestion-widget.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.ai-action-btn {
  background: transparent;
  border: 1px solid var(--ink-light);
  border-radius: 4px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: all 0.2s ease;
}
.ai-action-btn:hover { background: rgba(0,0,0,0.1); }
.ai-generate-btn:hover { background: rgba(0,0,0,0.05); }

.ai-action-btn.accept:hover { color: #1e7033; border-color: #1e7033; }
.ai-action-btn.reject:hover { color: var(--wanted-red); border-color: var(--wanted-red); }

.copy-btn, .clear-btn {
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-title);
  font-size: 0.95rem;
  letter-spacing: 1px;
  transition: all 0.2s ease;
}
.copy-btn:hover { background: rgba(0,0,0,0.1); }
.clear-btn:hover { background: var(--wanted-red); color: var(--parchment); border-color: var(--wanted-red); }

.editor-textarea::placeholder {
  color: rgba(44, 30, 22, 0.4);
}

/* Scrollbars - Artistic */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--parchment-dark); border-left: 1px solid var(--ink-light); }
::-webkit-scrollbar-thumb { background: var(--ink-light); border: 2px solid var(--parchment-dark); }
::-webkit-scrollbar-corner { background: var(--parchment-dark); }

/* ---------- Bottom Bar ---------- */
.bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-top: 2px solid var(--ink-light);
  background: var(--parchment-dark);
}

.stats-section, .export-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-item {
  font-size: 0.9rem;
  font-weight: 600;
}

.stat-value {
  font-family: var(--font-mono);
}

.copy-btn {
  padding: 2px 10px;
  font-weight: bold;
}

.export-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.export-label {
  font-weight: 600;
  font-style: italic;
}

.export-input {
  background: var(--parchment);
  border: 1px solid var(--ink-light);
  color: var(--ink);
  padding: 4px 8px;
  font-family: var(--font-mono);
  outline: none;
}
.export-input:focus {
  border-bottom: 2px solid var(--wanted-red);
}

.export-btn {
  padding: 4px 10px;
  font-weight: bold;
}

/* ---------- App Footer ---------- */
.app-footer {
  text-align: center;
  padding: 5px 0;
  border-top: 1px dashed var(--ink-light);
  font-style: italic;
  font-size: 0.9rem;
}

/* ---------- Modal (Wanted Poster Style) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--parchment);
  border: 3px double var(--ink);
  width: 400px;
  padding: 20px;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.5);
  transform: scale(0.95) rotate(-1deg);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: scale(1) rotate(0deg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 10px;
}

.modal-header h2 {
  font-family: var(--font-title);
  font-size: 2rem;
  color: var(--wanted-red);
}

.modal-close {
  background: none;
  border: none;
  box-shadow: none;
  font-size: 2rem;
  line-height: 1;
}
.modal-close:hover { color: var(--wanted-red); }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-weight: bold;
}

.form-group input {
  padding: 8px;
  background: rgba(255,255,255,0.3);
  border: 1px solid var(--ink-light);
  font-family: var(--font-mono);
  outline: none;
}
.form-group input:focus { border-color: var(--wanted-red); }

.form-textarea {
  padding: 8px;
  background: rgba(255,255,255,0.3);
  border: 1px solid var(--ink-light);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
  width: 100%;
  color: var(--ink);
  line-height: 1.5;
}
.form-textarea:focus { border-color: var(--wanted-red); }

.shortcut-recorder {
  padding: 10px;
  border: 1px dashed var(--ink-light);
  text-align: center;
  font-family: var(--font-mono);
  cursor: pointer;
  background: rgba(255,255,255,0.2);
}
.shortcut-recorder:focus { border-style: solid; border-color: var(--wanted-red); }
.shortcut-recorder.recorded { background: rgba(0,0,0,0.05); font-weight: bold; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-cancel, .btn-create {
  padding: 8px 15px;
  font-weight: bold;
  font-size: 1.1rem;
}
.btn-create { background: var(--ink); color: var(--parchment); }

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.toast {
  background: var(--parchment);
  border: 2px solid var(--ink);
  padding: 10px 15px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-weight: 600;
  animation: slideIn 0.3s forwards;
}

.toast.toast-out { animation: slideOut 0.3s forwards; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  to { transform: translateX(100%); opacity: 0; }
}

/* ---------- AI Elements ---------- */
.ai-settings-btn {
  background: var(--marine-blue);
  color: var(--parchment);
  border: 1px solid var(--ink);
  font-family: var(--font-title);
  font-size: 1.2rem;
  padding: 5px 12px;
  box-shadow: 2px 2px 0 var(--ink);
}
.ai-settings-btn:hover { background: #153048; }
.ai-settings-btn:active { box-shadow: 0 0 0 var(--ink); }

.ai-generate-btn {
  background: var(--gold);
  color: var(--ink);
  border: 1px solid var(--ink);
  font-family: var(--font-title);
  font-size: 1.2rem;
  padding: 5px 12px;
  box-shadow: 2px 2px 0 var(--ink);
  margin-right: 15px;
}
.ai-generate-btn:hover { background: #966f08; }
.ai-generate-btn:active { box-shadow: 0 0 0 var(--ink); }
.ai-generate-btn.loading { opacity: 0.7; cursor: wait; pointer-events: none; }

.form-select {
  padding: 8px;
  background: rgba(255,255,255,0.3);
  border: 1px solid var(--ink-light);
  font-family: var(--font-mono);
  outline: none;
  width: 100%;
}
.form-select:focus { border-color: var(--wanted-red); }

/* ---------- Responsive / Mobile ---------- */
@media (max-width: 768px) {
  html, body {
    overflow-y: auto; /* Allow scrolling on mobile if needed */
    overscroll-behavior-y: none; /* Block pull-to-refresh */
  }

  .app-container {
    width: 100vw;
    height: 100vh;
    height: 100svh; /* Handle mobile browser UI correctly */
    border: none;
    border-radius: 0;
  }
  
  .app-header {
    padding: 8px 10px;
  }

  .header-title h1 {
    font-size: 1.2rem;
  }

  .header-subtitle {
    font-size: 0.75rem;
  }

  .straw-hat-icon {
    font-size: 20px;
  }

  .bounty-value {
    font-size: 1.1rem;
  }

  .toolbar {
    padding: 5px 10px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .toolbar-section, .tag-buttons {
    flex-wrap: nowrap;
  }

  .tag-btn kbd {
    display: none; /* Hide shortcuts on mobile to save horizontal space */
  }

  .editor-wrapper {
    margin: 5px;
  }

  .editor-textarea {
    font-size: 1rem;
    padding: 10px;
  }

  .bottom-bar {
    padding: 5px 10px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .stats-section, .export-section, .export-group {
    flex-wrap: nowrap;
  }

  .stat-item {
    font-size: 0.8rem;
  }

  .modal {
    width: 95vw;
    padding: 15px;
  }
}
