/* ==========================================================================
   Google Docs Inspired Chinese Pinyin Typing App
   Tối ưu hiển thị đa nền tảng: Windows, Android, iOS
   ========================================================================== */

:root {
  --docs-bg: #f9fbfd;
  --docs-header-bg: #ffffff;
  --docs-toolbar-bg: #edf2fa;
  --docs-border: #dadce0;
  --docs-text: #202124;
  --docs-text-muted: #5f6368;
  --docs-primary: #1a73e8;
  --docs-primary-hover: #1557b0;
  --docs-primary-light: #e8f0fe;
  --docs-danger: #d93025;
  --docs-success: #1e8e3e;
  --page-bg: #ffffff;
  --page-shadow: 0 1px 3px 1px rgba(60,64,67,0.15), 0 2px 8px 4px rgba(60,64,67,0.08);
  --ruler-bg: #f1f3f4;
  --font-family-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --editor-font: 'FZKTPY01', 'FangSong', 'SimSun', serif;
  --editor-font-size: 26pt;
  --editor-line-height: 2.3;
}

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

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

/* ==========================================================================
   Top Header (Google Docs Title & Action Buttons)
   ========================================================================== */
.docs-header {
  background: var(--docs-header-bg);
  padding: 8px 16px 4px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e0e0e0;
  z-index: 50;
}

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

.docs-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: white;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(26,115,232,0.3);
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.2s;
}

.docs-logo:hover {
  transform: scale(1.05);
}

.doc-info {
  display: flex;
  flex-direction: column;
}

.doc-title-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-title-input {
  font-size: 18px;
  font-weight: 500;
  color: var(--docs-text);
  border: 1px solid transparent;
  padding: 3px 8px;
  border-radius: 4px;
  background: transparent;
  outline: none;
  transition: all 0.2s;
  max-width: 320px;
}

.doc-title-input:hover {
  border-color: var(--docs-border);
  background: #f8f9fa;
}

.doc-title-input:focus {
  border-color: var(--docs-primary);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}

.save-badge {
  font-size: 12px;
  color: var(--docs-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.save-badge svg {
  width: 14px;
  height: 14px;
  fill: var(--docs-success);
}

/* Menu items */
.doc-menubar {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}

.menu-item {
  font-size: 13px;
  padding: 2px 7px;
  border-radius: 4px;
  color: #3c4043;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: background 0.15s;
}

.menu-item:hover {
  background: #e8eaed;
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #ffffff;
  border: 1px solid #dadce0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  border-radius: 6px;
  padding: 6px 0;
  min-width: 190px;
  z-index: 1000;
}

.menu-item.active .menu-dropdown {
  display: block;
}

.menu-option {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #202124;
}

.menu-option:hover {
  background: #f1f3f4;
}

.menu-divider {
  height: 1px;
  background: #e8eaed;
  margin: 4px 0;
}

/* Header Right Actions */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-samples {
  background: #fef7e0;
  color: #b06000;
  border-color: #fce8b2;
}

.btn-samples:hover {
  background: #feefc3;
}

.btn-audio {
  background: #e6f4ea;
  color: #137333;
  border-color: #ceead6;
}

.btn-audio:hover {
  background: #ceead6;
}

.btn-audio.playing {
  background: #fce8e6;
  color: #c5221f;
  border-color: #fad2cf;
  animation: pulse-ring 1.5s infinite;
}

.btn-print {
  background: var(--docs-primary);
  color: white;
}

.btn-print:hover {
  background: var(--docs-primary-hover);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.btn-guide {
  background: #f1f3f4;
  color: #3c4043;
}

.btn-guide:hover {
  background: #e8eaed;
}

/* ==========================================================================
   Toolbar (Google Docs Style)
   ========================================================================== */
.docs-toolbar {
  background: var(--docs-toolbar-bg);
  padding: 4px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 24px;
  margin: 6px 16px;
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 1px 2px rgba(60,64,67,0.08);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.docs-toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #444746;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.15s;
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: rgba(68, 71, 70, 0.12);
}

.toolbar-btn.active {
  background: #d3e3fd;
  color: #041e49;
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: #c7c7c7;
  margin: 0 4px;
  flex-shrink: 0;
}

.toolbar-select {
  height: 32px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  color: #444746;
  cursor: pointer;
  outline: none;
  font-weight: 500;
  transition: all 0.15s;
  flex-shrink: 0;
}

.toolbar-select:hover {
  background: rgba(68, 71, 70, 0.12);
}

.toolbar-select:focus {
  background: #ffffff;
  border-color: var(--docs-primary);
}

/* Font Selector Specific */
#fontFamilySelect {
  max-width: 220px;
  font-weight: 600;
  color: #1a73e8;
}

/* Font Size Control */
.font-size-control {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.7);
  border-radius: 4px;
  border: 1px solid #d0d7de;
  overflow: hidden;
  height: 30px;
  flex-shrink: 0;
}

.font-size-btn {
  background: transparent;
  border: none;
  width: 26px;
  height: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #444746;
}

.font-size-btn:hover {
  background: #e8eaed;
}

#fontSizeInput {
  width: 44px;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #1f1f1f;
  background: transparent;
  outline: none;
}

