@import url('https://fonts.googleapis.com/css2?family=Bai+Jamjuree:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400&family=Inter:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700&family=Pridi:wght@300;400;500;600;700&family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400&display=swap');

/* --- Design Tokens & CSS Variables --- */
:root {
  --bg-workspace: #0d0e12;
  --bg-sidebar: #13151b;
  --bg-card: #1b1e26;
  --bg-card-hover: #222731;
  --border-color: #2b303c;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dark: #1f2937;
  
  --color-gold: #d4af37;
  --color-gold-hover: #f3cf65;
  --color-gold-glow: rgba(212, 175, 55, 0.15);
  
  --color-accent: #8b5cf6;
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.1);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.1);
  --color-success: #10b981;
  
  --font-ui: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  --font-book-serif: 'Pridi', serif;
  --font-book-sans: 'Sarabun', 'Bai Jamjuree', sans-serif;
  
  /* Book Styles */
  --book-page-bg: #faf7f0; /* Cream paper */
  --book-text-color: #2c251e; /* Soft sepia-charcoal for reading comfort */
  --book-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  --page-shadow-left: inset -15px 0 20px rgba(0, 0, 0, 0.05), 5px 0 10px rgba(0, 0, 0, 0.05);
  --page-shadow-right: inset 15px 0 20px rgba(0, 0, 0, 0.05), -5px 0 10px rgba(0, 0, 0, 0.05);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-workspace);
  color: var(--text-main);
  font-family: var(--font-ui);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Layout --- */
header {
  height: 60px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-gold), #b58d1d);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  font-weight: bold;
  font-size: 1.2rem;
  box-shadow: 0 0 15px var(--color-gold-glow);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, #ffffff, #d4af37);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* Main Container */
.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* --- Left Sidebar (Controls & Linter) --- */
.sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section h3 svg {
  width: 16px;
  height: 16px;
}

/* Control Elements */
.control-group {
  margin-bottom: 16px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 8px;
}

.control-val {
  font-weight: 600;
  color: var(--color-gold);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--color-gold);
  background: var(--border-color);
  height: 6px;
  border-radius: 3px;
  outline: none;
}

select {
  width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}

select:focus {
  border-color: var(--color-gold);
}

.btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-gold), #b58d1d);
  color: #0d0e12;
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--color-gold-hover), var(--color-gold));
  box-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

.btn-glowing-gold {
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.25);
  animation: pulse-glow 2s infinite alternate;
}

@keyframes pulse-glow {
  0% {
    box-shadow: 0 0 6px rgba(212, 175, 55, 0.2);
    transform: scale(1);
  }
  100% {
    box-shadow: 0 0 16px rgba(212, 175, 55, 0.55);
    transform: scale(1.02);
  }
}


.btn-outline-gold {
  border-color: var(--color-gold);
  color: var(--color-gold);
  background: transparent;
}

