/* css/live-demo-style.css */

/* Live Demo App General Styles */
.live-demo-outer-container.container {
  padding-left: 10px;
  padding-right: 10px;
}
@media (max-width: 360px) {
  .live-demo-outer-container.container {
    padding-left: 5px;
    padding-right: 5px;
  }
}

.live-demo-app {
  background-color: #f0f0f0;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.07);
  display: flex;
  flex-direction: column; /* Default for mobile */
  gap: 10px;
  max-width: 1000px;
  margin: 0 auto;
  overflow: hidden;
  box-sizing: border-box;
}

.editor-panel {
  display: flex;
  flex-direction: column; /* Default for mobile & tablet, overridden by grid for desktop */
  gap: 10px;
  background-color: #ffffff;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #dcdcdc;
  min-width: 0;
  box-sizing: border-box;
}

/* Tools Panel */
.tools-panel {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background-color: #f7f7f7;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  flex-wrap: wrap;
  box-sizing: border-box;
}

.tool-button {
  background-color: #fff;
  border: 1px solid #ccc;
  padding: 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease,
    border-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  touch-action: manipulation;
  box-sizing: border-box;
}
.tool-button svg {
  width: 18px;
  height: 18px;
  stroke: #555;
  pointer-events: none;
}
.tool-button:hover {
  background-color: #e9e9e9;
  border-color: #bbb;
}
.tool-button.active {
  /* This class might be mainly for visual cue if auto-tool is primary */
  background-color: var(--primary-color, #4caf50);
  border-color: var(--primary-color, #4caf50);
  box-shadow: 0 0 5px var(--primary-color, #4caf50);
}
.tool-button.active svg {
  stroke: #fff;
}
.tool-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background-color: #e0e0e0;
}

/* Canvas Area */
.canvas-wrapper-outer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  box-sizing: border-box;
}
.canvas-container {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  background-color: #fff;
  border: 1px solid #999;
  overflow: hidden;
  margin: 0 auto;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}
#pixel-canvas {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(16, 1fr);
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  background-color: #fff;
  box-sizing: border-box;
}
#pixel-canvas div.pixel {
  background-color: transparent;
  border-right: 1px solid #d0d0d0;
  border-bottom: 1px solid #d0d0d0;
  box-sizing: border-box;
}
#pixel-canvas div.pixel:nth-child(16n) {
  border-right: none;
}
#pixel-canvas div.pixel:nth-last-child(-n + 16) {
  border-bottom: none;
}
#pixel-canvas div.pixel.filled {
  background-color: #000000;
}

.current-char-display-editor {
  text-align: center;
  font-size: 0.85rem;
  color: #333;
  background-color: #e9e9e9;
  padding: 3px 8px;
  border-radius: 4px;
  box-sizing: border-box;
}

/* Character Selector Panel */
.char-selector-panel {
  display: flex;
  gap: 6px;
  background-color: #f7f7f7;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  align-items: stretch;
  min-width: 0;
  box-sizing: border-box;
}
.char-selector-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.arrow-button {
  background-color: #fff;
  border: 1px solid #ccc;
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  color: #555;
  touch-action: manipulation;
  box-sizing: border-box;
}
.arrow-button:hover {
  background-color: #e9e9e9;
  border-color: #bbb;
}
.arrow-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  color: #aaa;
}

.char-slots-wrapper {
  flex-grow: 1;
  overflow: hidden;
  border: 1px solid #999;
  background-color: #fff;
  position: relative;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
  min-width: 0;
  box-sizing: border-box;
}
.char-slots-sliding-container {
  display: flex;
  flex-wrap: nowrap;
  height: 100%;
  transition: transform 0.2s ease-in-out;
  box-sizing: border-box;
}
.char-slot {
  width: 32px;
  height: 42px;
  border-right: 1px solid #999;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  flex-shrink: 0;
  background-color: #fff;
  touch-action: manipulation;
}
.char-slot .slot-char-display {
  height: 10px;
  background-color: #585858;
  color: white;
  font-size: 8px;
  line-height: 10px;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  border-bottom: 1px solid #999;
  box-sizing: border-box;
}
.char-slot .slot-glyph-preview {
  height: 32px;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  box-sizing: border-box;
}
.char-slot .slot-glyph-preview svg {
  width: 100%;
  height: 100%;
}
.char-slot.selected {
  outline: 1px solid var(--primary-color, #4caf50);
  outline-offset: -1px;
  position: relative;
  z-index: 10;
}
.char-slot.selected::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--primary-color, #4caf50);
  opacity: 0.25;
  pointer-events: none;
}

/* Preview Panel */
.preview-panel {
  background-color: #ffffff;
  padding: 10px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid #dcdcdc;
  min-width: 0;
  box-sizing: border-box;
}
.preview-status {
  font-size: 0.9em;
  color: #777;
  text-align: center;
  padding: 5px 0;
}
#preview-text-input {
  width: 100%;
  min-height: 70px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 0.95rem;
  line-height: 1.4;
  resize: vertical;
  flex-shrink: 0;
}
#preview-text-input:focus {
  border-color: var(--primary-color, #4caf50);
  box-shadow: 0 0 5px var(--primary-color-transparent, rgba(76, 175, 80, 0.5));
  outline: none;
}

