:root {
  --bg: #101214;
  --panel: #171b1d;
  --panel-2: #202629;
  --text: #f5f2e8;
  --muted: #a7afa9;
  --line: #30383b;
  --accent: #6de3c6;
  --gold: #f6d365;
  --danger: #ff6b6b;
  --shadow: 0 18px 60px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(109, 227, 198, .08), transparent 32%),
    radial-gradient(circle at 70% 10%, rgba(246, 211, 101, .1), transparent 24%),
    var(--bg);
  font-family: "Yu Gothic UI", "Meiryo", sans-serif;
}
button, input, select {
  font: inherit;
  color: inherit;
}
button, select, input {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
}
button {
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.danger { background: #3b1e20; border-color: #733235; color: #ffdada; }
button.danger-lite { background: #2a2720; border-color: #6b5b24; color: #fff0b8; }
.hidden { display: none !important; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(16, 18, 20, .9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
h1 { margin: 0; font-size: 20px; }
.view-tabs { display: flex; gap: 6px; }
.tab.active { border-color: var(--accent); color: var(--accent); }
.filters {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 8px;
  padding: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
}
.filters select, .filters input { min-height: 42px; padding: 0 10px; width: 100%; }
.review-view {
  max-width: 820px;
  margin: 0 auto;
  padding: 4px 12px 18px;
}
#swipeCard,
#reviewImage {
  touch-action: none;
}
.mode-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 8px;
}
.mode-toggle button {
  min-height: 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}
.mode-toggle button.active {
  background: var(--accent);
  color: #07110f;
  font-weight: 800;
}
.counter { color: var(--muted); font-size: 13px; }
.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.review-head .mode-toggle { margin-bottom: 0; }
.swipe-card {
  position: relative;
  display: grid;
  place-items: center;
  height: min(62vh, 650px);
  min-height: 320px;
  overflow: hidden;
  background: #0b0d0e;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  touch-action: none;
}
.swipe-card img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center;
  touch-action: none;
}
.action-row.review-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
}
.review-actions button {
  min-height: 58px;
  padding: 0 6px;
  font-weight: 800;
}
.review-actions #adoptBtn,
.review-actions #trashBtn {
  flex: 1 1 0;
  min-width: 0;
}
#prevBtn,
#nextBtn {
  flex: 0 0 46px;
  font-size: 1.6rem;
  background: #182022;
  border-color: #344043;
  color: var(--text);
}
.view-only-mode .review-actions #prevBtn,
.view-only-mode .review-actions #nextBtn {
  flex: 1 1 0;
}
#adoptBtn {
  background: #17332d;
  border-color: #2a7969;
  color: #baffef;
}
.view-only-mode #adoptBtn,
.view-only-mode #tagBtn,
.view-only-mode #trashBtn,
.view-only-mode #starButtons,
.view-only-mode #undoBtn,
.view-only-mode #reviewTagEditor {
  display: none;
}
.gesture-label {
  position: absolute;
  display: none;
  top: 14px;
  left: 14px;
  z-index: 2;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-weight: 800;
  opacity: 0;
}
.meta-line { min-height: 28px; color: var(--muted); font-size: 13px; padding: 8px 2px; overflow-wrap: anywhere; }
.meta-bottom {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: #5d686b;
  max-height: 4.6em;
  overflow-y: auto;
}
.action-row {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.star-row { grid-template-columns: repeat(5, 1fr); }
.star-row button.active { background: #4a3a13; border-color: var(--gold); color: var(--gold); }
.review-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.review-footer #undoBtn { flex: 1 1 0; }
.review-footer #trashBtn { flex: 1 1 0; }
.review-footer #tagBtn {
  margin-left: auto;
  min-height: 36px;
  padding: 0 12px;
  color: var(--muted);
}
.tag-editor {
  margin-top: 10px;
  padding: 10px;
  background: rgba(23, 27, 29, .92);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tag-editor.collapsed { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; max-height: 78px; overflow: auto; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #263235;
  color: #e8fffa;
  font-size: 12px;
}
.chip button { min-height: 20px; padding: 0 4px; border: 0; background: transparent; }
.tag-input-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.tag-input-row input { min-height: 38px; padding: 0 10px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.suggestions button { min-height: 30px; padding: 0 9px; font-size: 12px; color: var(--muted); }
.grid-view { padding: 0 12px 20px; }
.bulkbar {
  position: sticky;
  top: 68px;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr repeat(4, auto);
  gap: 6px;
  align-items: center;
  padding: 8px 0;
  background: rgba(16, 18, 20, .92);
}
.bulkbar span { color: var(--muted); font-size: 13px; }
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--panel);
}
.tile.selected { border-color: var(--accent); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute;
  left: 5px;
  bottom: 5px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: var(--gold);
  font-size: 11px;
}
.load-more { width: 100%; margin: 12px 0; }
.detail-dialog {
  width: min(760px, calc(100vw - 18px));
  max-height: 92vh;
  padding: 10px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.detail-dialog::backdrop { background: rgba(0, 0, 0, .72); }
.detail-dialog form {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.detail-dialog img { width: 100%; max-height: 56vh; object-fit: contain; background: #0b0d0e; border-radius: 8px; touch-action: none; transform-origin: center; }
#reviewFromHereBtn { min-height: 32px; }
.close { float: right; min-height: 32px; width: 32px; padding: 0; }
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #fff7d6;
  color: #161514;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.toast button { color: #161514; background: #f6d365; border-color: #d7ad39; }
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}
.login-shell { width: min(420px, 100%); }
.login-panel {
  padding: 24px;
  background: rgba(23, 27, 29, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-form { display: grid; gap: 14px; margin-top: 22px; }
.login-form label { display: grid; gap: 6px; color: var(--muted); }
.login-form input { min-height: 44px; padding: 0 12px; color: var(--text); }
.login-form button { background: var(--accent); color: #07110f; border: 0; font-weight: 800; }
.form-error { min-height: 20px; margin: 0; color: #ffb3b3; }

@media (min-width: 760px) {
  main { width: min(1180px, 100%); margin: 0 auto; }
  .filters { grid-template-columns: 1.2fr .7fr .8fr 1fr; }
  .grid { grid-template-columns: repeat(6, 1fr); }
}