/* Color Pickers */
.color-picker-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}

.color-picker-label:hover {
  background: rgba(68, 71, 70, 0.12);
}

.color-picker-label input[type="color"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.color-bar {
  width: 16px;
  height: 3px;
  position: absolute;
  bottom: 5px;
  border-radius: 2px;
}

/* Pinyin Quick Bar */
.pinyin-tones-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
}

.tone-btn {
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 13px;
  font-weight: 500;
  color: #3c4043;
  cursor: pointer;
  transition: all 0.15s;
}

.tone-btn:hover {
  background: #e8f0fe;
  color: #1a73e8;
  border-color: #1a73e8;
}

/* ==========================================================================
   Ruler
   ========================================================================== */
.docs-ruler-container {
  display: flex;
  justify-content: center;
  background: transparent;
  margin-bottom: 2px;
  overflow: hidden;
  user-select: none;
}

.docs-ruler {
  width: 816px; /* A4 width standard at 96 DPI */
  height: 14px;
  background: var(--ruler-bg);
  border-bottom: 1px solid #d3d3d3;
  display: flex;
  position: relative;
  border-radius: 2px 2px 0 0;
}

.ruler-tick {
  position: absolute;
  bottom: 0;
  height: 4px;
  width: 1px;
  background: #a0a0a0;
}

.ruler-tick.major {
  height: 8px;
  background: #606060;
}

.ruler-marker-left, .ruler-marker-right {
  position: absolute;
  top: 1px;
  width: 0;
  height: 0;
  border-style: solid;
  cursor: pointer;
}

.ruler-marker-left {
  left: 54px;
  border-width: 7px 5px 0 5px;
  border-color: #1a73e8 transparent transparent transparent;
}

.ruler-marker-right {
  right: 54px;
  border-width: 7px 5px 0 5px;
  border-color: #1a73e8 transparent transparent transparent;
}

/* ==========================================================================
   Editor Workspace & A4 Page Canvas
   ========================================================================== */
.workspace-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px 60px 16px;
  background: var(--docs-bg);
  position: relative;
}

.page-wrapper {
  transition: transform 0.2s ease-out;
  transform-origin: top center;
  margin-bottom: 40px;
}

/* Standard A4 Paper Style */
.doc-page {
  width: 816px;
  min-height: 1056px;
  background: var(--page-bg);
  box-shadow: var(--page-shadow);
  padding: 60px 65px;
  border-radius: 2px;
  position: relative;
  outline: none;
}

/* Content Editable Area */
.doc-content {
  min-height: 900px;
  outline: none;
  font-family: 'FZKTPY01', 'FangSong', 'SimSun', serif;
  font-size: 26pt;
  line-height: 2.3;
  color: #111111;
  letter-spacing: 2px;
  word-break: break-word;
  white-space: pre-wrap;
}

.doc-content:empty:before {
  content: attr(data-placeholder);
  color: #9aa0a6;
  font-family: var(--font-family-ui);
  font-size: 18px;
  letter-spacing: normal;
  line-height: 1.6;
  pointer-events: none;
  display: block;
}

/* ==========================================================================
   Bottom Status Bar
   ========================================================================== */
.docs-statusbar {
  background: #ffffff;
  border-top: 1px solid var(--docs-border);
  padding: 6px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--docs-text-muted);
  flex-shrink: 0;
  z-index: 40;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-value {
  font-weight: 600;
  color: var(--docs-text);
}

