:root {
    --theme-white-primary: #e9d8c4;
    --theme-white-secondary: #d4c0a7;
    --theme-white-canvas: #ffffff;
    --theme-white-accent: #724707;
    --theme-white-pdf-bg: #ffffff;
    --theme-white-pdf-text: #000000;
    --theme-white-border-start: #f5e3b1;
    --theme-white-border-end: #9f9071;
    --theme-white-shadow: rgba(45, 43, 31, 0.5);
    --theme-white-overlay: rgba(222, 208, 177, 0.2);
    --theme-white-hover: #936d0d;
  
    --theme-red-primary: #530F19;
    --theme-red-secondary: #340a0a;
    --theme-red-canvas: #2d0c12;
    --theme-red-accent: #EFD58C;
    --theme-red-pdf-bg: #d2c4a2;
    --theme-red-pdf-text: #340a0a;
    --theme-red-border-start: #EFD58C;
    --theme-red-border-end: #ab925d;
    --theme-red-shadow: rgba(0, 0, 0, 0.3);
    --theme-red-overlay: rgba(91, 28, 34, 0.15);
    --theme-red-hover: #ffe2c5;
  
    --theme-dark-primary: #010522;
    --theme-dark-secondary: #010319;
    --theme-dark-canvas: #010319;
    --theme-dark-accent: #ab925d;
    --theme-dark-pdf-bg: #010311;
    --theme-dark-pdf-text: #decc91;
    --theme-dark-border-start: #9b8d6a;
    --theme-dark-border-end: #695e45;
    --theme-dark-shadow: rgba(0, 0, 0, 0.3);
    --theme-dark-overlay: rgba(91, 28, 34, 0.15);
    --theme-dark-hover: #c4aa6e;
  
    --shadow-accent: rgba(212, 175, 55, 0.2);
    --overlay-error: rgba(139, 0, 0, 0.05);
  
    --pecha-width: 97vw;
    --pecha-height: calc(var(--pecha-width) * 70/297);
    --min-viewer-height: 200px;
    --max-viewer-height: calc(100vh - 175px);
    --theme-transition: 0.32s ease;

    /* Default theme (red) */
    --surface-color: var(--theme-red-primary);
    --surface-secondary: var(--theme-red-secondary);
    --font-color: var(--theme-red-accent);
    --canvas-color: var(--theme-red-canvas);
    --bg-opacity: var(--theme-red-overlay);
    --shadow-strength: var(--theme-red-shadow);
    --border-gradient-start: var(--theme-red-border-start);
    --border-gradient-end: var(--theme-red-border-end);
    --color-hover: var(--theme-red-hover);
    --theme-applied: red;
  }
  
  [data-theme="white"] {
    --surface-color: var(--theme-white-primary);
    --surface-secondary: var(--theme-white-secondary);
    --font-color: var(--theme-white-accent);
    --canvas-color: var(--theme-white-canvas);
    --bg-opacity: var(--theme-white-overlay);
    --shadow-strength: var(--theme-white-shadow);
    --border-gradient-start: var(--theme-white-border-start);
    --border-gradient-end: var(--theme-white-border-end);
    --color-hover: var(--theme-white-hover);
    --theme-applied: white;
  }
  
  [data-theme="red"] {
    --surface-color: var(--theme-red-primary);
    --surface-secondary: var(--theme-red-secondary);
    --font-color: var(--theme-red-accent);
    --canvas-color: var(--theme-red-canvas);
    --bg-opacity: var(--theme-red-overlay);
    --shadow-strength: var(--theme-red-shadow);
    --border-gradient-start: var(--theme-red-border-start);
    --border-gradient-end: var(--theme-red-border-end);
    --color-hover: var(--theme-red-hover);
    --theme-applied: red;
  }
  
  [data-theme="dark"] {
    --surface-color: var(--theme-dark-primary);
    --surface-secondary: var(--theme-dark-secondary);
    --font-color: var(--theme-dark-accent);
    --canvas-color: var(--theme-dark-canvas);
    --bg-opacity: var(--theme-dark-overlay);
    --shadow-strength: var(--theme-dark-shadow);
    --border-gradient-start: var(--theme-dark-border-start);
    --border-gradient-end: var(--theme-dark-border-end);
    --color-hover: var(--theme-dark-hover);
    --theme-applied: dark;
  }
  
  body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Add padding to account for the controls at the bottom */
    padding-bottom: 7rem; 
    box-sizing: border-box;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--surface-color);
    color: var(--font-color);
    background: linear-gradient(180deg, var(--surface-color), var(--surface-secondary));
    position: relative;
    overflow: hidden;
    transition: color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
  }
  
  .viewer-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    /* Ensure it doesn't overflow */
    max-height: 100%; 
  }
  
  .controls:not(.left) {
    position: fixed;
    bottom: 2rem;
    left: 75%;
    transform: translateX(-50%);
    z-index: 10;
  }
  
  .controls.left {
    position: fixed;
    bottom: 1.75rem; /* Adjusted for vertical alignment with smaller logo */
    left: 25%;
    transform: translateX(-50%);
    z-index: 10;
  }

  .controls .select-label {
    display: none;
  }

  .control-panel {
    background: var(--bg-opacity);
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 15px var(--shadow-strength);
    display: flex;
    gap: 2rem;
    align-items: center;
    min-height: 36px; /* Ensures vertical alignment with navigation panel */
    transition: background-color var(--theme-transition), box-shadow var(--theme-transition);
  }
  
  .control-panel:not(.logo-panel)::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    padding: 2px;
    background: linear-gradient(to bottom, var(--border-gradient-start), var(--border-gradient-end));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
  }
  
  .logo-panel {
    background: none;
    backdrop-filter: none;
    box-shadow: none;
    padding: 0.6rem 1.5rem 0.6rem 0;
    gap: 1rem;
  }
  
  .logo-icon {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 15px var(--shadow-strength));
  }
  
  .logo {
    font-family: 'Playfair Display', serif;
    color: var(--font-color);
    text-decoration: none;
    line-height: 1.2;
    display: flex;
    align-items: center;
    transition: color var(--theme-transition);
  }
  
  .logo-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
  
  .logo-main {
    font-size: 2rem;
    text-shadow: 0 2px 15px var(--shadow-strength);
  }
  
  .logo-sub {
    font-size: 0.77rem;
    letter-spacing: 0.925em;
    margin-top: -0.2rem;
    text-shadow: 0 2px 15px var(--shadow-strength);
  }
  
  .viewer-wrapper {
    position: relative;
    padding-top: 2rem;
  }
  
  .viewer-container {
    width: var(--pecha-width);
    height: var(--pecha-height);
    min-height: var(--min-viewer-height);
    max-height: var(--max-viewer-height);
    position: relative;
    border-radius: 8px;
    transition: height 0.3s ease, color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
    outline: none; /* Remove focus outline for cleaner appearance */
  }
  
  #canvas {
    display: block; /* Fixes the small gap below the canvas */
    max-width: var(--pecha-width, 97vw);
    max-height: var(--max-viewer-height);
    min-height: var(--min-viewer-height);
    border-radius: 8px;
    transition: height 0.3s ease;
  }

  .viewer-container::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    padding: 2px;
    background: linear-gradient(to bottom, var(--border-gradient-start), var(--border-gradient-end));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
  }
  
  canvas {
    width: 100%;
    height: 100%;
    background: var(--canvas-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-strength);
    transition: color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
  }
  
  /* When a PDF is loaded, allow the container and canvas to resize dynamically */
  body.pdf-loaded .viewer-container {
    height: auto;
  }

  body.pdf-loaded .viewer-container canvas {
    height: auto;
  }

  .drop-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-opacity);
    border: 2px dashed var(--font-color);
    margin: 1rem;
    border-radius: 8px;
    pointer-events: auto;
    transition: all 0.3s ease;
    opacity: 1;
    visibility: visible;
    cursor: pointer;
  }
  
  .drop-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    line-height: 1.6;
    pointer-events: none;
  }
  
  .drop-text p {
    margin: 0;
    font-size: 1.2rem;
    color: var(--font-color);
    transition: color 0.3s ease;
  }
  
  .filename-display {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-color);
    padding: 0.5rem 25px;
    border-radius: 8px 8px 0 0;
    color: var(--font-color);
    font-size: 1rem;
    box-shadow: 0 -2px 10px var(--shadow-strength);
    opacity: 0;
    transition: opacity 0.3s ease;
    text-align: center;
    white-space: nowrap;
  }
  
  .navigation {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    gap: 1rem;
    align-items: center;
  }
  
  .navigation .control-panel {
    justify-content: center;
  }

  .theme-panel {
    padding: 1rem;
  }
  
  .navigation button {
    background: transparent;
    border: 1px solid var(--font-color);
    color: var(--font-color);
    padding: 0.4rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    height: 32px;
    transition: color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
  }

  .navigation button:hover {
    border-color: var(--color-hover);
  }

  .navigation .mode-button.active {
    background: var(--font-color);
    color: var(--surface-color);
    border-color: var(--font-color);
  }


  
  #pageInfo {
    color: var(--font-color);
    font-size: 0.9rem;
    width: 5rem;
    text-align: center;
    display: inline-block;
  }
  
  .select-wrapper {
    position: relative;
    display: inline-block;
    text-align: center;
  }
  
  .select-label {
    font-size: 0.8rem;
    color: var(--font-color);
    margin-bottom: 0.6rem;
    opacity: 0.8;
  }
  
  .select-wrapper select {
    appearance: none;
    background: transparent;
    border: 1px solid var(--font-color);
    border-radius: 4px;
    padding: 0.4rem 1.2rem;
    font-size: 0.9rem;
    color: var(--font-color);
    cursor: pointer;
    height: 32px;
    transition: color var(--theme-transition), border-color var(--theme-transition);
  }
  
  .select-wrapper::after {
    content: '';
    position: absolute;
    right: 8px;
    bottom: 13px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--font-color);
    pointer-events: none;
  }

  .select-wrapper select:hover {
    border-color: var(--color-hover);
    color: var(--color-hover);
  }

  .select-wrapper:hover::after {
    border-top-color: var(--color-hover);
  }
  .color-swatches {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
  }

  .mode-toggle-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
  }

  .swatch-separator {
    width: 1px;
    height: 24px;
    background: var(--font-color);
    opacity: 0.3;
  }

  .color-swatch {
    border-radius: 4px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    position: relative;
    border: none;
    transition: color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
  }

  .color-swatch:hover {
    transform: translateY(-1px);
  }
  
  .color-swatch::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 4px;
    padding: 1px;
    background: linear-gradient(to bottom, var(--border-gradient-start), var(--border-gradient-end));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
  }
  
  .color-swatch::after {
    content: 'A';
    font-size: 1.2rem;
    font-weight: 300;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  .color-swatch[data-theme="white"] {
    background-color: var(--theme-white-pdf-bg);
  }
  .color-swatch[data-theme="white"]::after {
    color: var(--theme-white-pdf-text);
  }

  .color-swatch[data-theme="red"] {
    background-color: var(--theme-red-pdf-bg);
  }
  .color-swatch[data-theme="red"]::after {
    color: var(--theme-red-pdf-text);
  }

  .color-swatch[data-theme="dark"] {
    background-color: var(--theme-dark-pdf-bg);
  }
  .color-swatch[data-theme="dark"]::after {
    color: var(--theme-dark-pdf-text);
  }

  .color-swatch.active {
    transform: scale(1.1);
  }
  
  .color-swatch.active::before {
    padding: 2px;
  }

  .mode-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
  }

  .mode-button {
    background: transparent;
    border: 1px solid var(--font-color);
    color: var(--font-color);
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    height: 32px;
    min-width: 60px;
    transition: all var(--theme-transition);
    position: relative;
  }

  .mode-button:hover {
    border-color: var(--color-hover);
    color: var(--color-hover);
    transform: translateY(-1px);
  }

  .mode-button.active {
    background: var(--font-color);
    color: var(--surface-color);
    font-weight: 500;
    transform: scale(1.05);
  }

  .mode-button.active:hover {
    background: var(--color-hover);
    border-color: var(--color-hover);
    color: var(--surface-color);
  }

  .mode-toggle {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    justify-content: center;
    padding: 4px;
  }

  .mode-toggle::after {
    content: none !important;
  }

  .mode-toggle .rectangle {
    width: 14px;
    height: 5px;
    border: 1px solid var(--font-color);
    border-radius: 1px;
    transition: all var(--theme-transition);
  }

  /* Single mode: only bottom rectangle filled */
  .mode-toggle[data-mode="single"] .rectangle:last-child {
    background: var(--font-color);
  }

  /* Double mode: both rectangles filled */
  .mode-toggle[data-mode="double"] .rectangle {
    background: var(--font-color);
  }

  .icon-button {
    background: transparent;
    border: 1px solid var(--font-color);
    color: var(--font-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0.9rem;
    transition: color var(--theme-transition), background-color var(--theme-transition), border-color var(--theme-transition), box-shadow var(--theme-transition), background var(--theme-transition);
  }

  .icon-button:hover {
    color: var(--color-hover);
    border-color: var(--color-hover);
    transform: translateY(-1px);
  }
  
  .icon-button svg {
    width: 20px;
    height: 20px;
  }
  
  .end-of-file {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--font-color);
    font-size: 1.2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .error-message {
    position: fixed;
    top: 3rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(139,0,0,0.7);
    color: #fff;
    padding: 1rem;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 9999;
  }
  
  .error-message.visible {
    opacity: 1;
    pointer-events: auto;
  }
  
  .version-info {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    font-size: 0.8rem;
    color: var(--font-color);
    opacity: 0.6;
    user-select: none;
  }

  .contact-info {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    font-size: 0.8rem;
    color: var(--font-color);
    opacity: 0.6;
    user-select: none;
    pointer-events: none;
  }
  
  *:focus {
    outline: none !important;
  }

.version-info span {
  cursor: pointer;
  text-decoration: none;
}

/* Modal styles */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1000; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

.modal-content {
  background-color: #fefefe;
  color: #333;
  margin: 15% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: 80%; /* Could be more or less, depending on screen size */
  max-width: 500px;
  border-radius: 5px;
  position: relative;
}

.modal-content h2 {
    margin-top: 0;
}

.modal-content ul {
    list-style-type: disc;
    padding-left: 20px;
}

.close-button {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close-button:hover,
.close-button:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

#fullscreen-container {
  display: none;
}