.btn-outline-gold:hover {
  background: var(--color-gold-glow);
  border-color: var(--color-gold-hover);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

/* Linter List */
.linter-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.linter-item {
  padding: 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.linter-item.warning {
  background-color: var(--color-warning-bg);
  border-left: 3px solid var(--color-warning);
}

.linter-item.danger {
  background-color: var(--color-danger-bg);
  border-left: 3px solid var(--color-danger);
}

.linter-item:hover {
  transform: translateX(4px);
}

.linter-header {
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.linter-header .badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.linter-item.warning .badge {
  background: var(--color-warning);
  color: #000;
}

.linter-item.danger .badge {
  background: var(--color-danger);
  color: #fff;
}

.linter-desc {
  color: var(--text-muted);
}

.linter-action {
  font-size: 0.75rem;
  color: var(--color-gold);
  text-decoration: underline;
  align-self: flex-end;
}

.empty-linter {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-linter svg {
  color: var(--color-success);
  width: 24px;
  height: 24px;
}

/* --- Workspace Split --- */
.workspace-split {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Left Pane: Editor --- */
.editor-pane {
  flex: 1;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background-color: #0a0a0d;
}

.pane-header {
  height: 48px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.pane-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-actions {
  display: flex;
  gap: 8px;
}

.editor-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.textarea-container {
  flex: 1;
  position: relative;
  display: flex;
}

.line-numbers {
  width: 40px;
  padding: 12px 8px;
  text-align: right;
  font-family: monospace;
  font-size: 0.9rem;
  color: #3f4756;
  background: transparent;
  border-right: 1px solid #1f232d;
  user-select: none;
  overflow: hidden;
  line-height: 1.6;
}

textarea.editor-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e5e7eb;
  font-family: var(--font-book-sans);
  font-size: 1.05rem;
  line-height: 1.6;
  resize: none;
  padding: 12px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Quick Tools Bar below editor */
.quick-tools-bar {
  background-color: var(--bg-sidebar);
  border-top: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.tool-sep {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

/* --- Right Pane: Book Simulator --- */
.preview-pane {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  background-color: #16181f;
  background-image: radial-gradient(circle at center, #1b1e26 0%, #0d0e12 100%);
  position: relative;
  overflow: hidden;
}

.book-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  overflow-y: auto;
  perspective: 1000px;
}

/* Elegant Book Frame representing the physical book */
.book-wrapper {
  display: flex;
  width: 100%;
  max-width: 820px;
  height: 540px;
  background-color: var(--book-page-bg);
  box-shadow: var(--book-shadow);
  border-radius: 6px 12px 12px 6px;
  position: relative;
  transition: transform 0.5s ease;
  overflow: hidden;
}

/* Spine effect in the center of the book */
.book-spine {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 100%;
  background: linear-gradient(to right, 
    rgba(0,0,0,0.18) 0%, 
    rgba(0,0,0,0.05) 30%, 
    rgba(255,255,255,0.15) 50%, 
    rgba(0,0,0,0.05) 70%, 
    rgba(0,0,0,0.18) 100%
  );
  box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
  z-index: 5;
  pointer-events: none;
}

/* Book pages */
.book-page {
  flex: 1;
  height: 100%;
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  color: var(--book-text-color);
  background-color: var(--book-page-bg);
}

.book-page.left-page {
  box-shadow: var(--page-shadow-left);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.book-page.right-page {
  box-shadow: var(--page-shadow-right);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
}

/* Headers & Footers in Book */
.book-header {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: rgba(44, 37, 30, 0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(44, 37, 30, 0.08);
  padding-bottom: 6px;
  margin-bottom: 20px;
  height: 18px;
  user-select: none;
}

.book-footer {
  margin-top: auto;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: rgba(44, 37, 30, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 10px;
  height: 18px;
  user-select: none;
}

/* Page Content Formatting */
.book-body {
  flex: 1;
  font-size: 1rem;
  line-height: 1.6;
  position: relative;
}

.book-body.font-serif {
  font-family: var(--font-book-serif);
}

.book-body.font-sans {
  font-family: var(--font-book-sans);
}

/* Rules visualization styling */
.half-page-start {
  height: 40%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px dashed rgba(212, 175, 55, 0.25);
  margin-bottom: 20px;
  position: relative;
}

.half-page-start::after {
  content: "เริ่มที่ครึ่งหน้า (7-9 บรรทัด)";
  position: absolute;
  bottom: 4px;
  right: 0;
  font-size: 0.65rem;
  color: var(--color-gold);
  font-family: var(--font-ui);
  background: rgba(26, 26, 36, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  transform: translateY(50%);
  opacity: 0.8;
}

/* Chapter Title Cover styling */
.chapter-title-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  text-align: center;
}

.chapter-number {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--color-gold);
  margin-bottom: 16px;
}

.chapter-name {
  font-family: var(--font-book-serif);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--book-text-color);
  margin-bottom: 40px;
  line-height: 1.3;
}

/* Cheedab Content Elements rendered inside pages */
.cheedab-p {
  margin-bottom: 1.5em; /* เคาะย่อหน้า = เคาะ 2 บรรทัด */
  text-indent: 2em;
}

.cheedab-line {
  margin-bottom: 0.5em; /* เคาะใจความ = เคาะ 1 บรรทัด */
  text-indent: 2em;
  display: block;
}

/* Hook line styling: centered or uniquely spaced with bold/italic */
.cheedab-hook {
  margin: 2em 0; /* เคาะ hook = เคาะ 2 บรรทัด และเว้น 2 บรรทัด */
  text-align: center;
  font-weight: bold;
  font-style: italic;
  font-size: 1.1rem;
  text-indent: 0 !important;
  color: #000;
  display: block;
  position: relative;
}

.cheedab-hook::before, .cheedab-hook::after {
  content: "";
  display: block;
  width: 40px;
  height: 1px;
  background: rgba(44, 37, 30, 0.15);
  margin: 8px auto;
}

/* Pause indicator ... */
.cheedab-pause {
  text-align: center;
  margin: 1.5em 0;
  font-weight: bold;
  letter-spacing: 6px;
  color: rgba(44, 37, 30, 0.4);
  text-indent: 0 !important;
  display: block;
}

/* Divider image/logo */
.cheedab-divider {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 2em 0;
  text-indent: 0 !important;
}

.cheedab-divider-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-gold);
  opacity: 0.7;
}

.cheedab-divider-logo svg {
  width: 20px;
  height: 20px;
}

.cheedab-divider::before, .cheedab-divider::after {
  content: "";
  flex: 1;
  max-width: 60px;
  height: 1px;
  background: rgba(44, 37, 30, 0.15);
  margin: 0 15px;
}

/* Highlight for linter issues in mockup */
.mockup-highlight {
  background-color: rgba(245, 158, 11, 0.12);
  border-bottom: 2px dashed var(--color-warning);
  cursor: pointer;
  position: relative;
}

.mockup-highlight.too-long {
  background-color: rgba(239, 68, 68, 0.08);
  border-bottom: 2px dashed var(--color-danger);
}

/* Book Controls (Page indicators and navigation) */
.book-navigation {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 0 24px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-sidebar);
}

.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.nav-btn:hover:not(:disabled) {
  background: var(--color-gold);
  color: #000;
  border-color: var(--color-gold-hover);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-counter {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* --- Tutorial Modal / Preset Selection Drawer --- */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(7, 8, 10, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-smooth);
}

.tutorial-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.tutorial-modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  transform: scale(0.95);
  transition: var(--transition-smooth);
}

.tutorial-overlay.active .tutorial-modal {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  transition: var(--transition-smooth);
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Preset Cards */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
}

.preset-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: var(--transition-smooth);
  text-align: left;
}

.preset-card:hover {
  border-color: var(--color-gold);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.preset-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-gold);
  margin-bottom: 4px;
}

.preset-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--color-gold);
  color: var(--text-main);
  padding: 16px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateY(100px);
  opacity: 0;
  transition: var(--transition-smooth);
}

.toast.active {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  color: var(--color-gold);
}

/* --- Scrollbar Customization --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0f0f12;
}

::-webkit-scrollbar-thumb {
  background: #252833;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #383c4d;
}

/* Extra premium touch */
.glowing-amber-dot {
  width: 6px;
  height: 6px;
  background-color: var(--color-gold);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--color-gold);
  display: inline-block;
}
