* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  padding: 10px 20px;
  background: #16213e;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

h1 {
  color: #00d9ff;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  height: 1.4rem;
  width: auto;
  image-rendering: pixelated;
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: flex;
  padding: 10px;
  gap: 10px;
  overflow: hidden;
}

/* Left column: TileSet + Render */
.left-column {
  width: 50%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* Right column: Tile Edit (100% height) */
.right-column {
  width: 50%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Panels */
.panel {
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tileset-panel {
  flex: 1;
  min-height: 0;
}

.render-panel {
  flex: 1;
  min-height: 0;
}

.tileedit-panel {
  flex: 1;
  min-height: 0;
}

.panel-header {
  padding: 8px 12px;
  background: #0f3460;
  font-size: 12px;
  font-weight: 500;
  color: #00d9ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  height: 40px;
  gap: 6px;
  overflow: hidden;
}

.panel-header-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.header-btn {
  padding: 4px 8px;
  background: #1a5f9e;
  color: #eee;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.2s, opacity 0.2s;
}

.header-btn:hover:not(:disabled) {
  background: #2a7fcf;
}

.header-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.header-btn.active {
  background: #00d9ff;
  color: #1a1a2e;
}

.header-divider {
  width: 1px;
  height: 16px;
  background: #2a4a6a;
  margin: 0 4px;
}

.info-badge {
  padding: 3px 8px;
  background: #0a1628;
  border: 1px solid #2a4a6a;
  border-radius: 3px;
  font-size: 11px;
  color: #88ccff;
}

.panel-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

.placeholder-text {
  color: #666;
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

/* Tile Set Canvas */
#tileset-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: auto;
}

#tileset-canvas {
  image-rendering: pixelated;
  cursor: default;
  display: block;
  flex-shrink: 0;
}

#color-picker {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid #444;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}

#color-picker::-webkit-color-swatch-wrapper {
  padding: 2px;
}

#color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

#color-picker.transparent {
  border-color: #00d9ff;
}

.transparent-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid #444;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
  overflow: hidden;
}

.transparent-btn:hover {
  border-color: #666;
}

.transparent-btn.active {
  border-color: #00d9ff;
}

.transparent-pattern {
  width: 100%;
  height: 100%;
  background:
    linear-gradient(45deg, #3a3a4a 25%, transparent 25%),
    linear-gradient(-45deg, #3a3a4a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3a4a 75%),
    linear-gradient(-45deg, transparent 75%, #3a3a4a 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #2a2a3a;
}

/* Edit Canvas Container - centered */
.edit-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: auto;
}

#edit-canvas {
  image-rendering: pixelated;
  cursor: crosshair;
  display: block;
  flex-shrink: 0;
}

/* Dialog Styles */
dialog {
  background: #16213e;
  color: #eee;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 20px;
  min-width: 280px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog h2 {
  margin-bottom: 15px;
  color: #00d9ff;
  font-size: 1.2rem;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 8px;
  background: #1a1a2e;
  border: 1px solid #444;
  border-radius: 4px;
  color: #eee;
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: #00d9ff;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.dialog-buttons button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.dialog-buttons button:not(.secondary) {
  background: #00d9ff;
  color: #1a1a2e;
}

.dialog-buttons button:not(.secondary):hover {
  background: #00b8d9;
}

.dialog-buttons button.secondary {
  background: #444;
  color: #eee;
}

.dialog-buttons button.secondary:hover {
  background: #555;
}

/* Footer bar */
.footer-bar {
  padding: 6px 15px;
  background: #16213e;
  font-size: 11px;
  color: #4a6a8a;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-tip {
  color: #88ccff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.copyright {
  flex-shrink: 0;
}

/* Render Panel */
.render-container {
  display: flex;
  flex: 1;
  min-height: 0;
}

.render-sidebar {
  width: 60px;
  background: transparent;
  border-right: 1px solid #2a4a6a;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 4px;
  flex-shrink: 0;
}

.render-sidebar-left {
  border-right: 1px solid #2a4a6a;
  border-left: none;
}

.render-sidebar-right {
  width: 140px;
  border-right: none;
  border-left: 1px solid #2a4a6a;
}

.render-mode-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-btn {
  padding: 6px 4px;
  background: #1a5f9e;
  color: #eee;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.2s;
}

.mode-btn:hover:not(:disabled) {
  background: #2a7fcf;
}

.mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mode-btn.active {
  background: #00d9ff;
  color: #1a1a2e;
}

.frame-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  padding-right: 2px;
}

.frame-list::-webkit-scrollbar {
  width: 6px;
}

.frame-list::-webkit-scrollbar-track {
  background: #1a1a2e;
}

.frame-list::-webkit-scrollbar-thumb {
  background: #3a3a5a;
  border-radius: 3px;
}

.frame-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: #0f3460;
  border-radius: 3px;
  border: 1px solid transparent;
}

.frame-item.selected {
  border-color: #00ff00;
}

.frame-preview {
  width: 32px;
  height: 32px;
  background: #2a2a4a;
  border: 1px solid #3a3a5a;
  cursor: pointer;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.frame-preview:hover {
  border-color: #5a5a7a;
}

.frame-controls {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.frame-duration {
  display: flex;
  align-items: center;
  gap: 2px;
}

.frame-duration input {
  width: 36px;
  padding: 2px;
  background: #1a1a2e;
  border: 1px solid #3a3a5a;
  border-radius: 2px;
  color: #eee;
  font-size: 10px;
  text-align: center;
}

.frame-duration input:focus {
  outline: none;
  border-color: #00d9ff;
}

.frame-duration-btn {
  width: 16px;
  height: 18px;
  padding: 0;
  background: #1a5f9e;
  color: #eee;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
}

.frame-duration-btn:hover {
  background: #2a7fcf;
}

.frame-delete {
  padding: 2px 6px;
  background: #8b3030;
  color: #eee;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-size: 9px;
}

.frame-delete:hover {
  background: #a04040;
}

.render-workspace {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: auto;
}

#render-canvas {
  display: block;
  flex-shrink: 0;
}

/* Smooth scaling toggle button */
.toggle-btn {
  width: 28px;
  height: 24px;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.smooth-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at center, #4488ff 0%, #4488ff 60%, transparent 70%);
  border: 2px solid #fff;
  box-sizing: border-box;
}

.toggle-btn:not(:disabled):hover .smooth-icon {
  background: radial-gradient(circle at center, #66aaff 0%, #4488ff 60%, transparent 70%);
}

.toggle-btn.active .smooth-icon {
  background: radial-gradient(circle at center, #00d9ff 0%, #4488ff 60%, transparent 70%);
}
