:root {
  --bg: #160a0d;
  --surface: #22101a;
  --surface-2: #2d1620;
  --border: #3d1f29;
  --text: #f5e6e8;
  --muted: #b09098;
  --accent: #c0392b;
  --accent-strong: #7f1d1d;
  --buy: #ffb86b;
  --sell: #7ee29b;
  --danger: #ff8080;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbf6f6;
    --surface: #ffffff;
    --surface-2: #faf0f0;
    --border: #f0d9d9;
    --text: #2a1414;
    --muted: #876060;
    --accent: #b91c1c;
    --accent-strong: #7f1d1d;
    --buy: #c2701f;
    --sell: #1f7a44;
    --danger: #b13030;
    --shadow: 0 4px 18px rgba(70, 20, 20, 0.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text);
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}
.nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--text); }
.lang { display: inline-flex; gap: 0.4rem; }
.lang-link {
  font-size: 0.85rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.lang-link.active { background: var(--surface-2); }
.inline-form { display: inline; }
.link-button {
  background: none; border: none; color: var(--text); cursor: pointer;
  font: inherit; padding: 0;
}

.main-content { padding: 1.5rem 0 3rem; }

.hero {
  padding: 1rem 0 2rem;
}
.hero h1 { font-size: 2rem; margin: 0 0 0.5rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}
.card-soft {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 0.5rem 0;
}
.card-soft legend { padding: 0 0.4rem; }

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent-strong); }
.btn-primary:hover { background: var(--accent-strong); text-decoration: none; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.9rem; }
.btn-link { background: transparent; border: none; color: var(--accent); }

input, select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
textarea { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
label { display: block; margin-bottom: 0.75rem; }
label > span { display: block; margin-bottom: 0.25rem; font-size: 0.9rem; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.checkbox input { width: auto; }
.checkbox span { margin-bottom: 0; }

.stack > * + * { margin-top: 0.6rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.flashes { margin-bottom: 1rem; }
.flash {
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 0.5rem;
}
.flash-error { border-color: var(--danger); }
.flash-success { border-color: var(--sell); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}
.badge-buy { color: var(--buy); border-color: var(--buy); }
.badge-sell { color: var(--sell); border-color: var(--sell); }

.event-list, .lgs-list, .result-list { list-style: none; padding: 0; margin: 0; }
.event { display: grid; grid-template-columns: 140px 1fr; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.event:last-child { border-bottom: none; }
.event-when { color: var(--muted); font-variant-numeric: tabular-nums; }
.event-title { font-weight: 600; }
.event-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.lgs-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.lgs-item:last-child { border-bottom: none; }
.lgs-name { font-weight: 600; color: var(--text); }

.result { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: none; }
.result-title { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.card-preview { columns: 2; column-gap: 1.5rem; list-style: none; padding: 0; }
@media (max-width: 600px) { .card-preview { columns: 1; } }
.card-preview li { break-inside: avoid; padding: 0.1rem 0; }
.qty { color: var(--muted); margin-right: 0.3rem; font-variant-numeric: tabular-nums; }

.card-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.8rem;
}
.card-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
}
.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-image-qty {
  position: absolute;
  top: 0.3rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.card-image-fallback {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.6rem 0.4rem 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.8rem;
}
.card-image-qty-static { position: absolute; }
.card-image-name { word-break: break-word; }

.ig-section { }
.ig-handle {
  color: var(--accent);
  border-color: var(--accent);
  text-decoration: none;
}
.ig-handle:hover { background: var(--accent); color: white; text-decoration: none; }

.ig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}
@media (max-width: 480px) {
  .ig-grid { grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
}

.ig-item {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  color: white;
}
.ig-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.ig-item:hover img { transform: scale(1.05); }

.ig-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.ig-item:hover .ig-overlay { opacity: 1; }

.ig-icon { width: 2rem; height: 2rem; color: white; }

.footer { margin-top: 3rem; padding: 1.5rem 0; border-top: 1px solid var(--border); }

.auth-form { max-width: 380px; margin: 1.5rem auto; }

.notes { white-space: pre-wrap; background: var(--surface-2); padding: 0.75rem; border-radius: 8px; margin: 0.75rem 0; }
.preview { margin-top: 0.5rem; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: white; }

.card-edit-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.card-edit-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.card-edit-row:last-child { border-bottom: none; }
.card-edit-name { flex: 1 1 12rem; min-width: 0; word-break: break-word; }
.card-edit-actions { display: flex; gap: 0.4rem; align-items: center; margin: 0; }
.card-edit-qty { margin: 0; }
.card-edit-qty input { width: 5rem; padding: 0.35rem 0.5rem; }

.card-add-form { margin-top: 0.5rem; }
.card-add-form h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.card-add-grid {
  display: grid;
  grid-template-columns: 1fr 6rem auto;
  gap: 0.6rem;
  align-items: end;
}
.card-add-grid label { margin: 0; }
.card-add-submit { display: flex; align-items: end; }
@media (max-width: 600px) {
  .card-add-grid { grid-template-columns: 1fr; }
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.nav-admin {
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
}
.nav-admin:hover { background: var(--accent); color: white; text-decoration: none; }

.admin-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}
.admin-tab {
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  font-size: 0.92rem;
}
.admin-tab:hover { border-color: var(--accent); text-decoration: none; }
.admin-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent-strong);
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.admin-stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.admin-stat:hover { border-color: var(--accent); text-decoration: none; }
.admin-stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.admin-stat-label { font-size: 0.95rem; }
.admin-stat-sub { font-size: 0.8rem; }

.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.admin-table th, .admin-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.admin-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table .nowrap { white-space: nowrap; }
.admin-table .small { font-size: 0.8rem; }
.admin-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}
.admin-actions-col { width: 1%; white-space: nowrap; }
.admin-inline-form summary { list-style: none; cursor: pointer; }
.admin-inline-form summary::-webkit-details-marker { display: none; }
