:root {
  --bg: #15151a;
  --bg-2: #1d1d24;
  --card: #23232c;
  --line: #32323d;
  --txt: #f2f1ee;
  --muted: #9a9aa6;
  --gold: #d9b97a;
  --gold-2: #c89c54;
  --green: #5ec27a;
  --danger: #e0796b;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* --- Giriş --- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 80% at 50% -10%, #26222a 0%, var(--bg) 60%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: 22px; padding: 32px 24px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-mark { color: var(--gold); }
.brand h1 { margin: 10px 0 2px; font-size: 26px; letter-spacing: .5px; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }

input[type=password], input[type=text] {
  width: 100%; padding: 14px 16px; font-size: 16px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--txt); outline: none;
}
input:focus { border-color: var(--gold-2); }

.btn-primary {
  width: 100%; padding: 14px 16px; font-size: 16px; font-weight: 600;
  border: none; border-radius: 12px; color: #2a2113;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-2) 100%);
}
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  padding: 12px 16px; font-size: 15px; background: transparent;
  color: var(--txt); border: 1px solid var(--line); border-radius: 12px;
}
.btn-ghost.full { width: 100%; }
.btn-ghost.danger { color: var(--danger); border-color: #4a3433; }
.btn-text { background: none; border: none; color: var(--muted); font-size: 15px; padding: 10px; }
.error { color: var(--danger); font-size: 14px; text-align: center; margin: 4px 0 0; }

/* --- Üst bar --- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(21,21,26,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.index-info { color: var(--muted); font-size: 12px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--txt); font-size: 18px; line-height: 1;
}

.main { flex: 1; padding: 16px; max-width: 680px; width: 100%; margin: 0 auto; }

/* --- Kod ile arama --- */
.code-search { display: flex; gap: 8px; }
#code-input {
  flex: 1; text-transform: uppercase;
}
#code-input::placeholder { text-transform: none; }
.code-btn {
  width: 52px; border: none; border-radius: 12px; font-size: 20px; color: #2a2113;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-2) 100%);
}
.code-btn:active { transform: translateY(1px); }

.or-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 12px; margin: 18px 2px;
}
.or-divider::before, .or-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

/* --- Kamera / Galeri butonları --- */
.capture-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cap-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
  border: 1.5px dashed var(--gold-2); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-2), var(--card));
  padding: 26px 12px; text-align: center; font-size: 15px; font-weight: 600; color: var(--txt);
}
.cap-btn:active { border-color: var(--gold); transform: scale(.99); }
.cap-ico { font-size: 34px; }

.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 24px; }

/* --- Kırpma --- */
.cropper { display: flex; flex-direction: column; gap: 12px; }
.crop-hint { color: var(--muted); font-size: 13px; text-align: center; }
.crop-stage {
  position: relative; width: 100%; line-height: 0;
  touch-action: none; user-select: none; -webkit-user-select: none;
  background: #000; border-radius: var(--radius); overflow: hidden;
}
#crop-img { width: 100%; height: auto; display: block; -webkit-user-drag: none; }
.crop-box {
  position: absolute; border: 2px solid var(--gold);
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5);
  cursor: move; box-sizing: border-box;
}
.ch {
  position: absolute; width: 26px; height: 26px; background: var(--gold);
  border: 2px solid #2a2113; border-radius: 50%;
}
.ch-tl { left: -13px; top: -13px; cursor: nwse-resize; }
.ch-tr { right: -13px; top: -13px; cursor: nesw-resize; }
.ch-bl { left: -13px; bottom: -13px; cursor: nesw-resize; }
.ch-br { right: -13px; bottom: -13px; cursor: nwse-resize; }
.crop-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

/* --- Sorgu önizleme --- */
.query {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 16px;
}
#query-img { width: 76px; height: 76px; object-fit: cover; border-radius: 12px; background: #fff; }
.query-side { flex: 1; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.status-line { font-size: 15px; color: var(--muted); }
.status-line.done { color: var(--green); }

/* --- Sonuçlar --- */
.results-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 12px; gap: 10px; }
.results-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
.results-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.elapsed { color: var(--muted); font-size: 12px; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 520px) { .results { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; text-align: center;
}
.card:active { transform: scale(.98); }
.card .thumb {
  width: 100%; aspect-ratio: 1; object-fit: cover; background: #fff; display: block;
}
.card .meta { padding: 7px 6px 9px; }
.card .code { font-size: 11.5px; font-weight: 600; word-break: break-all; line-height: 1.25; }
.card .bar { height: 4px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.card .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-2), var(--gold)); }
.card.top1 { border-color: var(--gold-2); box-shadow: 0 0 0 1px var(--gold-2) inset; }
.rank { position: absolute; }

/* --- Spinner --- */
.spinner { display: grid; place-items: center; padding: 40px; }
.ring {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--gold);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Modal --- */
.modal, .sheet { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; }
.modal-backdrop, .sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-card {
  position: relative; z-index: 1; width: min(92vw, 460px);
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  overflow: hidden; box-shadow: var(--shadow);
}
#modal-img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.modal-info { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-code { font-size: 22px; font-weight: 700; letter-spacing: .5px; word-break: break-all; }
.modal-score { color: var(--muted); font-size: 14px; }
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 15px;
}

/* --- Alt sayfa (menü) --- */
.sheet { align-items: end; }
.sheet-card {
  position: relative; z-index: 1; width: 100%; max-width: 680px; margin: 0 auto;
  background: var(--card); border-top-left-radius: 22px; border-top-right-radius: 22px;
  border: 1px solid var(--line); padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  display: flex; flex-direction: column; gap: 12px;
}
.sheet-card h3 { margin: 4px 0 6px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Footer --- */
.site-footer {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 20px 12px calc(env(safe-area-inset-bottom) + 16px);
  margin-top: 18px;
}
.login-card .site-footer { margin-top: 22px; padding-bottom: 0; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%); z-index: 30;
  background: #2c2c36; border: 1px solid var(--line); color: var(--txt);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
  animation: toastin .2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
