body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  background-color: #2b2b2b;
  color: #eee;
  overflow: hidden;
  user-select: none;
}

/* Layout */
#left-panel {
  width: 300px;
  min-width: 300px;
  background-color: #1e1e1e;
  border-right: none;
  display: flex;
  flex-direction: column;
  position: relative;
}
#right-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: #333;
  position: relative;
}

#panel-splitter {
  width: 8px;
  background: linear-gradient(to right, #262626, #353535, #262626);
  border-left: 1px solid #1b1b1b;
  border-right: 1px solid #1b1b1b;
  cursor: col-resize;
  flex-shrink: 0;
  z-index: 20;
  touch-action: none;
}

#panel-splitter:hover {
  background: linear-gradient(to right, #2c2c2c, #3f3f3f, #2c2c2c);
}

body.resizing {
  user-select: none;
}

/* Header */
.panel-header {
  padding: 10px;
  background-color: #252526;
  font-weight: bold;
  border-bottom: 1px solid #444;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  min-height: 40px;
  box-sizing: border-box;
}

#normal-header,
#modify-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 8px;
}

#normal-header > span {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.panel-header-buttons {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* --- BUTTON STYLES (Shared) --- */
button {
  height: 28px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  box-sizing: border-box;
  transition: all 0.2s;
}

/* Open / Back buttons (grey) */
.btn-open {
  background-color: #3c3c3c;
  color: #ccc;
  border-color: #555;
}
.btn-open:hover {
  background-color: #4c4c4c;
  color: white;
  border-color: #666;
}
.btn-open:disabled {
  background-color: #333;
  color: #666;
  cursor: not-allowed;
  border-color: #444;
}

/* Extract buttons (blue) */
.action-btn {
  background-color: #0e639c;
  color: white;
  white-space: nowrap;
  flex-shrink: 0;
}
.action-btn:hover {
  background-color: #1177bb;
}
.action-btn:disabled {
  background-color: #444;
  color: #888;
  cursor: not-allowed;
  border-color: #444;
}

/* Save button (green) */
.btn-save {
  background-color: #388e3c;
  color: white;
}
.btn-save:hover {
  background-color: #4caf50;
}
.btn-save:disabled {
  background-color: #444;
  color: #888;
  cursor: not-allowed;
  border-color: #444;
}

/* Icon Style */
.btn-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* List Area */
#region-list-container {
  flex: 1;
  overflow-y: auto;
}
#region-list {
  list-style: none;
  padding: 0;
  margin: 0;
  padding-bottom: 20px;
}
.region-item {
  padding: 6px 15px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #2a2a2a;
  user-select: none;
}
.region-item:hover {
  background-color: #2a2d2e;
}

/* Highlight Styles */
.region-item.selected {
  background-color: #094771;
  color: white;
}

/* Right Panel Controls */
#controls {
  padding: 10px;
  background-color: #252526;
  border-bottom: 1px solid #444;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
  z-index: 10;
  min-height: 40px;
  box-sizing: border-box;
}

#extract-controls,
#modify-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  overflow: hidden;
}

/* Repack Options Row */
#repack-options {
  width: 100%;
  padding-top: 6px;
  border-top: 1px solid #3a3a3a;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #bbb;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 32px;
  height: 18px;
  background-color: #555;
  border-radius: 9px;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background-color: #ccc;
  border-radius: 50%;
  transition:
    transform 0.2s,
    background-color 0.2s;
}

.toggle-label input:checked + .toggle-switch {
  background-color: #0e639c;
}

.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(14px);
  background-color: white;
}

.info-icon {
  width: 14px;
  height: 14px;
  fill: #777;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-label:hover .info-icon {
  fill: #aaa;
}

.repack-mode-label {
  font-size: 12px;
  color: #bbb;
}

#repack-mode-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.repack-mode-select {
  height: 28px;
  background-color: #2f2f2f;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 12px;
}

.repack-mode-select:disabled {
  color: #888;
  border-color: #444;
  background-color: #272727;
}

.repack-info-btn {
  height: 26px;
  width: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #555;
  background-color: #2f2f2f;
  color: #aaa;
}

.repack-info-btn:hover {
  color: #fff;
  border-color: #6a6a6a;
  background-color: #3a3a3a;
}

#repack-info-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.55);
  z-index: 2300;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