.font-live-preview {
  width: 100%;
  min-height: 90px;
  padding: 8px;
  border: 1px dashed #aaa;
  border-radius: 4px;
  background-color: #fdfdfd;
  font-size: 18px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start; /* Align lines to the start if container is taller */
  gap: 0.2em 0.05em; /* row-gap column-gap */
  overflow-y: auto;
  flex-grow: 1;
  box-sizing: border-box;
}
.preview-char-container {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  height: 1em;
  line-height: 1;
  box-sizing: border-box;
}
.preview-char-container svg,
.preview-char-container span {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: middle;
}
.preview-char-container span {
  font-family: monospace;
  color: #777;
}

/* --- Breakpoints --- */

/* Mobile (default, up to 579px) */
@media (max-width: 579px) {
  .live-demo-app {
    flex-direction: column;
  }
  /* Ensure panels take full width if they were sharing */
  .editor-panel,
  .preview-panel {
    flex-basis: auto; /* Reset flex-basis */
    width: 100%; /* Take full width */
  }
}

/* Tablet Layout (580px to 833px) */
@media (min-width: 580px) and (max-width: 833px) {
  .live-demo-app {
    flex-direction: row;
    align-items: flex-start;
    gap: 15px;
  }
  .editor-panel {
    flex: 1 1 50%; /* Allow editor to take roughly half */
    max-width: 450px; /* But not too wide */
    min-width: 280px;
    /* display: flex; /* Keep flex for internal stacking */
    /* flex-direction: column; /* Keep stacking for tools, canvas, char-selector */
  }
  .preview-panel {
    flex: 1 1 50%;
    align-self: stretch;
  }
  .tools-panel {
    /* Tools still above canvas on tablet */
    order: -1;
    flex-direction: row;
    justify-content: flex-start;
  }
  .canvas-container {
    max-width: 100%; /* Canvas can fill editor width */
  }
  #preview-text-input {
    min-height: 100px;
  }
  .font-live-preview {
    min-height: 150px;
    font-size: 20px;
  }
}

/* Desktop Layout (834px and up) */
@media (min-width: 834px) {
  .live-demo-app {
    flex-direction: row; /* editor | preview */
    align-items: flex-start;
    gap: 20px;
  }
  .editor-panel {
    width: 420px; /* Fixed width for editor */
    flex-shrink: 0;
    display: grid;
    grid-template-columns: min-content 1fr; /* Tools | Canvas/CharSelect */
    /* grid-template-rows: auto minmax(0, 1fr); /* Canvas | CharSelect */
    grid-template-rows: auto auto; /* Adjusted for new areas */
    grid-template-areas:
      "tools  canvas"
      "charselect charselect"; /* Charselect spans both columns under canvas */
    gap: 15px;
    align-items: start;
    padding: 15px;
  }

  .tools-panel {
    grid-area: tools;
    flex-direction: column;
    align-items: center;
    align-self: start; /* Align to top of its area */
  }

  .canvas-wrapper-outer {
    grid-area: canvas;
    width: 100%; /* Span its allocated area */
    min-width: 0; /* Allow shrinking within the grid cell */
  }
  .canvas-container {
    width: 100%;
    max-width: 320px; /* Max drawing canvas size */
    margin: 0 auto; /* Center if grid cell is wider */
  }

  .char-selector-panel {
    grid-area: charselect;
    /* This will now span 2 columns based on grid-template-areas */
    /* width: 100%; /* Not needed, grid-area handles spanning */
    /* display: flex; /* Already flex */
    min-width: 0; /* Allow shrinking */
    /* overflow: hidden; /* Already set */
  }

  .preview-panel {
    flex: 1 1 auto; /* Take remaining space */
    align-self: stretch; /* Match height */
    display: flex;
    flex-direction: column;
  }
  .font-live-preview {
    flex-grow: 1;
  }
  #preview-text-input {
    min-height: 120px;
  }
  /* .font-live-preview { min-height: 200px; font-size: 22px; } /* Re-evaluate font-size if too big */
}

/* Further adjustments for very narrow screens (e.g., 320px wide) */
@media (max-width: 360px) {
  .live-demo-outer-container.container {
    padding-left: 5px;
    padding-right: 5px;
  }
  .live-demo-app {
    padding: 8px;
    gap: 8px;
  }
  .editor-panel,
  .preview-panel {
    padding: 8px;
    gap: 8px;
  }
  .tools-panel,
  .char-selector-panel {
    padding: 5px;
    gap: 4px;
  }
  .tool-button {
    width: 36px;
    height: 36px;
    padding: 6px;
  }
  .tool-button svg {
    width: 18px;
    height: 18px;
  }
  .arrow-button {
    width: 28px;
    font-size: 0.9rem;
  }
  .char-slot {
    width: 28px;
    height: 38px;
  }
  .char-slot .slot-char-display {
    height: 8px;
    font-size: 7px;
    line-height: 8px;
  }
  .char-slot .slot-glyph-preview {
    height: 30px;
  }
  .font-live-preview {
    font-size: 16px;
    padding: 6px;
    min-height: 80px;
  }
  #preview-text-input {
    font-size: 0.9rem;
    padding: 6px;
    min-height: 60px;
  }
  .current-char-display-editor {
    font-size: 0.8rem;
    padding: 2px 6px;
  }
}
