* {
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0c;
  --bg-elevated: #141417;
  --bg-card: #18181c;
  --border: #232327;
  --text: #f2f2f4;
  --text-dim: #9a9aa2;
  --text-faint: #5c5c64;
  --accent: #e8e8ec;
  --danger: #ff6b6b;
  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --safe-top: calc(env(safe-area-inset-top, 0px) + 56px + var(--tg-safe-top, 0px));
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-safe-bottom, 0px));
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* our own scroll container, so iOS rubber-band overscroll never reveals
   content above the fixed top bar (fullscreen mini apps have no OS chrome
   to anchor against, so native body bounce looked broken there) */
#app {
  height: 100%;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 16px;
  padding-top: calc(var(--top-bar-height, 0px) + 16px);
  padding-bottom: calc(48px + var(--safe-bottom));
  transition: filter 0.25s var(--ease);
}

#app.privacy-blur {
  filter: blur(24px);
}

/* screenshots/recording can't be blocked from web content — this only
   deters casual long-press-save and hides content in the app switcher */
img {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* truly fixed to the viewport — not sticky — so it never shifts or
   ghosts during scroll/bounce, regardless of WebKit quirks. #app's
   padding-top (set from JS, see app.js) reserves exactly its height. */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  z-index: 20;
  padding: calc(var(--safe-top)) 16px 10px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 2px 16px;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.header p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.tabs-wrap {
  padding-bottom: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 8px;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.25s var(--ease), color 0.25s var(--ease), border-color 0.25s var(--ease);
}

.tab:active {
  transform: scale(0.97);
}

.tab.active {
  background: var(--accent);
  color: #0a0a0c;
  border-color: var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 4px;
}

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s var(--ease), border-color 0.35s var(--ease);
  animation: rise 0.5s var(--ease) backwards;
}

.card:active {
  transform: scale(0.97);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 12px;
  overflow: hidden;
}

.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

.card-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-flavor {
  font-size: 12px;
  color: var(--text-dim);
}

.card-mg {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.card-price {
  margin-top: auto;
  padding-top: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.cat-group {
  margin-bottom: 28px;
}

.cat-heading {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}

.cat-heading-1 {
  font-size: 17px;
  padding-top: 4px;
}

.cat-heading-2 {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 16px;
}

.cat-heading-3 {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 64px 16px;
  font-size: 14px;
}

/* --- admin --- */

.admin-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.admin-form input[type="text"],
.admin-form input[type="number"],
.admin-form textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.25s var(--ease);
  width: 100%;
}

.admin-form input:focus,
.admin-form textarea:focus {
  border-color: var(--text-dim);
}

.admin-form textarea {
  resize: vertical;
  min-height: 60px;
}

.admin-form label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row {
  display: flex;
  gap: 10px;
}

.row > * {
  flex: 1;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.25s var(--ease), transform 0.15s var(--ease);
  background: var(--accent);
  color: #0a0a0c;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.3);
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  transition: opacity 0.3s var(--ease);
}

.admin-item.out-of-stock {
  opacity: 0.5;
}

.admin-item-photo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  overflow: hidden;
  flex-shrink: 0;
}

.admin-item-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-item-info {
  flex: 1;
  min-width: 0;
}

.admin-item-name {
  font-size: 14px;
  font-weight: 500;
}

.admin-item-price {
  font-size: 12px;
  color: var(--text-dim);
}

.admin-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch {
  position: relative;
  width: 40px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.3s var(--ease);
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-faint);
  border-radius: 50%;
  transition: transform 0.3s var(--ease), background 0.3s var(--ease);
}

.switch input:checked + .switch-track {
  background: rgba(232, 232, 236, 0.2);
}

.switch input:checked + .switch-track::before {
  transform: translateX(16px);
  background: var(--accent);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.2s var(--ease);
}

.icon-btn:hover {
  color: var(--danger);
}
