/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Gaegu&family=Nanum+Pen+Script&display=swap');

/* Yuja EDU Design Tokens - v2 Lemon Refresh */
:root {
  /* Primary */
  --color-yuja-lemon: #FFE135;
  --color-yuja-lemon-amber: #F5C800;
  --color-yuja-forest: #142814;
  --color-yuja-forest-mid: #1E3D1E;
  --color-yuja-lemon-tint: #FEFCE8;
  
  /* Secondary (Leaf Green) */
  --color-leaf-green: #4CAA48;
  --color-leaf-green-mid: #388E3C;
  --color-leaf-green-deep: #2D7A29;
  --color-leaf-green-light: #B8E0B5;
  --color-leaf-green-tint: #E8F5E7;
  
  /* Notion Canvas */
  --color-canvas: #FFFFFF;
  --color-canvas-cream: #F7F6F3;
  --color-surface: #F1F0EE;
  --color-hairline: #E8E7E4;
  --color-hairline-strong: #D3D1CB;
  
  /* Text */
  --color-ink-deep: #1A1A1A;
  --color-ink: #37352F;
  --color-charcoal: #4B4945;
  --color-slate: #6F6E69;
  --color-steel: #9B9A97;
  --color-on-dark: #FFFFFF;
  --color-on-dark-muted: rgba(255,255,255,0.70);
  
  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-card: rgba(15, 15, 15, 0.08) 0px 4px 12px 0px;
  --shadow-mockup: rgba(15, 15, 15, 0.18) 0px 20px 40px -8px;
  
  /* Typography */
  --font-primary: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  font-family: var(--font-primary);
  background-color: var(--color-canvas-cream);
  color: var(--color-ink);
  line-height: 1.6;
  letter-spacing: -0.01em;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Typography Classes */
.text-hero { font-size: 72px; font-weight: 700; line-height: 1.05; letter-spacing: -2px; }
.text-display-lg { font-size: 52px; font-weight: 700; line-height: 1.10; letter-spacing: -1.5px; }
.text-h1 { font-size: 44px; font-weight: 700; line-height: 1.15; letter-spacing: -1px; }
.text-h2 { font-size: 32px; font-weight: 700; line-height: 1.20; letter-spacing: -0.5px; }
.text-h3 { font-size: 24px; font-weight: 600; line-height: 1.25; }
.text-h4 { font-size: 20px; font-weight: 600; line-height: 1.30; }
.text-body-md { font-size: 16px; font-weight: 400; line-height: 1.60; }
.text-body-md-medium { font-size: 16px; font-weight: 500; line-height: 1.60; }
.text-body-sm { font-size: 14px; font-weight: 400; line-height: 1.50; }
.text-body-sm-medium { font-size: 14px; font-weight: 500; line-height: 1.50; }
.text-caption-bold { font-size: 13px; font-weight: 600; line-height: 1.40; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: all 150ms ease;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background-color: var(--color-yuja-lemon-amber);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 500;
  padding: 14px 28px;
  border-radius: var(--radius-full);
  height: 50px;
}

.btn-secondary {
  background-color: transparent;
  color: var(--color-ink);
  border: 1px solid var(--color-hairline-strong);
  font-size: 14px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
}

.btn-primary:hover {
  background-color: #E5B900;
}

.btn-secondary:hover {
  background-color: var(--color-surface);
}

.tab-btn:hover:not(.active) {
  background-color: rgba(0,0,0,0.05);
}

.btn-group .btn:hover:not(.active) {
  background-color: rgba(0,0,0,0.05);
}

/* Header & Nav */
.promo-banner {
  background-color: var(--color-leaf-green-light);
  color: var(--color-ink);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 8px 16px;
}

.top-nav {
  position: sticky;
  top: 0;
  background-color: var(--color-canvas);
  height: 64px;
  border-bottom: 1px solid var(--color-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  z-index: 100;
  box-shadow: var(--shadow-card);
}

.nav-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-ink-deep);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Layout */
.app-container {
  display: flex;
  flex: 1;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  padding: 24px;
  gap: 24px;
}

.settings-panel {
  width: 460px;
  position: sticky;
  top: 88px; /* nav(64) + padding(24) */
  height: calc(100dvh - 112px);
  overflow-y: auto;
  background-color: var(--color-canvas);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-hairline);
  padding: 24px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-btn.active {
  background-color: var(--color-yuja-lemon-amber);
  color: #FFFFFF;
}

/* Section Navigation under Type Tabs */
.section-nav {
  display: flex;
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.section-btn {
  flex: 1;
  padding: 7px 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-charcoal);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
}

.section-btn.active {
  background-color: var(--color-canvas);
  color: var(--color-ink-deep);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.preview-region {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
}

.preview-scale-wrapper {
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: flex-start;
  align-items: center;
  transform-origin: top center;
  transition: transform 0.15s ease;
  padding-top: 20px;
}

.preview-container {
  background-color: var(--color-canvas);
  width: 210mm;
  height: 297mm;
  max-width: 210mm;
  max-height: 297mm;
  aspect-ratio: 210 / 297;
  box-sizing: border-box;
  box-shadow: var(--shadow-mockup);
  padding: 15mm;
  border: 1px solid var(--color-hairline);
  position: relative;
  overflow: hidden;
}

.btn-delete-page {
  position: absolute;
  top: 15mm;
  right: 15mm;
  background-color: var(--color-surface);
  color: var(--color-charcoal);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  opacity: 0;
  transition: all 150ms ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.preview-container:hover .btn-delete-page {
  opacity: 1;
}

.btn-delete-page:hover {
  background-color: #ffeaea;
  color: #d32f2f;
}

/* Tabs */
.tabs-header {
  display: flex;
  background-color: var(--color-surface);
  border-radius: var(--radius-full);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-slate);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
}

/* Card Groups */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-group-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-ink-deep);
  border-bottom: 1px solid var(--color-hairline);
  padding-bottom: 8px;
  margin-top: 8px;
}

