/* Base Variables */
:root {
  --color-bg: #ececec;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-border: #000000;
  --color-btn-hover: #333333;
  --font-main: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background-color: var(--color-bg);
  color: var(--color-text);
  overflow: hidden; /* Globally locks both X and Y viewport scrolling */
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Image Protection */
img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  pointer-events: none; /* Disables right-click and interaction on the image directly */
}

/* Header */
#app-header {
  padding: 1.5rem 2rem;
  background-color: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0; /* Prevents the header from getting magically crushed when vertical space runs out */
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.home-link {
  text-decoration: none;
  color: inherit; /* Prevents ugly blue default links */
  transition: opacity 0.2s ease;
}

.home-link:hover {
  opacity: 0.6; /* Simple tactile bounce indicating it's clickable */
}

#app-header h1 {
  font-size: 1.8rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.social-text-link {
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: opacity 0.2s ease;
}

#btn-gallery {
  font-size: 0.85rem; /* Force match to the social link size on desktop */
}

.social-text-link:hover {
  opacity: 0.4;
}

.bg-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 500;
}

.bg-settings input[type="color"] {
  height: 25px;
  width: 40px;
  padding: 0;
  border: 1px solid var(--color-border);
  cursor: pointer;
}

.bg-settings input:disabled,
.bg-settings label:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Buttons */
button {
  background-color: transparent;
  color: var(--color-text);
  border: 2px solid var(--color-border);
  padding: 0.5rem 1rem;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  margin-left: 1rem;
}

button:hover {
  background-color: var(--color-text);
  color: var(--color-bg);
}

/* Main Area */
#app-main {
  flex: 1;
  display: flex;
  position: relative;
  min-height: 0; /* CRITICAL FIX: Forces flexbox to respect the parent 100vh boundary, activating inner scrollbars natively! */
}

#editor-container {
  flex: 1;
  padding: 2rem; /* Reduced from massive 4rem to prevent pushing content completely off small laptop screens */
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center; /* Items centered horizontally */
  overflow-y: auto; /* Re-enabled to allow scrolling when text outgrows the window */
}

#editor-panel {
  width: 80%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05); /* subtle elevation */
}

#editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
  background-color: var(--color-text); /* Black */
  color: var(--color-surface); /* White */
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  margin-bottom: 2rem; /* Restored gap */
}

#editor-toolbar .bg-settings {
  color: var(--color-surface);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

#editor-toolbar .toolbar-select {
  background-color: transparent;
  color: var(--color-surface);
  border: 1px solid var(--color-surface);
  padding: 0.2rem 0.5rem;
  font-family: var(--font-main);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}

#editor-toolbar .toolbar-select option {
  background-color: var(--color-text); /* Black dropdown options to read properly against white text */
  color: var(--color-surface);
}

#editor-toolbar .toggle-btn {
  background-color: transparent;
  color: var(--color-surface);
  border: 1px solid var(--color-surface);
  padding: 0.2rem 0.5rem;
  font-family: var(--font-main);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  margin: 0;
  transition: all 0.2s ease;
  border-radius: 2px;
}

#editor-toolbar .toggle-btn.active {
  background-color: var(--color-surface);
  color: var(--color-text);
  font-weight: bold;
}

#editor-toolbar .toggle-btn:hover:not(.active) {
  background-color: rgba(255, 255, 255, 0.2);
}

#editor-toolbar .toolbar-btn {
  border: 2px solid var(--color-surface);
  color: var(--color-surface);
  background-color: transparent;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  margin: 0;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

#editor-toolbar .toolbar-btn:hover {
  background-color: var(--color-surface);
  color: var(--color-text);
}

#canvas-area {
  flex: 1;
  min-height: 60vh; /* Dramatically increased to pull focus to the canvas vertical length */
  background-color: var(--color-surface);
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px; /* spacing between letters */
  font-size: 16px; /* Base engine reference used for em scaling */
}

/* Typing Cursor */
.typing-cursor {
  width: 3px;
  height: 5em;
  background-color: var(--color-text);
  animation: blink 1s step-end infinite;
  display: inline-block;
  margin-left: 5px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Gallery Modal */
#gallery-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.95);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  z-index: 100;
  overflow-y: auto;
}

#gallery-modal.hidden {
  display: none;
}

