/* ── Fonts ──────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  --ink:        #241a10;
  --cream:      #f3e9d8;
  --indigo:     #24314f;
  --indigo-deep:#182338;
  --soga:       #8b4a24;
  --soga-deep:  #6e3a1b;
  --gold:       #c89144;
  --panel:      #fffaf2;
  --line:       #e4d7bf;

  --font-display: 'Fraunces', serif;
  --font-body:    'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  overflow: hidden; /* seluruh pengalaman muat dalam satu layar */
}

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── Layout ─────────────────────────────────────────────────── */
.wrapper { display: flex; flex-direction: column; height: 100vh; }

.main-content {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 18px;
  padding: 18px 24px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* ── Header ─────────────────────────────────────────────────── */
.site-header {
  position: relative;
  background: linear-gradient(120deg, var(--indigo-deep), var(--indigo));
  color: #fff;
  padding: 14px 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  overflow: hidden;
  flex-shrink: 0;
}
.site-header::before {
  content: "";
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cg fill='none' stroke='white' stroke-width='1'%3E%3Cellipse cx='30' cy='18' rx='10' ry='14'/%3E%3Cellipse cx='30' cy='42' rx='10' ry='14'/%3E%3Cellipse cx='18' cy='30' rx='14' ry='10'/%3E%3Cellipse cx='42' cy='30' rx='14' ry='10'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 60px 60px;
  opacity: .10;
  pointer-events: none;
}

.header-inner {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 32px; height: 32px; color: var(--gold); flex-shrink: 0; }
.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.45rem; font-weight: 700; line-height: 1; letter-spacing: .01em;
}
.brand-text p {
  font-family: var(--font-mono);
  font-size: .74rem; opacity: .78; margin-top: 5px; letter-spacing: .01em;
}

.kelas-badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.kelas-badge {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 20px;
  padding: 3px 11px;
  font-family: var(--font-mono);
  font-size: .7rem; font-weight: 600; letter-spacing: .01em;
}

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 2px 10px rgba(36,26,16,.06);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.card-title {
  font-family: var(--font-display);
  font-size: 1.02rem; font-weight: 600;
  color: var(--soga-deep);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

/* ── Upload Area ─────────────────────────────────────────────── */
.upload-area {
  flex: 1;
  min-height: 0;
  border: 2px dashed #c9a878;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  padding: 12px;
  background: #fdf8ef;
  overflow: hidden;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--soga); background: #fbeee0; }

.upload-icon { width: 44px; height: 44px; color: #c9a878; display: block; margin: 0 auto 10px; }
#uploadPrompt { text-align: center; }
.upload-text { font-size: .92rem; font-weight: 600; color: #6b4c2a; margin-bottom: 4px; }
.upload-hint { font-family: var(--font-mono); font-size: .74rem; color: #b09b7c; }

#previewImg { max-width: 100%; max-height: 100%; border-radius: 8px; object-fit: contain; }

/* ── Tombol ─────────────────────────────────────────────────── */
.btn-detect {
  flex-shrink: 0;
  margin-top: 14px;
  padding: 13px; background: var(--soga); color: #fff;
  border: none; border-radius: 10px; font-size: .95rem;
  font-weight: 700; cursor: pointer; letter-spacing: .02em;
  transition: background .2s, transform .1s;
}
.btn-detect:hover:not(:disabled) { background: var(--soga-deep); }
.btn-detect:active:not(:disabled) { transform: scale(.98); }
.btn-detect:disabled { background: #d8cbb5; cursor: not-allowed; }

.btn-reset {
  flex-shrink: 0;
  margin-top: 10px;
  padding: 9px; background: transparent; color: var(--indigo);
  border: 1.6px solid var(--indigo); border-radius: 9px;
  font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: all .2s;
}
.btn-reset:hover { background: var(--indigo); color: #fff; }

/* ── Panel Hasil (3 status, tanpa pindah scroll) ──────────────── */
.panel-result { position: relative; }

.state { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.state[hidden] { display: none !important; }

.state-empty, .state-loading {
  align-items: center; justify-content: center; text-align: center;
  gap: 8px; color: #a08a68;
}

.empty-illust { width: 120px; height: 80px; color: #d8c19a; margin-bottom: 6px; }
.empty-title { font-weight: 600; color: #6b4c2a; font-size: .95rem; }
.empty-hint { font-size: .8rem; max-width: 280px; color: #b09b7c; }

/* Loader "canting" — menorehkan garis motif, sesuai proses membatik */
.canting-loader { width: 120px; height: 80px; color: var(--soga); margin-bottom: 6px; }
#cantingPath {
  stroke-dasharray: 140;
  stroke-dashoffset: 140;
  animation: draw-line 1.6s ease-in-out infinite;
}
@keyframes draw-line {
  0%   { stroke-dashoffset: 140; opacity: 1; }
  60%  { stroke-dashoffset: 0;   opacity: 1; }
  100% { stroke-dashoffset: 0;   opacity: 0; }
}
.state-loading p { font-weight: 600; color: var(--soga-deep); font-size: .92rem; }
.state-loading small { font-family: var(--font-mono); font-size: .74rem; color: #b09b7c; }

@media (prefers-reduced-motion: reduce) {
  #cantingPath { animation: none; stroke-dashoffset: 0; }
}

/* ── Hasil ───────────────────────────────────────────────────── */
.result-layout { display: flex; gap: 18px; flex: 1; min-height: 0; }

.result-image-wrap {
  flex: 1 1 55%; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: #fbf5ea; border-radius: 10px; overflow: hidden;
}
#resultImg { max-width: 100%; max-height: 100%; object-fit: contain; }

.result-info { flex: 1 1 45%; min-height: 0; display: flex; flex-direction: column; }

.info-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px; flex-shrink: 0;
}
#totalFound { font-family: var(--font-display); font-weight: 700; font-size: .95rem; color: var(--soga-deep); }
.speed-tag {
  background: #eef7f0; color: #2c9a5b;
  border: 1px solid #a8dfbc; border-radius: 20px;
  padding: 3px 11px; font-family: var(--font-mono); font-size: .76rem; font-weight: 700;
}

/* ── Deteksi item ─────────────────────────────────────────────── */
.detection-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; padding-right: 2px;
}
.det-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; background: #fdf8ef;
  border-radius: 9px; border-left: 3px solid var(--gold);
}
.det-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--indigo); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: .7rem; font-weight: 700; flex-shrink: 0;
}
.det-info { flex: 1; }
.det-label { font-weight: 600; font-size: .88rem; text-transform: capitalize; }

.det-conf {
  padding: 3px 10px; border-radius: 20px;
  font-family: var(--font-mono); font-size: .76rem; font-weight: 700; flex-shrink: 0;
}
.conf-high { background: #e8f8ee; color: #27ae60; }
.conf-mid  { background: #fff8e1; color: #b9821f; }
.conf-low  { background: #fdecea; color: #d1483a; }

.no-det { margin: auto; color: #a08a68; font-style: italic; font-size: .85rem; text-align: center; padding: 16px 0; }

/* ── Footer ─────────────────────────────────────────────────── */
.site-footer {
  flex-shrink: 0;
  text-align: center; padding: 8px;
  font-size: .72rem; color: #b09b7c;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* ── Responsif: layar sempit tetap butuh scroll wajar ─────────── */
@media (max-width: 880px) {
  body { overflow: auto; }
  .wrapper { height: auto; min-height: 100vh; }
  .main-content { grid-template-columns: 1fr; }
  .card { min-height: 320px; }
  .result-layout { flex-direction: column; }
}