:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-strong: #f0f4f8;
  --ink: #18202b;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #147a8a;
  --accent-strong: #0f5f6b;
  --accent-soft: #dff5f7;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(24, 32, 43, 0.12);
  --selection-width: 560px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, "Noto Sans Thai", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(560px, min(var(--selection-width), calc(100vw - 520px)));
  gap: 18px;
  width: min(1920px, 100%);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: 18px;
}

.library-panel,
.selection-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.library-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.selection-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 36px);
  padding: 18px;
}

.topbar,
.selection-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 22px 14px;
}

.selection-header {
  padding: 0 0 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.stats {
  display: grid;
  place-items: center;
  min-width: 86px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid #b8e7ec;
  border-radius: 8px;
}

.stats strong {
  font-size: 28px;
}

.stats span {
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px auto;
  gap: 12px;
  padding: 0 22px 12px;
  align-items: end;
}

.search-box,
.select-box,
.title-box,
.export-options label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.search-box span,
.select-box span,
.title-box span,
.export-options span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 122, 138, 0.16);
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.result-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 22px 12px;
  color: var(--muted);
  font-size: 13px;
}

.pagination-bar {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr minmax(96px, auto);
  gap: 10px;
  align-items: center;
  padding: 0 22px 14px;
}

.pagination-bar span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.pagination-bar button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.skin-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  overflow: auto;
  padding: 0 22px 22px;
}

.skin-card {
  display: grid;
  grid-template-rows: 178px auto;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  text-align: left;
  padding: 0;
}

.skin-card.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.skin-card img {
  width: 100%;
  height: 178px;
  object-fit: cover;
  background: var(--panel-strong);
}

.skin-info {
  min-width: 0;
  padding: 0 10px 10px;
}

.hero-name,
.skin-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hero-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.skin-name {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
}

.title-box {
  display: none;
  margin-bottom: 12px;
}

.selected-list {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--preview-columns, 3), minmax(96px, 1fr));
  gap: 0;
  overflow: auto;
  padding: 8px 6px 8px 2px;
  align-items: start;
}

.selected-item {
  position: relative;
  display: block;
  aspect-ratio: 0.72;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: var(--panel-strong);
  box-shadow: none;
  overflow: visible;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.selected-item.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.selected-item img {
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: cover;
  background: var(--panel-strong);
}

.selected-item::after {
  content: "";
  position: absolute;
  inset: 45% 0 0;
  border-radius: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.68));
  pointer-events: none;
}

.selected-name {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 12px;
  z-index: 2;
  min-width: 0;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.75);
}

.selected-name strong,
.selected-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-name strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.08;
}

.selected-name span {
  display: none;
}

.order-badge {
  position: absolute;
  left: 50%;
  bottom: 30px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.icon-btn {
  min-width: 38px;
  padding: 0 8px;
}

.remove-btn {
  position: absolute;
  top: -9px;
  right: -9px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #f00000;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

.remove-btn:hover {
  border-color: #fff;
  background: #d30000;
}

.empty-state {
  display: none;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.empty-state.visible {
  display: grid;
}

.export-card {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.export-options {
  display: grid;
  grid-template-columns: 120px;
  gap: 10px;
}

.export-options label:last-child {
  display: none;
}

.primary-btn {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-btn:disabled {
  border-color: var(--line);
  background: #c7d0dc;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(16px);
  min-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: #18202b;
  color: #fff;
  padding: 12px 16px;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
  text-align: center;
  z-index: 20;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .selection-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .library-panel {
    max-height: none;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .quick-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .selection-panel {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
    padding: 16px 14px 10px;
  }

  h1 {
    font-size: 24px;
  }

  .controls,
  .export-options {
    grid-template-columns: 1fr;
  }

  .controls {
    padding: 0 14px 10px;
  }

  .result-meta {
    padding: 0 14px 10px;
  }

  .pagination-bar {
    grid-template-columns: 1fr auto 1fr;
    padding: 0 14px 12px;
  }

  .pagination-bar button {
    min-width: 0;
    padding: 0 10px;
  }

  .skin-grid {
    padding: 0 14px 14px;
  }

  .selected-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .skin-grid {
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  }

  .skin-card {
    grid-template-rows: 150px auto;
  }

  .skin-card img {
    height: 150px;
  }

  .selected-name strong {
    font-size: 17px;
    line-height: 1.12;
  }

  .selected-name {
    left: 46px;
    right: 8px;
    bottom: 10px;
    text-align: left;
  }

  .order-badge {
    left: 12px;
    bottom: 12px;
    width: 28px;
    height: 28px;
    transform: none;
    font-size: 13px;
  }
}