.modal-content {
  width: 90%;
  max-width: 1200px;
  margin-top: 2rem;
  padding: 2rem;
  background-color: var(--color-bg);
  border: 2px solid var(--color-border);
}

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

.download-pack-btn {
  background-color: var(--color-text);
  color: var(--color-bg);
  padding: 0.4rem 1rem;
  text-decoration: none;
  font-weight: bold;
  font-size: 0.8rem;
  text-transform: uppercase;
  border-radius: 2px;
  border: 2px solid var(--color-text);
  transition: all 0.2s ease;
}

.download-pack-btn:hover {
  background-color: transparent;
  color: var(--color-text);
}

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 1rem;
}

/* Typed Element Styles */
.typed-letter {
  height: 5em; /* dynamically adjusts to the canvas font-size scale */
  min-width: 2em; /* Prevents structural 0px pop-in while the image decodes */
  object-fit: contain;
  pointer-events: auto; /* Re-enable pointer logic so we can click them */
  cursor: pointer;
  transition: transform 0.15s ease-out, height 0.1s ease-out;
  color: transparent; /* Makes the default alt-text invisible while the image fetches */
}

.typed-letter:hover {
  transform: scale(1.08); /* Gives the user a hint it can be clicked */
}

.typed-letter:active {
  transform: scale(0.95);
}

.typed-space {
  width: 2.5em; /* exactly half of 5em height (40px relative to 80px) */
  height: 5em;
  display: inline-block;
  transition: width 0.1s ease-out, height 0.1s ease-out;
}

.typed-linebreak {
  width: 100%;
  height: 0;
  margin: 0;
}

/* Footer Section */
#app-footer {
  width: 100%;
  padding-top: 1.5rem; /* Shrunk padding to tighten layout */
  padding-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.35rem; /* Much tighter textual stacking */
  background-color: transparent;
  flex-shrink: 0;
}

#footer-logo {
  height: 35px; /* Shrunk down nicely from 55px */
  object-fit: contain;
  mix-blend-mode: multiply; /* Instantly knocks out any white background if the PNG wasn't exported with transparency */
}

.footer-credit {
  margin: 0;
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--color-text);
  opacity: 0.4;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.5;
}

/* =========================================
   MOBILE RESPONSIVENESS (PHONES / TABLETS)
   ========================================= */
@media (max-width: 768px) {
  /* Header Adjustments */
  #app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    gap: 1rem;
  }
  
  #app-header h1 {
    font-size: 1.3rem; /* Scaled down to survive single-line constraints, but explicitly requested to be larger */
  }

  /* Hide UI dividers to save space, but retain social links */
  .desktop-only {
    display: none !important;
  }

  .controls {
    width: 100%;
    justify-content: flex-start; /* Flow links naturally from the left */
    gap: 1rem; /* Tighter grouping for mobile */
    align-items: center;
    flex-wrap: wrap;
  }

  .social-text-link, #btn-gallery {
    font-size: 0.65rem !important; /* Unify exact font size across disparate elements on mobile */
    letter-spacing: 0.05em;
  }

  #btn-gallery {
    margin-left: auto; /* Lock the Gallery button against the right edge */
    padding: 0.4rem 0.8rem; /* Compress the button's physical boundaries to match its new reduced internal font */
  }

  /* Editor Panel Sizing */
  #editor-container {
    padding: 1rem 0.5rem; /* Recapture extreme vertical and horizontal screen real estate */
  }

  #editor-panel {
    width: 100%; /* Push canvas edges entirely to the physical glass boundaries */
  }

  /* Toolbar Grid Overhaul */
  #editor-toolbar {
    padding: 1rem;
    gap: 1.5rem;
    flex-direction: column;
    align-items: stretch; /* Stretch children full width */
  }

  #editor-toolbar .bg-settings {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  
  /* Create an inner grid for settings so labels align tightly with controls */
  #editor-toolbar .bg-settings > label {
    margin-bottom: -5px;
    font-size: 0.8rem;
  }
  
  #size-group, #align-group {
    justify-content: flex-start;
    width: 100%;
  }

  /* Expand Action Buttons */
  #editor-toolbar > div:last-child {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }

  #editor-toolbar .toolbar-btn {
    width: 100%;
    text-align: center;
    padding: 0.75rem; /* Fat fingers require larger tap targets */
  }

  /* Footer Rescaling */
  #app-footer {
    padding-top: 1rem;
    padding-bottom: 2rem;
  }
}