#repack-info-box {
  background-color: #252526;
  border: 1px solid #454545;
  border-radius: 8px;
  width: min(560px, calc(100vw - 20px));
  padding: 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

#repack-info-box h3 {
  margin: 0 0 10px 0;
  color: #e4e4e4;
  font-size: 17px;
}

#repack-info-box p {
  margin: 0 0 12px 0;
  color: #b9b9b9;
  line-height: 1.45;
  font-size: 13px;
}

/* Preview Area */
#preview-container {
  flex: 1;
  overflow: hidden;
  background-image: conic-gradient(
    #222 90deg,
    #333 90deg 180deg,
    #222 180deg 270deg,
    #333 270deg
  );
  background-size: 20px 20px;
  position: relative;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
#preview-container:active {
  cursor: grabbing;
}

img#preview-img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  border: 1px solid #555;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  display: none;
  transform-origin: center center;
  transition: transform 0.05s ease-out;
  image-rendering: optimizeQuality;
}

#region-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#status-text,
#modify-status-text {
  flex: 1;
  min-width: 0;
  color: #aaa;
  font-size: 0.9em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toast Notification */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}
.toast {
  background-color: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-left: 4px solid #0e639c; /* Blue accent */
  font-size: 14px;
  animation: slideIn 0.3s ease-out forwards;
  opacity: 0;
  transform: translateY(20px);
  max-width: 300px;
}
.toast.success {
  border-left-color: #4caf50;
}
.toast.error {
  border-left-color: #f44336;
}

@keyframes slideIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background-color: #1e1e1e;
}
::-webkit-scrollbar-thumb {
  background-color: #555;
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: #666;
}
::-webkit-scrollbar-corner {
  background-color: #1e1e1e;
}

/* Modal Styling */
.hidden {
  display: none !important;
}

#modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

#modal-box {
  background-color: #252526;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  min-width: 320px;
  max-width: 400px;
  border: 1px solid #454545;
  animation: modalPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

#modal-title {
  margin-top: 0;
  margin-bottom: 10px;
  color: #ddd;
  font-size: 18px;
}

#modal-message {
  color: #bbb;
  margin-bottom: 24px;
  line-height: 1.5;
  white-space: pre-line;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

.btn-primary {
  background-color: #0e639c;
  color: white;
}
.btn-primary:hover {
  background-color: #1177bb;
}
.btn-primary:active {
  background-color: #094771;
}

.btn-secondary {
  background-color: #3c3c3c;
  color: #ccc;
  border: 1px solid #555;
}
.btn-secondary:hover {
  background-color: #4c4c4c;
  color: white;
}
.btn-secondary:active {
  background-color: #2d2d2d;
}

.missing-images-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.55);
  z-index: 2600;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

.missing-images-dialog {
  width: min(680px, calc(100vw - 24px));
  max-height: min(80vh, 760px);
  overflow: hidden;
  background-color: #252526;
  border: 1px solid #454545;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: modalPop 0.2s ease-out;
}

.missing-images-title {
  margin: 0;
  font-size: 18px;
  color: #e5e5e5;
}

.missing-images-subtitle {
  margin: 0;
  font-size: 13px;
  color: #b7b7b7;
}

.missing-images-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-width: 0;
  padding-right: 4px;
}

.missing-images-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid #3c3c3c;
  border-radius: 6px;
  background-color: #2b2b2b;
}

.missing-images-row.selected {
  border-color: #0e639c;
}

.missing-images-row.drag-over {
  border-color: #0e639c;
  border-style: dashed;
  background-color: #28415a;
}

.missing-images-page {
  color: #e4e4e4;
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.missing-images-status {
  color: #a6a6a6;
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.missing-images-row.selected .missing-images-status {
  color: #d8ecff;
}

.missing-images-btn {
  height: 30px;
}

.missing-images-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 640px) {
  .missing-images-overlay {
    align-items: flex-end;
  }

  .missing-images-dialog {
    width: calc(100vw - 12px);
    max-height: min(88vh, 900px);
    padding: 12px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .missing-images-row {
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: stretch;
  }

  .missing-images-page,
  .missing-images-status {
    white-space: normal;
    word-break: break-word;
  }

  .missing-images-btn {
    width: 100%;
    height: 34px;
  }

  .missing-images-buttons {
    justify-content: stretch;
  }

  .missing-images-buttons .btn-secondary,
  .missing-images-buttons .btn-primary {
    flex: 1;
  }
}

.btn-primary:disabled {
  background-color: #444;
  color: #888;
  cursor: not-allowed;
}

/* Context Menu */
#context-menu {
  position: fixed;
  background-color: #2d2d2d;
  border: 1px solid #454545;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  padding: 4px 0;
  z-index: 4000;
  min-width: 160px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 13px;
  color: #ccc;
  cursor: pointer;
  transition: background-color 0.1s;
}

.context-menu-item:hover {
  background-color: #094771;
  color: white;
}

.context-menu-item .btn-icon {
  width: 14px;
  height: 14px;
}

/* Drop Overlay Styling */
#drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(14, 99, 156, 0.85);
  z-index: 3000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

#drop-overlay:not(.hidden) {
  display: flex !important;
  pointer-events: auto;
}

.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  color: white;
  pointer-events: none;
}

.drop-message svg {
  width: 80px;
  height: 80px;
  fill: white;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-15px);
  }
}

.drop-message span {
  font-size: 24px;
  font-weight: bold;
}


/* ==========================================
   UPDATE NOTIFICATION BAR (Bottom of right panel)
   ========================================== */

.toast-update {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: #1e2a38;
  border-top: 1px solid #2d6a9f;
  font-size: 12px;
  animation: slideUpBar 0.25s ease-out forwards;
  flex-shrink: 0;
}

@keyframes slideUpBar {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast-update-icon {
  width: 16px;
  height: 16px;
  fill: #4fc3f7;
  flex-shrink: 0;
}

.toast-update-title {
  font-weight: 600;
  color: #e0f0ff;
  white-space: nowrap;
}

.toast-update-sub {
  color: #7bafd4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.toast-update-btn-go {
  background-color: #0e639c;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 0 10px;
  height: 22px;
  font-size: 11px;
  font-family: "Segoe UI", sans-serif;
  cursor: pointer;
  transition: background-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}
.toast-update-btn-go:hover {
  background-color: #1177bb;
}

.toast-update-btn-go:disabled {
  background-color: #4a4a4a;
  color: #999;
  cursor: not-allowed;
}

.toast-update-btn-close {
  background: transparent;
  color: #ff6464;
  border: 1px solid #ff6464;
  padding: 0 6px;
  height: 22px;
  font-size: 11px;
  cursor: pointer;
  border-radius: 3px;
  transition: color 0.15s, background-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.toast-update-btn-close:hover {
  color: #e0f0ff;
  background-color: rgba(255, 255, 255, 0.08);
}

.toast-update-error {
  background-color: #3a1f1f;
  border-top: 1px solid #a94442;
}

.toast-update-error .toast-update-title {
  color: #ffd6d6;
}

.toast-update-error .toast-update-sub {
  color: #ffb3b3;
}

/* Responsive layout for portrait screens (mobile/tablet) */
@media (orientation: portrait), (max-width: 900px) {
  body {
    flex-direction: column;
  }

  /* Keep preview side on top */
  #right-panel {
    order: 1;
    min-height: 44dvh;
    border-bottom: none;
  }

  #panel-splitter {
    order: 2;
    width: 100%;
    height: 10px;
    cursor: row-resize;
    border-left: none;
    border-right: none;
    border-top: 1px solid #1b1b1b;
    border-bottom: 1px solid #1b1b1b;
    background: linear-gradient(to bottom, #262626, #353535, #262626);
  }

  /* Move regions panel below */
  #left-panel {
    order: 3;
    width: 100%;
    min-width: 0;
    min-height: 0;
    flex: 1;
    border-right: none;
  }

  #controls {
    padding: 8px;
    gap: 8px;
  }

  #extract-controls,
  #modify-controls {
    gap: 8px;
  }

  #status-text,
  #modify-status-text {
    font-size: 12px;
  }

  #repack-options {
    gap: 8px;
  }

  .repack-mode-label {
    width: 100%;
  }

  #repack-mode-group {
    width: calc(100% - 42px);
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .repack-mode-select {
    width: 100%;
    min-width: 0;
  }

  #preview-container {
    min-height: 0;
  }

  .drop-message span {
    font-size: 18px;
    text-align: center;
    padding: 0 16px;
  }
}