/* ── CSS Variables (UtilityX palette) ─────────────────────── */
    :root {
      --primary-color: #667eea;
      --secondary-color: #764ba2;
      --success-color: #28a745;
      --error-color: #dc3545;
      --warning-color: #ffc107;
      --info-color: #17a2b8;
      --dark-color: #2c3e50;
    }

    /* ── Reset ────────────────────────────────────────────────── */
    *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
    html { scroll-behavior: smooth; }

    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      line-height: 1.6;
      background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
      min-height: 100vh;
      padding: 20px;
      padding-top: 60px;
    }

    /* ── Back Button ──────────────────────────────────────────── */
    .back-button {
      position: fixed;
      top: 10px;
      left: 20px;
      background: rgba(255,255,255,.95);
      color: #333;
      padding: 10px 20px;
      border-radius: 30px;
      text-decoration: none;
      font-weight: 600;
      font-size: .95rem;
      border: none;
      cursor: pointer;
      z-index: 1000;
      box-shadow: 0 2px 10px rgba(0,0,0,.1);
      transition: all .2s;
    }
    .back-button:hover { background: white; transform: translateX(-3px); box-shadow: 0 4px 15px rgba(0,0,0,.15); }

    /* ── Breadcrumb ───────────────────────────────────────────── */
    .breadcrumb-nav { max-width: 1200px; margin: 0 auto; padding: 0 20px 10px; }
    .breadcrumb { list-style: none; display: flex; gap: 8px; font-size: .9rem; flex-wrap: wrap; }
    .breadcrumb li { display: flex; align-items: center; color: rgba(255,255,255,.9); }
    .breadcrumb li:not(:last-child)::after { content: '›'; margin-left: 8px; color: rgba(255,255,255,.6); font-size: 1.2rem; }
    .breadcrumb a { color: white; text-decoration: none; transition: opacity .2s; }
    .breadcrumb a:hover { opacity: .8; text-decoration: underline; }
    .breadcrumb [aria-current="page"] { color: white; font-weight: 600; }

    /* ── Tool Switcher ────────────────────────────────────────── */
    .tool-switcher {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      background: rgba(255,255,255,.12);
      border: 1px solid rgba(255,255,255,.2);
      border-radius: 14px;
      padding: 10px 16px;
      margin: 0 auto 16px;
      max-width: 1200px;
    }
    .tool-switcher-label {
      color: rgba(255,255,255,.7);
      font-size: .8rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: .5px;
      margin-right: 4px;
      white-space: nowrap;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .tool-switch-btn {
      color: rgba(255,255,255,.85);
      text-decoration: none;
      font-size: .85rem;
      font-weight: 500;
      padding: 6px 14px;
      border-radius: 20px;
      border: 1px solid rgba(255,255,255,.2);
      background: rgba(255,255,255,.1);
      transition: all .2s;
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      cursor: pointer;
    }
    .tool-switch-btn:hover { background: rgba(255,255,255,.25); color: white; }
    .tool-switch-btn.active { background: white; color: #667eea; font-weight: 700; border-color: white; pointer-events: none; }

    /* ── Main Container ───────────────────────────────────────── */
    .container {
      max-width: 1200px;
      margin: 0 auto 40px;
      background: white;
      border-radius: 15px;
      box-shadow: 0 10px 30px rgba(0,0,0,.2);
      overflow: hidden;
    }

    /* ── Tool Header (dark bar) ───────────────────────────────── */
    .header {
      background: var(--dark-color);
      color: white;
      padding: 30px;
      text-align: center;
    }
    .header h1 { font-size: 2rem; margin-bottom: 8px; }
    .header p { color: rgba(255,255,255,.75); font-size: .95rem; }
    .header .privacy-note {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      background: rgba(255,255,255,.1);
      border: 1px solid rgba(255,255,255,.2);
      border-radius: 20px;
      padding: 5px 14px;
      font-size: .82rem;
      margin-top: 10px;
      color: rgba(255,255,255,.85);
    }

    /* ── Main Content ─────────────────────────────────────────── */
    .main-content { padding: 30px; }

    /* ── Two Column ───────────────────────────────────────────── */
    .two-column {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 30px;
      margin-bottom: 30px;
    }

    /* ── Upload Section ───────────────────────────────────────── */
    .upload-section {
      background: #f8f9fa;
      border-radius: 15px;
      padding: 25px;
    }
    .upload-section h3 {
      margin-bottom: 20px;
      color: #333;
      font-size: 1.3rem;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .upload-area {
      border: 3px dashed #ddd;
      border-radius: 15px;
      padding: 40px;
      text-align: center;
      cursor: pointer;
      transition: all .3s ease;
      background: #f9f9f9;
      margin-bottom: 20px;
    }
    .upload-area:hover, .upload-area.drag-over {
      border-color: var(--primary-color);
      background: rgba(102,126,234,.05);
      transform: scale(1.02);
    }
    .upload-area:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; }
    .upload-icon { margin-bottom: 12px; color: var(--primary-color); }
    .upload-area h3 { color: #444; font-size: 1.1rem; margin-bottom: 6px; }
    .upload-area p { color: #888; font-size: .9rem; }
    .browse-button {
      background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
      color: white;
      border: none;
      padding: 12px 30px;
      border-radius: 25px;
      font-size: 1rem;
      cursor: pointer;
      margin-top: 15px;
      font-weight: 600;
      transition: opacity .2s, transform .2s;
    }
    .browse-button:hover { opacity: .9; transform: translateY(-1px); }
    #file-input { display: none; }
    .file-info {
      margin-top: 15px;
      padding: 15px;
      background: white;
      border-radius: 10px;
      display: none;
      font-size: .9rem;
      line-height: 1.8;
    }
    .file-info.show { display: block; }
    .file-info .change-btn {
      display: inline-block;
      margin-top: 8px;
      font-size: .82rem;
      color: var(--primary-color);
      background: none;
      border: 1px solid var(--primary-color);
      border-radius: 20px;
      padding: 3px 12px;
      cursor: pointer;
      transition: all .2s;
    }
    .file-info .change-btn:hover { background: var(--primary-color); color: white; }

    /* ── Controls Section ─────────────────────────────────────── */
    .settings-section {
      background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
      border-radius: 15px;
      padding: 25px;
    }
    .settings-section h3 {
      margin-bottom: 20px;
      color: #333;
      font-size: 1.3rem;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .ctrl-label {
      font-size: .85rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .05em;
      color: #666;
      margin-bottom: 10px;
      display: block;
    }
    .ctrl-group { margin-bottom: 20px; }

    /* Rotation control buttons */
    .rotation-btns {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }
    .rot-btn {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      padding: 10px 16px;
      border-radius: 25px;
      border: none;
      font-size: .88rem;
      font-weight: 600;
      cursor: pointer;
      transition: all .2s;
    }
    .rot-btn:disabled { opacity: .45; cursor: not-allowed; }
    .rot-btn svg { width: 15px; height: 15px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2.2; }

    .rot-btn--all-l  { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }
    .rot-btn--all-l:hover:not(:disabled)  { opacity: .9; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(102,126,234,.4); }
    .rot-btn--all-r  { background: linear-gradient(135deg, #764ba2, #667eea); color: white; }
    .rot-btn--all-r:hover:not(:disabled)  { opacity: .9; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(118,75,162,.4); }
    .rot-btn--sel-l  { background: white; color: #667eea; border: 2px solid #667eea; }
    .rot-btn--sel-l:hover:not(:disabled)  { background: #667eea; color: white; }
    .rot-btn--sel-r  { background: white; color: #764ba2; border: 2px solid #764ba2; }
    .rot-btn--sel-r:hover:not(:disabled)  { background: #764ba2; color: white; }

    /* Select / Deselect quick buttons */
    .quick-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
    .quick-btn {
      padding: 6px 12px;
      background: white;
      border: 1px solid var(--primary-color);
      border-radius: 20px;
      cursor: pointer;
      font-size: .8rem;
      font-weight: 500;
      transition: all .2s;
    }
    .quick-btn:hover { background: var(--primary-color); color: white; }
    .quick-btn.active { background: var(--primary-color); color: white; }

    /* Selection info box */
    .selection-info {
      padding: 10px 14px;
      background: rgba(102,126,234,.1);
      border: 1px solid rgba(102,126,234,.25);
      border-radius: 8px;
      font-size: .9rem;
      display: none;
    }
    .selection-info.show { display: block; }
    .selection-info strong { color: var(--primary-color); }

    /* ── Preview / Pages Section ──────────────────────────────── */
    .preview-section {
      margin-top: 30px;
      background: #f8f9fa;
      border-radius: 15px;
      padding: 25px;
      display: none;
    }
    .preview-section.show { display: block; }
    .preview-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;
      flex-wrap: wrap;
      gap: 15px;
    }
    .preview-header h3 {
      font-size: 1.2rem;
      color: #333;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .preview-header h3 svg { color: var(--primary-color); }
    .preview-meta { font-size: .85rem; color: #777; }

    /* Pages grid */
    .pages-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
      gap: 14px;
    }

    /* Page card */
    .page-card {
      background: white;
      border-radius: 10px;
      box-shadow: 0 2px 8px rgba(0,0,0,.07);
      overflow: hidden;
      border: 2px solid transparent;
      transition: border-color .2s, box-shadow .2s, transform .2s;
      cursor: grab;
      position: relative;
      animation: cardIn .28s ease forwards;
      opacity: 0;
    }
    @keyframes cardIn {
      from { opacity: 0; transform: translateY(10px) scale(.97); }
      to   { opacity: 1; transform: translateY(0) scale(1); }
    }
    .page-card:hover { border-color: var(--primary-color); box-shadow: 0 4px 16px rgba(102,126,234,.2); transform: translateY(-2px); }
    .page-card.selected { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(102,126,234,.2); }
    .page-card.sortable-ghost { opacity: .3; background: #eef2ff; }
    .page-card.sortable-drag  { box-shadow: 0 10px 30px rgba(0,0,0,.15); cursor: grabbing; }

    .page-card__check { position: absolute; top: 8px; left: 8px; z-index: 2; }
    .page-card__check input[type=checkbox] { width: 17px; height: 17px; cursor: pointer; accent-color: var(--primary-color); }
    .page-card__num {
      position: absolute; top: 8px; right: 8px;
      background: rgba(0,0,0,.55); color: white;
      font-size: 10px; font-weight: 700;
      padding: 2px 7px; border-radius: 20px; z-index: 2;
    }
    .page-card__thumb {
      aspect-ratio: 3/4;
      background: #f1f5f9;
      display: flex; align-items: center; justify-content: center;
      overflow: hidden; position: relative;
    }
    .page-card__thumb canvas { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
    .thumb-placeholder { display: flex; flex-direction: column; align-items: center; gap: 7px; color: #aaa; font-size: 11px; }
    .thumb-loading {
      width: 22px; height: 22px;
      border: 2.5px solid #ddd;
      border-top-color: var(--primary-color);
      border-radius: 50%;
      animation: spin .7s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    .rotation-badge {
      position: absolute; bottom: 6px; right: 6px;
      background: var(--primary-color); color: white;
      font-size: 10px; font-weight: 700;
      padding: 2px 7px; border-radius: 10px; z-index: 2;
      opacity: 0; transform: scale(.8);
      transition: opacity .2s, transform .2s;
    }
    .rotation-badge.visible { opacity: 1; transform: scale(1); }
    .page-card__drag-handle {
      position: absolute; bottom: 6px; left: 6px;
      color: #bbb; opacity: 0; transition: opacity .2s; cursor: grab;
    }
    .page-card:hover .page-card__drag-handle { opacity: 1; }
    .page-card__drag-handle svg { width: 14px; height: 14px; }

    .page-card__footer {
      padding: 8px 8px 10px;
      display: flex; align-items: center; gap: 4px;
    }
    .page-card__name { font-size: 11px; color: #888; font-weight: 500; flex: 1; text-align: center; }
    .page-card__actions { display: flex; gap: 3px; }
    .card-rot-btn {
      display: inline-flex; align-items: center; justify-content: center;
      width: 28px; height: 28px;
      border-radius: 6px; border: 1px solid #e0e0e0;
      background: #f8f9fa; cursor: pointer;
      transition: all .2s; padding: 0;
    }
    .card-rot-btn svg { width: 13px; height: 13px; fill: none; stroke: #555; stroke-width: 2.2; }
    .card-rot-btn:hover { background: var(--primary-color); border-color: var(--primary-color); }
    .card-rot-btn:hover svg { stroke: white; }

    /* ── Action Buttons ───────────────────────────────────────── */
    .action-buttons {
      display: flex;
      gap: 15px;
      margin-top: 30px;
      flex-wrap: wrap;
    }
    .action-button {
      flex: 1;
      padding: 15px;
      border: none;
      border-radius: 10px;
      font-size: 1rem;
      font-weight: 600;
      cursor: pointer;
      transition: all .3s ease;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
    }
    .action-button.primary {
      background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
      color: white;
    }
    .action-button.primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(102,126,234,.4); }
    .action-button.secondary { background: #f8f9fa; color: #333; border: 2px solid #ddd; }
    .action-button.secondary:hover:not(:disabled) { background: #e9ecef; transform: translateY(-2px); }
    .action-button.danger { background: var(--error-color); color: white; }
    .action-button.danger:hover:not(:disabled) { background: #c82333; transform: translateY(-2px); }
    .action-button:disabled { opacity: .5; cursor: not-allowed; }
    .action-button svg { width: 18px; height: 18px; flex-shrink: 0; }

    /* ── Progress ─────────────────────────────────────────────── */
    .progress-section {
      display: none;
      margin: 20px 0;
      padding: 20px;
      background: #f0f4f8;
      border-radius: 10px;
    }
    .progress-section.show { display: block; }
    .progress-status { text-align: center; font-weight: 600; margin-bottom: 10px; }
    .progress-bar { width: 100%; height: 10px; background: #ddd; border-radius: 5px; overflow: hidden; margin: 15px 0; }
    .progress-fill {
      height: 100%;
      background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
      width: 0%; transition: width .3s ease;
    }
    .progress-details { font-size: .9rem; color: #666; margin-top: 10px; text-align: center; }

    /* ── Result Info ──────────────────────────────────────────── */
    .result-info {
      margin-top: 20px; padding: 15px;
      background: #d4edda; border-radius: 10px;
      text-align: center; display: none;
    }
    .result-info.show { display: block; }

    /* ── Toast ────────────────────────────────────────────────── */
    .toast {
      position: fixed;
      bottom: 30px; right: 30px;
      min-width: 280px; max-width: 360px;
      padding: 14px 20px;
      background: #333; color: white;
      border-radius: 8px;
      transform: translateY(100px); opacity: 0;
      transition: all .3s ease;
      z-index: 1000;
      font-size: .9rem;
      display: flex; align-items: flex-start; gap: 10px;
    }
    .toast.show { transform: translateY(0); opacity: 1; }
    .toast.success { background: var(--success-color); }
    .toast.error   { background: var(--error-color); }
    .toast.warning { background: #856404; }
    .toast__msg { flex: 1; line-height: 1.4; }
    .toast__close { background: none; border: none; color: rgba(255,255,255,.7); cursor: pointer; padding: 0; font-size: 1.1rem; line-height: 1; margin-left: 4px; }
    .toast__close:hover { color: white; }

    /* ── Loading Overlay ──────────────────────────────────────── */
    .loading-overlay {
      display: none;
      position: fixed; inset: 0;
      background: rgba(255,255,255,.9);
      z-index: 999;
      flex-direction: column;
      align-items: center; justify-content: center;
      gap: 16px;
      backdrop-filter: blur(3px);
    }
    .loading-overlay.active { display: flex; }
    .loading-spinner {
      width: 50px; height: 50px;
      border: 4px solid #e0e0e0;
      border-top-color: var(--primary-color);
      border-radius: 50%;
      animation: spin .8s linear infinite;
    }
    .loading-title { font-size: 1.1rem; font-weight: 600; color: #333; }
    .loading-sub { font-size: .9rem; color: #777; }
    .loading-bar-wrap { width: 240px; height: 4px; background: #ddd; border-radius: 4px; overflow: hidden; }
    .loading-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary-color), var(--secondary-color)); width: 0%; transition: width .3s; }

    /* ── Features Grid ────────────────────────────────────────── */
    .features {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 20px;
      margin-top: 30px;
      padding: 30px;
      background: #f8f9fa;
      border-radius: 10px;
    }
    .feature { text-align: center; padding: 20px; }
    .feature-icon { margin-bottom: 12px; color: var(--primary-color); }
    .feature-icon svg { width: 32px; height: 32px; stroke: var(--primary-color); fill: none; stroke-width: 1.6; }
    .feature h4 { margin-bottom: 8px; color: #333; }
    .feature p { font-size: .85rem; color: #666; }

    /* ── SEO Content ──────────────────────────────────────────── */
    .seo-content { padding: 30px; border-top: 1px solid #eee; }
    .seo-content h2 { font-size: 1.3rem; color: var(--dark-color); margin: 20px 0 10px; }
    .seo-content h2:first-child { margin-top: 0; }
    .seo-content p { font-size: .95rem; color: #555; line-height: 1.7; margin-bottom: 15px; }

    /* ── FAQ Section ──────────────────────────────────────────── */
    .faq-section { padding: 30px; background: #f8f9fa; border-top: 1px solid #eee; }
    .faq-section h2 { text-align: center; margin-bottom: 24px; color: #333; font-size: 1.5rem; }
    .faq-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
    .faq-item {
      background: white; padding: 15px 20px;
      border-radius: 8px;
      box-shadow: 0 2px 5px rgba(0,0,0,.05);
    }
    .faq-item summary { font-weight: 600; color: #333; cursor: pointer; padding: 5px 0; }
    .faq-item summary:hover { color: var(--primary-color); }
    .faq-item p { margin-top: 10px; color: #555; line-height: 1.6; font-size: .95rem; }

    /* ── Related Tools ────────────────────────────────────────── */
    .related-tools { padding: 30px; text-align: center; border-top: 1px solid #eee; }
    .related-tools h2 { margin-bottom: 20px; color: #333; font-size: 1.4rem; }
    .related-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
    .related-link {
      display: inline-flex; align-items: center; gap: 8px;
      padding: 10px 20px;
      background: #e9ecef; color: #333;
      text-decoration: none; border-radius: 25px;
      font-weight: 500; font-size: .9rem;
      transition: all .2s;
    }
    .related-link:hover { background: var(--primary-color); color: white; transform: translateY(-2px); }

    /* ── AdSense placeholders ─────────────────────────────────── */
    .ad-wrap { max-width: 1200px; margin: 0 auto 16px; }
    .ad-label { display: block; text-align: center; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: rgba(255,255,255,.5); margin-bottom: 4px; }
    .ad-slot {
      background: rgba(255,255,255,.08);
      border: 1px dashed rgba(255,255,255,.2);
      border-radius: 10px;
      display: flex; align-items: center; justify-content: center;
      color: rgba(255,255,255,.35); font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
    }
    .ad-slot--top    { height: 90px; }
    .ad-slot--bottom { height: 90px; }
    .ad-slot--mid-inner {
      background: #f8f9fa;
      border: 2px dashed #ddd;
      border-radius: 10px;
      height: 100px;
      display: flex; align-items: center; justify-content: center;
      color: #bbb; font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
      margin-top: 30px;
    }

    /* ── Footer ───────────────────────────────────────────────── */
    footer {
      background: rgba(0,0,0,.3);
      color: rgba(255,255,255,.85);
      padding: 20px; text-align: center; font-size: .9rem;
    }
    footer a { color: white; text-decoration: none; }
    footer a:hover { text-decoration: underline; }

    /* ── Responsive ───────────────────────────────────────────── */
    @media (max-width: 768px) {
      body { padding-top: 55px; }
      .back-button { top: 8px; left: 10px; padding: 8px 16px; font-size: .85rem; }
      .two-column { grid-template-columns: 1fr; gap: 20px; }
      .main-content { padding: 20px; }
      .action-buttons { flex-direction: column; }
      .tool-switcher { gap: 6px; padding: 8px 12px; }
      .tool-switch-btn { font-size: .75rem; padding: 5px 10px; }
      .pages-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
      .header h1 { font-size: 1.5rem; }
    }
    @media (max-width: 480px) {
      .pages-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
    }
    @media (min-width: 1200px) {
      .pages-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
    }

    :focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; border-radius: 4px; }
    .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }