.sidebar,
.top-nav {
  background: #252526;
}
:root {
  --frame-cell-padding: 8px; /* Small padding around thumbnail */
  --min-frame-size: 64px; /* Minimum effective sprite size for UI cells */
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1e1e1e;
  color: #e0e0e0;
  height: 100vh;
  overflow: hidden;
}
.app-container {
  display: flex;
  flex-direction: row;
  height: 100vh;
}
.top-nav {
  padding: 8px 16px;
  border-bottom: 1px solid #3c3c3c;
  display: flex;
  gap: 20px;
}
.top-nav a,
.top-nav span {
  color: #ddd;
  text-decoration: none;
  font-weight: 700;
}
.top-nav .active {
  color: #00ffea;
}
.sidebar {
  width: 330px;
  padding: 16px;
  border-right: 1px solid #3c3c3c;
  overflow-y: auto;
  flex-shrink: 0;
}
.main-area {
  flex: 1;
  position: relative;
  background: #111;
  overflow: auto;
  padding: 20px;
}
.accordion,
.primary-btn,
.secondary-btn,
.third-btn {
  padding: 10px;
  width: 100%;
  cursor: pointer;
}
h2,
h3 {
  margin-bottom: 16px;
  color: #fff;
}
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #ccc;
}
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-row input {
  width: 80px;
  padding: 6px 8px;
  background: #3c3c3c;
  border: 1px solid #555;
  color: #fff;
  border-radius: 4px;
}
.primary-btn,
.secondary-btn,
.third-btn {
  margin: 8px 0;
  border: none;
  border-radius: 4px;
  font-weight: 700;
}
.primary-btn {
  background: #007acc;
  color: #fff;
}
.secondary-btn {
  background: #444;
  color: #ddd;
}
.third-btn {
  background: #28a745;
  color: #ddd;
}
#set-state-timing-btn:hover,
.primary-btn:hover,
.small-btn:hover {
  background: #005f99;
}
.editor-panel:not(.hidden),
.setup-panel {
  display: block;
}
.hidden,
.setup-panel:not(.active) {
  display: none !important;
}
.editor-panel {
  display: none;
}
#status-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  pointer-events: none;
  visibility: hidden; /* NEW: Use visibility instead of display */
  opacity: 0; /* NEW: Fade out */
  transition: opacity 0.3s ease;
  z-index: 1000; /* Ensure it's above everything */
}
#status-overlay:not(.hidden) {
  visibility: visible;
  opacity: 1;
}
.accordion {
  background: #333;
  color: #ddd;
  border: none;
  text-align: left;
  outline: 0;
  font-size: 14px;
  transition: 0.4s;
  margin-bottom: 4px;
  border-radius: 4px;
}
.accordion.active,
.accordion:hover {
  background: #444;
}
.panel {
  padding: 0 18px;
  background: #252526;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
  padding: 12px 0;
}
#preview-container,
.editor-workspace,
.preview-controls,
.table-controls {
  display: flex;
  display: flex;
}
.tile-thumb {
  width: 48px;
  height: 48px;
  background: #1e1e1e;
  border: 2px solid transparent;
  cursor: pointer;
  border-radius: 4px;
  object-fit: none;
}
.tile-thumb.selected {
  border: 2px solid #00ffea;
  box-shadow: 0 0 8px #00ffea;
}
.palette-panel {
  margin: 16px 0;
  background: #2d2d2d;
  border-radius: 4px;
  padding: 12px;
}
.palette-panel h3 {
  margin-bottom: 12px;
}
#animation-table td,
#animation-table th {
  border: 1px solid #444;
  padding: 8px;
  text-align: center;
}
#animation-table th {
  background: #333;
  color: #fff;
  min-width: calc(
    max(var(--frame-width), var(--min-frame-size)) + var(--frame-cell-padding) *
      2
  );
  height: auto; /* Fit text height */
  text-align: center;
  padding: 8px;
}
.animation-state-cell:focus {
  outline: #00ffea solid 2px;
}
.animation-frame-cell {
  min-width: calc(
    max(var(--frame-width), var(--min-frame-size)) + var(--frame-cell-padding) *
      2
  );
  min-height: calc(
    max(var(--frame-height), var(--min-frame-size)) +
      var(--frame-cell-padding) * 2
  );
  width: calc(
    max(var(--frame-width), var(--min-frame-size)) + var(--frame-cell-padding) *
      2
  );
  height: calc(
    max(var(--frame-height), var(--min-frame-size)) +
      var(--frame-cell-padding) * 2
  );
  background: #1e1e1e;
  border: 2px solid transparent;
  cursor: pointer;
  box-sizing: border-box;
  text-align: center;
  vertical-align: middle; /* Centers vertically in table cell */
  overflow: hidden;
}