.font-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: #e6f4ea;
  color: #137333;
  border-radius: 12px;
  font-weight: 500;
}

.font-indicator.loading {
  background: #feefc3;
  color: #b06000;
}

.font-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ==========================================================================
   Modals & Popups
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  width: 90%;
  max-width: 760px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #e8eaed;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 18px;
  color: var(--docs-text);
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: #5f6368;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover {
  background: #f1f3f4;
}

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

/* Samples Modal Cards */
.samples-category-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--docs-primary);
  margin: 16px 0 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.samples-category-title:first-child {
  margin-top: 0;
}

.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.sample-card {
  border: 1px solid #dadce0;
  border-radius: 8px;
  padding: 14px;
  background: #fafbfc;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sample-card:hover {
  border-color: var(--docs-primary);
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(26,115,232,0.15);
  transform: translateY(-2px);
}

.sample-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f1f1f;
  margin-bottom: 6px;
}

.sample-card-preview {
  font-size: 13px;
  color: #5f6368;
  font-family: 'FZKTPY01', 'FangSong', 'SimSun', serif;
  line-height: 1.8;
  max-height: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}

.sample-card-desc {
  font-size: 12px;
  color: #80868b;
}

/* Guide Tabs & Content */
.guide-tip {
  background: #e8f0fe;
  border-left: 4px solid var(--docs-primary);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 16px;
  color: #174ea6;
}

.guide-step {
  margin-bottom: 16px;
}

.guide-step h4 {
  font-size: 15px;
  color: #202124;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-step p, .guide-step li {
  font-size: 13px;
  color: #3c4043;
  line-height: 1.6;
}

.guide-step ul {
  padding-left: 20px;
  margin-top: 4px;
}

.kbd-badge {
  background: #f1f3f4;
  border: 1px solid #dadce0;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 12px;
  color: #202124;
}

/* Audio control panel */
.audio-player-bar {
  display: none;
  background: #e8f0fe;
  border-top: 1px solid #d2e3fc;
  padding: 8px 20px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #174ea6;
}

.audio-player-bar.active {
  display: flex;
}

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

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

.toast {
  background: #323232;
  color: white;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.3s ease;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(217,48,37, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(217,48,37, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217,48,37, 0); }
}

/* ==========================================================================
   Print Styles (Optimized for saving to PDF / Paper)
   ========================================================================== */
@media print {
  body {
    background: white;
    height: auto;
    overflow: visible;
  }

  .docs-header,
  .docs-toolbar,
  .docs-ruler-container,
  .docs-statusbar,
  .audio-player-bar,
  .modal-overlay,
  .toast-container {
    display: none !important;
  }

  .workspace-container {
    padding: 0;
    margin: 0;
    overflow: visible;
  }

  .page-wrapper {
    transform: none !important;
    margin: 0 !important;
  }

  .doc-page {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    min-height: auto !important;
    padding: 20mm 20mm !important;
  }

  .doc-content {
    min-height: auto !important;
    font-size: 24pt !important;
    line-height: 2.3 !important;
  }
}

/* ==========================================================================
   Responsive Adaptations (Mobile Android & iOS Safari)
   ========================================================================== */
@media (max-width: 860px) {
  .docs-header {
    padding: 6px 10px;
  }

  .doc-title-input {
    font-size: 15px;
    max-width: 160px;
  }

  .doc-menubar {
    display: none; /* Hide submenu on mobile to save space */
  }

  .header-right {
    gap: 6px;
  }

  .btn-header span {
    display: none; /* Keep only icons on mobile */
  }

  .btn-header {
    padding: 6px 10px;
  }

  .docs-toolbar {
    margin: 4px 6px;
    padding: 4px 8px;
  }

  .docs-ruler-container {
    display: none; /* Hide ruler on mobile */
  }

  .workspace-container {
    padding: 10px 4px 50px 4px;
  }

  .doc-page {
    width: 96vw !important;
    padding: 25px 20px !important;
    min-height: 80vh !important;
  }

  .doc-content {
    font-size: 20pt !important;
    line-height: 2.2 !important;
  }

  .docs-statusbar {
    padding: 4px 10px;
    font-size: 11px;
  }
}
