/* ==========================================================================
   Design System & Modern CSS Variables
   ========================================================================== */
:root {
  --primary: #fb6a02;
  --primary-glow: rgba(251, 106, 2, 0.45);
  --primary-dark: #e05400;
  --primary-light: #ff8533;
  --accent-yellow: #ffb703;
  
  --bg-dark: #0b0d14;
  --bg-surface: #141824;
  --bg-surface-elevated: #1e2436;
  --bg-glass: rgba(20, 24, 36, 0.75);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(251, 106, 2, 0.4);
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --shadow-glow: 0 0 35px var(--primary-glow);
  --shadow-elevation: 0 12px 30px -10px rgba(0, 0, 0, 0.6);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition-fast: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-smooth: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light mode support if user browser prefers */
@media (prefers-color-scheme: light) {
  :root {
    --bg-dark: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --text-main: #0f172a;
    --text-muted: #475569;
    --text-dim: #94a3b8;
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-active: rgba(251, 106, 2, 0.5);
    --shadow-elevation: 0 12px 30px -10px rgba(0, 0, 0, 0.12);
  }
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Background Ambient Lights */
body::before {
  content: '';
  position: fixed;
  top: -15%;
  left: 50%;
  transform: translateX(-50%);
  width: 650px;
  height: 650px;
  background: radial-gradient(circle, var(--primary-glow) 0%, rgba(251, 106, 2, 0) 70%);
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.7;
}

/* ==========================================================================
   Layout Containers
   ========================================================================== */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

/* Top Navbar / Header */
.navbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
}

.logo-badge {
  background: linear-gradient(135deg, var(--primary), var(--accent-yellow));
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.region-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.region-select {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 30px 8px 12px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  min-width: 140px;
  transition: all var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.region-select:hover, .region-select:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.region-select option {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
}

.history-toggle-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.history-toggle-btn:hover {
  border-color: var(--border-active);
  background: var(--bg-surface);
  transform: translateY(-1px);
}

.badge-count {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.share-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.share-btn:hover {
  border-color: var(--border-active);
  background: var(--bg-surface);
  transform: translateY(-1px);
}

.share-btn.copied {
  border-color: #10b981;
  color: #10b981;
}

.toast-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-active);
  color: var(--text-main);
  padding: 10px 22px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-elevation);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

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

/* ==========================================================================
   Hero & Roll Section
   ========================================================================== */
.hero-section {
  text-align: center;
  margin: 24px auto auto auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.tagline-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.tagline-chip .dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
}

.hero-title {
  font-size: clamp(32px, 6vw, 56px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -1.5px;
  max-width: 680px;
}

.hero-title .gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--accent-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: clamp(15px, 2.5vw, 18px);
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto;
}

/* Category Pills */
.category-pills {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 650px;
  margin: 0 auto;
  min-height: 80px;
}

.pill-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.pill-btn:hover {
  color: var(--text-main);
  border-color: var(--border-active);
  background: var(--bg-surface-elevated);
}

.pill-btn.active {
  background: linear-gradient(135deg, rgba(251, 106, 2, 0.25), rgba(255, 183, 3, 0.2));
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 0 14px var(--primary-glow);
}

/* Big Surprise Me Button */
.roll-cta-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.roll-button {
  position: relative;
  background: linear-gradient(135deg, var(--primary) 0%, #d84315 100%);
  color: #ffffff;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: clamp(18px, 3.5vw, 24px);
  font-weight: 800;
  line-height: 1;
  padding: 20px 48px;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 0 10px 30px var(--primary-glow), 0 2px 4px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 14px;
  letter-spacing: -0.5px;
  transform: translateZ(0);
  will-change: transform, box-shadow;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), filter var(--transition-fast);
  user-select: none;
}

.roll-button:hover {
  transform: translateY(-3px) translateZ(0);
  box-shadow: 0 15px 40px var(--primary-glow), 0 4px 8px rgba(0, 0, 0, 0.4);
  filter: brightness(1.08);
}

.roll-button:active {
  transform: translateY(1px) translateZ(0);
  box-shadow: 0 5px 15px var(--primary-glow);
}

.roll-button:focus-visible {
  outline: 3px solid var(--accent-yellow);
  outline-offset: 4px;
}

.btn-icon {
  display: inline-block;
  font-size: 28px;
  line-height: 1;
  transform: translateZ(0);
  transform-origin: center center;
  will-change: transform;
  pointer-events: none;
  backface-visibility: hidden;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.roll-button:hover .btn-icon {
  transform: rotate(20deg) scale(1.15) translateZ(0);
}

.btn-text {
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

/* Rolling & Loading animation state */
.roll-button.loading {
  cursor: wait !important;
  opacity: 0.9;
  filter: brightness(1.08);
  box-shadow: 0 0 25px var(--primary-glow);
  pointer-events: none;
}

.roll-button.rolling .btn-icon,
.roll-button.loading .btn-icon {
  animation: spin 0.5s infinite linear;
}

.roll-button:disabled:not(.loading) {
  cursor: not-allowed;
  opacity: 0.7;
}

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

.shortcut-hint {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.kbd-badge {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Last Discovered Card (Toast / Teaser)
   ========================================================================== */
.last-roll-card {
  width: 100%;
  max-width: 540px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-elevation);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

.last-roll-card.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.last-roll-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  overflow: hidden;
  flex: 1;
}

.last-roll-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.last-roll-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  color: var(--primary);
}

.shipping-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.shipping-badge.local {
  background: rgba(251, 106, 2, 0.15);
  color: #ff9d42;
  border: 1px solid rgba(251, 106, 2, 0.3);
}

.shipping-badge.global {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.last-roll-warning {
  font-size: 11px;
  color: #fbbf24;
  margin-top: 2px;
  line-height: 1.3;
}

.last-roll-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.last-roll-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.report-soldout-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-dim);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.report-soldout-btn:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
  color: #ef4444;
}

.report-soldout-btn.reported {
  background: rgba(16, 185, 129, 0.12);
  border-color: #10b981;
  color: #10b981;
  cursor: default;
}

.report-soldout-btn.still-available {
  background: rgba(59, 130, 246, 0.12);
  border-color: #3b82f6;
  color: #60a5fa;
  cursor: default;
}

.reopen-link {
  background: linear-gradient(135deg, #fb6a02, #f59e0b);
  border: 1px solid rgba(251, 106, 2, 0.5);
  color: #ffffff !important;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(251, 106, 2, 0.3);
  transition: all var(--transition-fast);
}

.reopen-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(251, 106, 2, 0.45);
}

.reopen-link:active {
  transform: translateY(0);
}

.pill-count {
  font-size: 11px;
  opacity: 0.65;
  margin-left: 4px;
}

/* ==========================================================================
   Stats Bar
   ========================================================================== */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-val {
  font-weight: 700;
  color: var(--text-main);
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.5; }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  width: 100%;
  margin-top: 40px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer a:hover {
  color: var(--primary);
}

/* ==========================================================================
   Recently Discovered Drawer / Modal
   ========================================================================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  z-index: 101;
  transform: translateX(100%);
  transition: transform var(--transition-smooth);
  display: flex;
  flex-direction: column;
}

.drawer-backdrop.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.close-drawer-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.close-drawer-btn:hover {
  color: var(--text-main);
  background: var(--bg-surface-elevated);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-history {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.history-item {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: var(--text-main);
  transition: all var(--transition-fast);
}

.history-item:hover {
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
}

.history-wh-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  margin-left: 6px;
  vertical-align: middle;
}

.history-wh-badge.local {
  background: rgba(251, 106, 2, 0.2);
  color: #ff9d42;
}

.history-wh-badge.global {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
}

.history-item-time {
  color: var(--text-dim);
  font-size: 11px;
}

.history-item-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.clear-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.clear-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

/* ==========================================================================
   Import URLs Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevation);
  width: 90%;
  max-width: 540px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-textarea {
  width: 100%;
  height: 130px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 12px;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

.modal-textarea:focus {
  outline: 1px solid var(--primary);
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
}

.btn-primary {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.modal-status {
  font-size: 13px;
  font-weight: 600;
  color: #10b981;
}

/* ==========================================================================
   Mobile Optimization
   ========================================================================== */
@media (max-width: 600px) {
  .hero-section {
    gap: 20px;
  }
  .navbar {
    flex-wrap: wrap;
    gap: 10px;
  }
  .nav-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .last-roll-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .last-roll-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .reopen-link {
    flex: 1;
    text-align: center;
    justify-content: center;
    padding: 10px 14px;
  }
  .roll-button {
    width: 100%;
    justify-content: center;
    padding: 18px 24px;
  }
  .drawer-panel {
    max-width: 100%;
  }
}