.animation-frame-cell canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  display: inline-block; /* Centers horizontally */
  vertical-align: middle; /* Centers vertically */
}

.animation-frame-cell.filled {
  border-color: #00ffea;
}
#frame-context-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  background: #444;
  border: none;
  color: #fff;
  cursor: pointer;
  text-align: left;
}
#frame-context-menu button:hover {
  background: #555;
}
.delete-frame-btn,
.delete-state-btn {
  background: #f44;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
}
.delete-frame-btn:hover,
.delete-state-btn:hover {
  background: #c00;
}
#preview-container {
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 200px;
  text-align: center;
  background: #222; /* Slightly different shade for distinction */
  border-radius: 8px;
  border: 1px solid #555;
}
#preview-canvas {
  image-rendering: pixelated;
  border: 2px solid #444;
  background: #000;
}
#preview-state-select {
  padding: 6px 12px;
  background: #3c3c3c;
  border: 1px solid #555;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  width: 128px;
  margin: 8px 0;
}
#preview-play-btn,
.small-btn {
  border: none;
  color: #fff;
  cursor: pointer;
}
#preview-speed-label {
  font-size: 1.1rem;
  color: #ccc;
}
.preview-controls {
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 128px;
}
#preview-speed-slider {
  width: 100%;
}
#preview-play-btn {
  padding: 8px 16px;
  background: #28a745;
  border-radius: 4px;
  width: 100%;
}
#preview-play-btn.playing {
  background: #dc3545;
}
.table-controls {
  margin: 12px 0 16px;
  gap: 12px;
  justify-content: flex-start;
}
.small-btn {
  padding: 6px 12px;
  font-size: 0.9rem;
  min-width: 100px;
  background: #007acc;
  border-radius: 4px;
}
.preview-controls button {
  min-width: 100px;
  padding: 8px 16px;
}
#set-state-timing-btn {
  background: #007acc;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.editor-workspace {
  flex-direction: row;
  gap: 15px;
  width: 100%;
  align-items: flex-start;
}
#animation-container {
  overflow-x: auto;
  flex: 4;
  min-width: 600px;
}
#advanced-mode-toggle {
  accent-color: #00ffea;
  cursor: pointer;
}
#animation-container,
#preview-container {
  padding-top: 0;
  margin-top: 0;
}
#animation-container > *,
#preview-container > * {
  margin-top: 0;
}
#animation-container h3:first-child,
#preview-container h3:first-child {
  margin-top: 0;
  padding-top: 0;
  font-size: 1.3rem;
}
#animation-table {
  table-layout: fixed;
  width: auto;
  border-collapse: collapse;
  background: #222;
}
.animation-state-cell {
  min-width: 128px;
  width: 128px;
  max-width: 300px;
  min-height: 40px; /* NEW: Minimum height for state name text */
  background: #2d2d2d;
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 8px;
}
.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  width: fit-content;
  max-width: 100%;
  margin: 16px 0 0;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1e1e1e;
}

.advanced-toggle-label.disabled {
  color: #777; /* Gray out text */
  cursor: not-allowed;
}

#advanced-mode-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.6; /* Visual disabled look */
}

/* Advanced Workspace – exact replica of editor-workspace */
#advanced-workspace {
  display: flex;
  flex-direction: column;
  width: 100%;
  align-items: flex-start; /* Same alignment */
  padding-top: 20px; /* Same top padding */
  margin-top: 20px; /* Space below main workspace */
  border-top: 1px solid #444; /* Optional visual separation */
}

#per-frame-container,
#tags-container {
  width: 100%;
  padding: 20px;
}

#per-frame-container h3:first-child,
#tags-container h3:first-child {
  margin-top: 0;
  padding-top: 0;
  font-size: 1.3rem;
}

.frame-settings-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 128px; /* Consistent with preview panel max width */
  width: 100%;
  margin-left: auto;
  margin-right: auto; /* Center in container */
  background: #222; /* Slightly different shade for distinction */
  border-radius: 8px;
  border: 1px solid #555;
}

