:root {
  --bg-top: #2a0a10;
  --bg-bottom: #120306;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.09);
  --accent: #e0304a;
  --accent-2: #ff5f6d;
  --accent-dark: #7a1522;
  --text: #f5e9ea;
  --text-dim: #c9a4a9;
  --danger: #ff4d4d;
  --success: #3ecf7e;
  --radius: 999px;
  --radius-card: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 50% -10%, #4a1420 0%, var(--bg-top) 35%, var(--bg-bottom) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

/* --- Splash --------------------------------------------------------- */

#splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 30%, #4a1420 0%, var(--bg-top) 45%, var(--bg-bottom) 100%);
  z-index: 100;
  transition: opacity 0.5s ease;
}

#splash.fade-out { opacity: 0; pointer-events: none; }

.splash-logo {
  width: 132px;
  height: 132px;
  object-fit: cover;
  border-radius: 28px;
  animation: splash-pop 900ms cubic-bezier(.2, .9, .3, 1.3) both, splash-float 3.2s ease-in-out 900ms infinite;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 26px rgba(255, 90, 100, 0.45));
}

@keyframes splash-pop {
  0% { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes splash-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.splash-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
}

.splash-by {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.splash-claude {
  position: absolute;
  bottom: 28px;
  font-size: 11px;
  color: rgba(201, 164, 169, 0.7);
  letter-spacing: 0.4px;
}

/* --- Top bar / header ------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 8px;
}

.app-logo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 10px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
  flex-shrink: 0;
}

.app-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-title {
  font-size: 16px;
  font-weight: 700;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- Screens ------------------------------------------------------------ */

.screen {
  flex: 1;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Tiles (main menu) --------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 6px;
}

.tile {
  background: linear-gradient(155deg, rgba(255,255,255,0.09), rgba(255,255,255,0.02)), var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  min-height: 100px;
  position: relative;
  overflow: hidden;
}

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

.tile .tile-icon { font-size: 26px; }
.tile .tile-label { font-size: 14px; font-weight: 600; line-height: 1.25; }
.tile .tile-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 2px 8px;
  min-width: 20px;
  text-align: center;
}

.tile.wide { grid-column: span 2; flex-direction: row; align-items: center; }
.tile.wide .tile-icon { font-size: 22px; }

.tile.shift-on { border-color: rgba(62, 207, 126, 0.5); }
.tile.shift-off { border-color: rgba(255, 77, 77, 0.4); }

/* --- Pill buttons --------------------------------------------------------- */

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 6px 16px rgba(224, 48, 74, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
}

.btn:active { transform: scale(0.97); }
.btn.secondary {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: none;
  color: var(--text);
}
.btn.block { width: 100%; }
.btn.small { padding: 9px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; }

/* --- Cards / lists --------------------------------------------------------- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.list-btn {
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  color: var(--text);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

.list-btn.lead { border-color: var(--accent); }

.list-btn .row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.list-btn .name { font-weight: 700; font-size: 14px; }
.list-btn .preview {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-btn .unread-dot {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px 12px;
}

/* --- Chat detail --------------------------------------------------------- */

.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.35;
}

.msg.in {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
}

.msg.out {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-bottom-right-radius: 4px;
}

.reply-bar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-top: 6px;
}

.reply-bar textarea {
  flex: 1;
  resize: none;
  border-radius: 18px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  max-height: 100px;
}

.reply-bar textarea:focus { outline: none; border-color: var(--accent); }

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}

.chat-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Toggle switch (points / shift) --------------------------------------- */

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { display: none; }

.switch .track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  transition: background 0.2s;
}

.switch .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

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

/* --- Toast ------------------------------------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 4, 8, 0.95);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 200;
  max-width: 85vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Loader --------------------------------------------------------------- */

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Section title ------------------------------------------------------ */

.section-title {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 6px 2px 0;
}

/* --- Form fields ---------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label { font-size: 12.5px; color: var(--text-dim); }

.field input, .field textarea {
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
}

.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }

.barcode-img {
  width: 100%;
  border-radius: 14px;
  background: #fff;
  padding: 10px;
}

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--card-border);
}

.leaderboard-row.me { color: var(--accent-2); font-weight: 700; }
.leaderboard-row:last-child { border-bottom: none; }