/* Forms */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flex-between {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.form-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-charcoal);
}

.mb-sm { margin-bottom: 8px; }

.form-input, .form-select, .form-textarea {
  background-color: var(--color-canvas);
  color: var(--color-ink);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  transition: border-color 150ms ease;
}

.form-textarea {
  resize: vertical;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--color-yuja-lemon-amber);
}

.form-select:disabled {
  background-color: var(--color-surface);
  color: var(--color-steel);
  cursor: not-allowed;
}

.w-full { width: 100%; }
.w-auto { width: auto; }
.w-60 { width: 60px; }
.text-center { text-align: center; }

/* Radio and Button Groups */
.radio-group {
  display: flex;
  gap: 16px;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

.btn-group {
  display: flex;
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 2px;
}

.btn-group.full-width {
  width: 100%;
}

.db-checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--color-charcoal);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--color-canvas);
  cursor: pointer;
  transition: background 150ms ease;
  line-height: 1.4;
}
.db-checklist-item:hover {
  background: var(--color-surface);
}
.db-checklist-item input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--color-yuja-lemon-amber);
  cursor: pointer;
}

.btn-group .btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  color: var(--color-charcoal);
}

.btn-group .btn.active {
  background-color: var(--color-canvas);
  color: var(--color-ink-deep);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Number Control */
.number-control {
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-ghost {
  background: transparent;
  color: var(--color-slate);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-ghost:hover {
  background-color: var(--color-surface);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--color-hairline-strong);
  transition: .2s;
  border-radius: 24px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider {
  background-color: var(--color-yuja-lemon-amber);
}
input:checked + .slider:before {
  transform: translateX(20px);
}

/* Range Slider */
.form-range {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--color-hairline-strong);
  outline: none;
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-yuja-lemon-amber);
  cursor: pointer;
}

/* Print */
@media print {
  .promo-banner, .top-nav, .settings-panel, .btn-delete-page, #btnAddPageBottom {
    display: none !important;
  }
  
  .sentence-block {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  
  .app-container {
    padding: 0;
    margin: 0;
    max-width: none;
    display: block;
  }
  
  .preview-region {
    display: block;
  }
  
  .preview-scale-wrapper {
    transform: none !important;
    width: auto !important;
    height: auto !important;
    gap: 0 !important;
    padding: 0 !important;
  }

  .page-container {
    page-break-after: always;
    break-after: page;
  }
  
  .page-container:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .preview-container {
    width: 210mm !important;
    height: 297mm !important;
    max-width: 210mm !important;
    max-height: 297mm !important;
    aspect-ratio: 210 / 297 !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    padding: 15mm !important;
    overflow: hidden !important;
  }

  .preview-container.landscape {
    width: 297mm !important;
    height: 210mm !important;
    max-width: 297mm !important;
    max-height: 210mm !important;
    aspect-ratio: 297 / 210 !important;
  }
  
  @page {
    size: A4;
    margin: 0;
  }
  
  body {
    background-color: white;
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }
  
  .settings-panel {
    width: 100%;
    position: static;
    height: auto;
  }
}

/* Preview Content Styling */
.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 30px;
  border-bottom: 2px solid var(--color-hairline-strong);
  padding-bottom: 15px;
}

