:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --accent: #e13d49;
  --accent-dark: #b92d38;
  --green: #167f5f;
  --red-soft: #fff1f3;
  --red-line: #f3a4ad;
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  padding: 28px;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
}

.topbar,
.scanner,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar {
  margin-bottom: 20px;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
}

.status {
  min-width: 150px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.status.is-loading {
  border-color: #f7c56f;
  background: #fff8e8;
  color: #9a5b00;
}

.status.is-ready {
  border-color: #83d6bc;
  background: #edfdf7;
  color: var(--green);
}

.status.is-error {
  border-color: var(--red-line);
  background: var(--red-soft);
  color: #b42318;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.58);
}

.loading-panel {
  width: min(420px, 90vw);
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 24px;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.loading-panel strong {
  font-size: 22px;
}

.loading-panel span {
  color: var(--muted);
  line-height: 1.45;
}

.loader {
  width: 42px;
  height: 42px;
  border: 5px solid #ffe2a8;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-box {
  margin-bottom: 16px;
  padding: 13px 15px;
  border: 1px solid var(--red-line);
  border-radius: 8px;
  background: var(--red-soft);
  color: #b42318;
  font-weight: 700;
}

.scanner {
  align-items: stretch;
}

.capture-panel,
.result-panel,
.catalog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.capture-panel {
  flex: 1.1;
  min-height: 470px;
  padding: 18px;
}

.upload-zone {
  display: grid;
  min-height: 150px;
  place-items: center;
  border: 2px dashed #9aa6b8;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  text-align: center;
}

.upload-zone input {
  display: none;
}

.upload-title {
  display: block;
  color: var(--accent-dark);
  font-size: 20px;
  font-weight: 800;
}

.upload-text {
  display: block;
  max-width: 420px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.preview {
  display: none;
  width: 100%;
  max-height: 650px;
  margin-top: 18px;
  object-fit: contain;
  border-radius: 8px;
  background: #101828;
}

.preview-placeholder {
  display: grid;
  min-height: 300px;
  margin-top: 18px;
  place-items: center;
  border-radius: 8px;
  background: #101828;
  color: #cbd5e1;
  text-align: center;
}

.result-panel {
  width: 390px;
  padding: 20px;
}

.panel-title {
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 700;
}

.empty-state {
  display: grid;
  min-height: 380px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.result-card {
  display: block;
}

.result-carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 100%;
  gap: 16px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}

.result-slide {
  position: relative;
  display: grid;
  gap: 18px;
  scroll-snap-align: start;
}

.result-slide img,
.result-card img {
  width: 100%;
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(16, 24, 40, 0.18);
}

.result-slide h2,
.result-card h2 {
  margin-bottom: 8px;
  font-size: 26px;
}

.rank-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  border-radius: 8px;
  padding: 7px 9px;
  background: rgba(23, 32, 51, 0.88);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.metric-row strong {
  color: var(--green);
}

a {
  color: var(--accent-dark);
  font-weight: 700;
}

.catalog {
  margin-top: 20px;
  padding: 20px;
}

.search-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  margin-top: 18px;
  align-items: end;
}

.search-form label {
  display: grid;
  gap: 6px;
}

.search-form span,
.catalog-summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-form input,
.search-form select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  font: inherit;
  background: var(--surface);
}

.catalog-summary {
  margin: 14px 0 0;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.catalog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  background: #98a2b3;
  cursor: wait;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.catalog-card {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.catalog-card:hover,
.catalog-card:focus-visible {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.12);
}

.catalog-card img {
  width: 100%;
  border-radius: 6px;
}

.catalog-card strong {
  display: block;
  margin-top: 8px;
  font-size: 14px;
}

.catalog-card em {
  display: block;
  margin-top: 4px;
  color: var(--green);
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
}

.catalog-card span {
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.62);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  position: relative;
  width: min(980px, 96vw);
  max-height: 90vh;
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.32);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.modal-card-detail {
  display: grid;
  grid-template-columns: minmax(220px, 330px) 1fr;
  gap: 24px;
}

.modal-card-detail > img {
  width: 100%;
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(16, 24, 40, 0.18);
}

.modal-ko {
  margin-bottom: 16px;
  color: var(--green);
  font-size: 20px;
  font-weight: 800;
}

.detail-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  border-top: 1px solid var(--line);
}

.detail-grid span,
.detail-grid strong {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-grid span {
  color: var(--muted);
}

.attack-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.attack-list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.attack-list span {
  float: right;
  color: var(--accent-dark);
  font-weight: 800;
}

.admin-page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.admin-page-size select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  font: inherit;
}

.table-wrap {
  width: 100%;
  margin-top: 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.admin-table td span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.admin-thumb {
  width: 58px;
  border-radius: 6px;
}

.name-ko-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}

.pagination span {
  color: var(--muted);
  font-weight: 800;
}

.exchange-panel {
  max-width: 560px;
}

.exchange-form {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.exchange-form input {
  width: 180px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
}

@media (max-width: 840px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .scanner,
  .section-heading {
    display: block;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

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

  .catalog-actions,
  .admin-links,
  .exchange-form {
    align-items: stretch;
    flex-direction: column;
  }

  .status,
  .result-panel {
    width: 100%;
    margin-top: 14px;
  }

  .modal-card-detail {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    padding: 18px;
  }

  h1 {
    font-size: 28px;
  }
}