.frame-label {
  font-size: 1.1rem;
  font-weight: bold;
  color: #fff;
}

.frame-settings-row .ms-label {
  font-size: 1.1rem;
  color: #ccc;
}

.frame-settings-row .frame-slider {
  width: 100%;
  max-width: 200px;
}

#apply-all-frame-timings-btn {
  padding: 8px 16px;
  font-size: 0.9rem;
  min-width: 128px;
  width: 128px; /* Exact match to preview panel elements */
  margin-bottom: 16px;
}

.frame-separator {
  width: 80%;
  border: 0;
  height: 1px;
  background: #444;
  margin: 8px 0;
}

#tags-table {
  table-layout: fixed;
  width: auto;
  border-collapse: collapse;
  background: #222;
}

#tags-table th,
#tags-table td {
  border: 1px solid #444;
  padding: 8px;
  text-align: center;
}

#tags-table th {
  background: #333;
  color: #fff;
  min-width: 128px;
  height: auto;
  padding: 8px;
}

.tag-cell {
  width: 128px !important; /* Fixed 128px width */
  min-width: 128px !important;
  height: 128px !important; /* Fixed 128px height */
  min-height: 128px !important;
  background: #1e1e1e;
  border: 2px solid transparent;
  box-sizing: border-box;
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
  padding: 0; /* Remove padding to maximize textarea space */
}

#tags-table .tag-cell textarea {
  width: 100%;
  height: 100%;
  background: #1e1e1e;
  border: none;
  color: #e0e0e0;
  padding: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none; /* No manual resize */
  box-sizing: border-box;
}

#tags-table .tag-cell.filled textarea {
  background: #2a2a2a; /* Slightly different for filled cells */
}

.frame-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  width: fit-content;
  max-width: 100%;
}

#frame-settings-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%; /* Full width of parent */
  max-width: 100%;
  padding-bottom: 8px; /* Space for scrollbar */
  scrollbar-width: thin;
}

#frame-settings-scroll::-webkit-scrollbar {
  height: 8px;
}

#frame-settings-scroll::-webkit-scrollbar-track {
  background: #222;
}

#frame-settings-scroll::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}

#frame-settings-list {
  display: flex;
  flex-direction: row;
  gap: 16px;
  width: fit-content; /* Grow to content */
  flex-wrap: nowrap; /* NEW: Prevent wrapping */
  padding: 12px 0;
}

.frame-settings-row {
  flex-shrink: 0; /* NEW: Prevent chunks from shrinking */
  width: 128px;
  /* ... your existing styles ... */
}

#preview-speed-slider:disabled {
  opacity: 0.5; /* Grayed-out look */
  cursor: not-allowed;
}

#preview-speed-label.disabled {
  color: #777; /* Gray out label text */
  cursor: not-allowed;
}

#set-state-timing-btn:disabled {
  opacity: 0.5; /* Grayed-out look */
  cursor: not-allowed;
  background: #555; /* Hover effect like secondary-btn */
}

.input-row input[type="text"] {
  flex: 1;
  padding: 6px 8px;
  background: #3c3c3c;
  border: 1px solid #555;
  color: white;
  border-radius: 4px;
}

.hidden-frame-size {
  display: none !important;
}
/* Setup spritesheet radio + label alignment */
#setup-spritesheet-library .panel > div {
  display: flex;
  align-items: center;
  gap: 12px; /* Space between radio and text */
  padding: 8px 0;
  border-bottom: 1px solid #3c3c3c;
}

#setup-spritesheet-library .panel > div:last-child {
  border-bottom: none;
}

#setup-spritesheet-library input[type="radio"] {
  accent-color: #00ffea; /* Theme accent */
  margin: 0;
  flex-shrink: 0; /* Prevent squishing */
}

#setup-spritesheet-library label {
  display: flex;
  align-items: center;
  flex: 1;
  color: #e0e0e0;
  font-size: 0.95rem;
  cursor: pointer;
}

#setup-spritesheet-library label a {
  color: #00ffea;
  text-decoration: none; /* No underline */
  margin-left: 6px;
  transition: color 0.2s;
}

#setup-spritesheet-library label a:hover {
  color: #00e0d0; /* Slightly brighter hover */
  text-decoration: underline; /* Subtle underline on hover only */
}

.storage-info {
  font-size: 0.8em;    /* smaller font */
  color: #aaa;         /* optional: subtle color */
  margin-left: 6px;    /* a little space after the count */
}