.print-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-ink-deep);
}

.print-meta {
  display: flex;
  gap: 30px;
  font-size: 16px;
  color: var(--color-charcoal);
}

.print-name-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.name-line {
  display: inline-block;
  width: 100px;
  border-bottom: 1px solid var(--color-charcoal);
}

.render-area {
  display: flex;
  flex-direction: column;
}

/* Sentence Block */
.sentence-block {
  display: flex;
  margin-bottom: 20px;
}

.sentence-number {
  font-weight: 700;
  font-size: 16px;
  color: var(--color-slate);
  width: 30px;
  flex-shrink: 0;
  padding-top: 8px;
}

.sentence-grid-container {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.grid-row {
  display: flex;
  flex-wrap: wrap;
}

/* Character Cell */
.char-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-hairline-strong);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  margin-left: -1px;
  margin-top: -1px;
}

.layout-line .char-cell {
  border: none;
  border-bottom: 1px solid var(--color-hairline-strong);
  aspect-ratio: auto;
  height: auto;
  margin-top: 0;
}

/* Guides */
.guide-center::before, .guide-center::after,
.guide-cross::before, .guide-cross::after {
  content: '';
  position: absolute;
  background-color: var(--color-hairline);
  z-index: 1;
}

.guide-center::before, .guide-cross::before {
  top: 50%; left: 0; right: 0; height: 1px;
}
.guide-center::after, .guide-cross::after {
  left: 50%; top: 0; bottom: 0; width: 1px;
}

.guide-cross {
  background-image: linear-gradient(to bottom right, transparent 48%, var(--color-hairline) 49%, var(--color-hairline) 51%, transparent 52%),
                    linear-gradient(to top right, transparent 48%, var(--color-hairline) 49%, var(--color-hairline) 51%, transparent 52%);
}

.guide-circle::before {
  content: '';
  position: absolute;
  top: 10%; left: 10%; right: 10%; bottom: 10%;
  border: 1px dashed var(--color-hairline-strong);
  border-radius: 50%;
  z-index: 1;
}

.char-text {
  position: relative;
  z-index: 2;
  line-height: 1;
}

.tracing-text {
  color: var(--color-ink);
  opacity: 0.15; /* Will be set via inline style based on slider */
}

/* A4 Landscape Adjustments */
.preview-container.landscape {
  width: 297mm;
  height: 210mm;
  max-width: 297mm;
  max-height: 210mm;
  aspect-ratio: 297 / 210;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-hairline-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-steel);
}
