* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; background: #ffffff; color: #222; }
#app { width: 100vw; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }

/* Tab Bar */
.tab-bar {
  display: flex;
  padding: 8px 8px 0 8px;
  background: #f0f0f0;
  border-bottom: none;
}
.tabs-scroll {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}
.tabs-scroll::-webkit-scrollbar {
  display: none;
}
.tab {
  padding: 8px 16px;
  background: #e0e0e0;
  border: none;
  color: #333;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
  flex-shrink: 0;
  height: 36px;
  line-height: 20px;
}
.tab.active { background: #ffffff; padding-right: 8px; }
.tab-add { background: transparent; color: #666; flex-shrink: 0; }
.tab-wrapper {
  display: flex;
  align-items: center;
  position: relative;
  flex-shrink: 0;
  height: 36px;
}
.tab-wrapper:has(.tab.active) {
  background: #ffffff;
  border-radius: 4px 4px 0 0;
  padding-right: 8px;
}
.tab-wrapper {
  cursor: grab;
  user-select: none;
}
.tab-wrapper.dragging {
  cursor: grabbing;
}
.tab-delete {
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  margin-right: 4px;
}
.tab-delete:hover {
  color: #ff4444;
}
.header-icons {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  margin-top: -3px;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #333;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn-icon:last-child {
  margin-top: 3px;
}

/* Table View */
.table-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.empty {
  color: #888;
  text-align: center;
  padding: 40px;
}

/* Table Config Row */
.table-config {
  display: flex;
  gap: 24px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, #ffffff, #f5f5f5);
  border-bottom: 1px solid #ddd;
}
.table-config label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #555;
}
.table-config input {
  width: 80px;
  padding: 6px;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
}

/* Table Actions */
.table-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
}
.table-actions button {
  padding: 8px 16px;
  background: #e0e0e0;
  border: none;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
}

/* Blend Delta Footer */
.blend-delta-footer {
  display: flex;
  align-items: center;
  gap: 6px;
}
.part-selector {
  padding: 6px 12px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  color: #333;
  width: 120px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.blend-delta-footer input {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  width: 84px;
  flex-shrink: 0;
}
.blend-delta-footer button {
  padding: 6px 12px;
  margin: 0 20px;
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.blend-delta-footer button:hover {
  background: #0052a3;
}
.delta-result {
  padding: 6px 12px;
  background: #e8f4f8;
  border: 1px solid #0066cc;
  border-radius: 4px;
  font-size: 12px;
  color: #0066cc;
  font-weight: 500;
  white-space: nowrap;
  width: 80px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  min-height: 32px;
}

/* Parts Grid */
.parts-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}
.grid-row {
  display: grid;
  grid-template-columns: 2fr repeat(7, 1fr) auto;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #e0e0e0;
  align-items: center;
}
.grid-header {
  font-weight: bold;
  color: #666;
  font-size: 12px;
  text-transform: uppercase;
}
.grid-row input {
  width: 100%;
  padding: 6px;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
  text-align: center;
}
.calculated {
  text-align: center;
  color: #0066cc;
  font-weight: bold;
}
.btn-delete-part {
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
}
.btn-delete-part:hover {
  color: #ff4444;
}

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  min-width: 300px;
  max-width: 90vw;
  width: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.modal:has(.neko-style-item) {
  min-width: 600px;
}
.modal h2 {
  margin-bottom: 16px;
  color: #222;
}
.part-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.part-option {
  padding: 12px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
}
.part-option:hover {
  background: #e8e8e8;
}
.btn-cancel {
  padding: 8px 16px;
  background: #e0e0e0;
  border: none;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
}

/* Screen Header */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 12px 16px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
}
.screen-header button {
  position: absolute;
  left: 16px;
  background: none;
  border: none;
  color: #0066cc;
  cursor: pointer;
  font-size: 16px;
}
.screen-header h1 {
  font-size: 18px;
  color: #222;
}

/* Settings Screen Scrolling */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}
.screen::-webkit-scrollbar {
  width: 8px;
}
.screen::-webkit-scrollbar-track {
  background: transparent;
}
.screen::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.screen::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

/* Settings */
.settings-section {
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
}
.settings-section h2 {
  font-size: 14px;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.settings-section label {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #444;
}
.settings-section select {
  padding: 8px;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
}
.hint {
  color: #888;
  font-size: 12px;
  margin-bottom: 12px;
}
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-row {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.settings-header {
  color: #666;
  font-size: 12px;
}
.settings-row input {
  padding: 8px;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
}
.btn-add {
  padding: 8px;
  background: #f5f5f5;
  border: 1px dashed #ccc;
  color: #666;
  cursor: pointer;
  border-radius: 4px;
}
.btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #666;
}
.btn-delete:hover {
  color: #ff4444;
}
.danger-zone {
  border-color: #ff4444;
}
.btn-danger {
  padding: 12px 24px;
  background: #ff4444;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
}

/* Clear All Confirmation */
.clear-confirm ul {
  margin: 12px 0;
  padding-left: 20px;
  color: #666;
}
.clear-confirm input {
  width: 100%;
  padding: 12px;
  margin: 12px 0;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}
.modal-actions .btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Explosion Animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}
.shake {
  animation: shake 1.5s ease-in-out;
}

#explosion {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2000;
}

@keyframes explode {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(0); opacity: 0; }
}
.particle {
  position: absolute;
  font-size: 24px;
  animation: explode 1.8s ease-out forwards;
}

#flash {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 1999;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  z-index: 3000;
}
.toast-warning {
  background: #f0c000;
  color: #222;
}

/* Logs Screen */
.logs-toolbar {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  align-items: center;
}
.logs-toolbar input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  border-radius: 4px;
}
.bulk-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}
.bulk-actions label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #666;
}
.bulk-actions button {
  padding: 8px 12px;
  background: #e0e0e0;
  border: none;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
}
.bulk-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.logs-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}
.log-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid #e0e0e0;
}
.log-name {
  flex: 1;
  cursor: pointer;
  color: #0066cc;
}
.log-name:hover {
  text-decoration: underline;
}

/* Delete Confirmation */
.delete-confirm {
  text-align: center;
}
.delete-confirm p {
  color: #666;
  margin: 12px 0;
}

/* Neko Style Picker */
.neko-style-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s;
}
.neko-style-item:hover {
  transform: scale(1.05);
}
.neko-style-item img {
  transition: border-color 0.2s;
}
.neko-style-item:hover img {
  border-color: #0066cc !important;
}

/* Font Picker */
.font-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px 0;
}

.font-picker-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 12px 8px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  transition: all 0.2s;
}

.font-picker-item:hover {
  border-color: #0066cc;
  transform: scale(1.02);
}

.font-picker-item.selected {
  border-color: #0066cc;
  border-width: 3px;
  background: #f0f7ff;
}

.font-preview {
  font-size: 16px;
  text-align: center;
  padding: 8px 4px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
}

.font-category {
  margin: 8px 0 0 0;
  font-size: 10px;
  text-transform: uppercase;
  color: #999;
  font-weight: 500;
}

/* Modal with font picker should be wider */
.modal:has(.font-picker-grid) {
  min-width: 700px;
}

/* Version & Update Styles */
.version-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.version-display {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  min-width: 100px;
}

.btn-version-check,
.btn-version-download {
  width: 36px;
  height: 36px;
  border: 2px solid #333;
  border-radius: 4px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-version-check:hover,
.btn-version-download:hover {
  background: #f0f0f0;
}

.btn-version-check:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Update flash animation: red ↔ yellow for 1 second, then settle to black */
@keyframes update-flash {
  0% { background-color: #ff4444; border-color: #ff4444; color: white; }
  12.5% { background-color: #ffcc00; border-color: #ffcc00; color: black; }
  25% { background-color: #ff4444; border-color: #ff4444; color: white; }
  37.5% { background-color: #ffcc00; border-color: #ffcc00; color: black; }
  50% { background-color: #ff4444; border-color: #ff4444; color: white; }
  62.5% { background-color: #ffcc00; border-color: #ffcc00; color: black; }
  75% { background-color: #ff4444; border-color: #ff4444; color: white; }
  87.5% { background-color: #ffcc00; border-color: #ffcc00; color: black; }
  100% { background-color: #222; border-color: #222; color: white; }
}

.btn-version-download.update-flash {
  animation: update-flash 1s ease-out forwards;
}

/* Update confirmation button */
.btn-update {
  padding: 12px 24px;
  background: #0066cc;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
  font-weight: 500;
}

.btn-update:hover {
  background: #0055aa;
}

/* Post-Update Banner */
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #00ff88;
  text-align: center;
  padding: 16px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 2px;
  z-index: 5000;
  opacity: 0;
  transform: translateY(-100%);
  transition: all 0.3s ease-out;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.update-banner.visible {
  opacity: 1;
  transform: translateY(0);
}

.update-banner.fade-out {
  opacity: 0;
  transform: translateY(-100%);
}
