/* Base: Mobile-first responsive styles, WCAG-friendly */
:root {
  --bg: #0b0d10;
  --text: #e6edf3;
  --muted: #94a3b8;
  --card: #0d1117;
  --border: #1f2937;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  /* Layout tokens */
  --space-1: 0.5rem; /* 8px */
  --space-2: 0.75rem; /* 12px */
  --space-3: 1rem; /* 16px */
  --space-4: 1.25rem; /* 20px */
  --radius: 0.75rem;
  --z-nav: 10;
  --z-menu: 30;
  --z-overlay: 50;
  --z-toast: 100;
  --z-floating: 1000;
}

html { box-sizing: border-box; font-size: 100%; }
*, *::before, *::after { box-sizing: inherit; }
body { margin: 0; background: linear-gradient(180deg, #0b0d10 0%, #111827 50%, #1f2937 100%); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; line-height: 1.6; }

/* Responsive typography (fluid with clamp) */
h1 { font-size: clamp(1.25rem, 1.05rem + 1.2vw, 1.85rem); margin: 0 0 1rem 0; font-weight: 600; }
h2 { font-size: clamp(1.125rem, 0.95rem + 0.9vw, 1.5rem); margin: 0 0 0.75rem 0; font-weight: 600; }
h3 { font-size: clamp(1rem, 0.9rem + 0.6vw, 1.25rem); margin: 0 0 0.5rem 0; font-weight: 600; }
p, label, input, button, a, li { font-size: clamp(0.95rem, 0.9rem + 0.3vw, 1rem); }
.muted { color: var(--muted); }

/* Containers and fluid layout */
.container { width: 100%; max-width: clamp(56rem, 88vw, 80rem); margin: 0 auto; padding: clamp(0.75rem, 1.5vw, 1.25rem); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(0.75rem, 1.5vw, 1.25rem); }
.card { box-shadow: 0 4px 12px rgba(0,0,0,0.18); transition: box-shadow 180ms ease, transform 180ms ease; }
.card:hover { box-shadow: 0 10px 22px rgba(0,0,0,0.25); }

/* Card headers and menus */
.card-header { display:flex; align-items:center; justify-content:space-between; gap: var(--space-1); margin-bottom: var(--space-2); }
.card-header .title { font-weight:700; letter-spacing:0.02em; }
.card-header .title, .panel-title { overflow-wrap: anywhere; word-break: break-word; }
.status-dot { width:8px; height:8px; border-radius:999px; background:#22c55e; box-shadow:0 0 0 4px rgba(34,197,94,0.15); }
.menu-trigger { background: transparent; border-color: var(--border); color: var(--text); padding: 0.25rem 0.5rem; min-width: 32px; min-height: 32px; }
.menu-trigger:hover { background: rgba(255,255,255,0.05); }
.contextual { position: relative; contain: paint; }
.context-menu { position: absolute; top: 8px; right: 8px; background: var(--card); border:1px solid var(--border); border-radius: 0.5rem; box-shadow: 0 8px 24px rgba(0,0,0,0.35); padding: 0.5rem; display: none; min-width: 200px; max-height: 50vh; overflow: auto; z-index: var(--z-menu); }
.context-menu button { width: 100%; text-align: left; background: transparent; }
.context-menu button:hover { background: rgba(255,255,255,0.05); }
.grid { display: grid; gap: clamp(0.75rem, 1.2vw, 1rem); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.row > * { min-width: 0; }

/* Responsive grid utilities reused across pages */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: clamp(0.75rem, 1.2vw, 1rem); align-items: start; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: clamp(0.75rem, 1.2vw, 1rem); align-items: stretch; }
.inv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }

@media (min-width: 64rem) {
  .grid-2 { grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .inv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Touch-friendly controls (≥48x48px) */
button, .btn, .nav-toggle {
  min-width: 48px; min-height: 48px;
  padding: 0.625rem 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: #1f2937; color: var(--text);
  cursor: pointer;
}
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary-dark); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--primary-dark); }
button.secondary, .btn.secondary { background: #0f172a; border-color: #334155; color: #e5e7eb; }
button.secondary:hover, .btn.secondary:hover { background: #111b2f; border-color: #3b4a66; }
button.ghost, .btn.ghost { background: transparent; }
button:focus, .btn:focus, .nav-toggle:focus { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* Inputs */
input, select, textarea {
  width: 100%; max-width: 100%;
  padding: 0.625rem 0.75rem;
  background: #0f1318; border: 1px solid var(--border); border-radius: 0.5rem;
  color: var(--text);
}
input::placeholder { color: #6b7280; }

/* Links */
a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* Flexible media */
img, video, canvas, svg { max-width: 100%; height: auto; }

/* Nav: responsive, accessible */
.nav { display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); background: #0b0d10; position: sticky; top: 0; z-index: var(--z-nav); }
.nav-title { font-size: 1rem; font-weight: 600; }
.nav-links { display: none; flex-direction: column; gap: 0.5rem; }
.nav-links a { padding: 0.5rem 0.75rem; border-radius: 0.5rem; }
.nav-toggle { background: transparent; border-color: var(--border); }
.nav[aria-expanded="true"] .nav-links { display: flex; }

/* Desktop breakpoint */
@media (min-width: 48rem) { /* 768px */
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.5rem; }
  .nav { padding: 0.75rem 2rem; }
  .nav-links { display: flex !important; flex-direction: row; align-items: center; gap: 0.75rem; }
  .nav-toggle { display: none; }
}

/* Sticky nav fallback */
@supports not (position: sticky) {
  .nav { position: fixed; width: 100%; }
  body { padding-top: 3.5rem; }
}

/* Utilities */
.center { display: grid; place-items: center; min-height: 100vh; }
.spacer-sm { margin-top: 0.5rem; }
.spacer-md { margin-top: 1rem; }
.spacer-lg { margin-top: 1.5rem; }

.hidden { display: none !important; }

/* Prevent horizontal scrolling due to accidental overflow */
body { overflow-x: hidden; }

/* High-contrast focus for accessibility */
:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* Recent visits panel */
.visits-panel { margin-top: 1rem; }
.visits-list {
  max-height: 18rem; /* ~288px */
  overflow-y: auto;
  scroll-behavior: smooth;
  border: 1px solid var(--border);
  background: #0f1318;
  padding: 0.5rem;
  border-radius: 0.5rem;
}
.visit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.visit-item:last-child { border-bottom: none; }
.visit-when { font-weight: 600; }
.visit-meta { color: var(--muted); }
.visit-item:hover { background: rgba(255,255,255,0.03); }

/* ---- Shared resource list styles (Global/Game pages) ---- */
.resources { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
@media (min-width: 48rem) {
  .resources { grid-template-columns: 1fr 1fr; }
}
.res { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: #0f1318; }
.res .name { font-weight: 600; overflow-wrap: anywhere; word-break: break-word; }
.note { color: var(--muted); font-size: 0.95rem; }

/* ---- Realms Workers UI enhancements ---- */
.panel-title { font-weight: 700; letter-spacing: 0.02em; margin-bottom: 0.5rem; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.quick-grid { grid-auto-rows: auto; }
.quick-card { background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem; padding: 1rem; box-shadow: 0 4px 12px rgba(0,0,0,0.2); transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease; }
.quick-card > div { overflow-wrap: anywhere; word-break: break-word; }
.quick-card:hover { transform: translateY(-2px); border-color: #334155; box-shadow: 0 10px 22px rgba(0,0,0,0.25); }
.quick-card.appear { animation: fadeInUp 300ms ease-out both; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.worker-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.25rem; }
.worker-title { font-weight: 600; }
.worker-meta { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.25rem; }
.pill { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.25rem 0.5rem; border-radius: 999px; background: #0f1318; border: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }

.worker-actions { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
.worker-actions .muted { font-size: 0.9rem; }
.worker-actions button.secondary { background: #0f172a; border-color: #334155; }
.worker-actions button.secondary:hover { background: #111b2f; border-color: #3b4a66; }

.chip { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.5rem; border-radius: 999px; background: #0f1318; border: 1px solid var(--border); font-size: 0.85rem; }
.bar { height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--accent) 0%, #b7f5c8 100%); transition: width 150ms ease; }

/* Toggle switches for checkboxes */
input.toggle { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; background: #111827; border: 1px solid #334155; border-radius: 999px; position: relative; outline: none; cursor: pointer; transition: background 150ms ease, border-color 150ms ease; }
input.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 999px; background: #6b7280; transition: transform 150ms ease, background 150ms ease; }
input.toggle:checked { background: #2563eb; border-color: #1d4ed8; }
input.toggle:checked::after { transform: translateX(18px); background: #fff; }

/* Action tiles with gradients */
.action-card { border-radius: 0.75rem; overflow: hidden; min-height: clamp(100px, 16vw, 140px); }
.action-card.mine { background: linear-gradient(145deg, #374151, #4b5563); }
.action-card.fish { background: linear-gradient(145deg, #6366f1, #3b82f6); }
.action-card.cut { background: linear-gradient(145deg, #22c55e, #16a34a); }
.action-card.harvest { background: linear-gradient(145deg, #f59e0b, #f97316); }
.action-card .action-top { padding: clamp(0.375rem, 0.8vw, 0.5rem) clamp(0.375rem, 0.8vw, 0.5rem); }
.action-top span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
.action-top button { flex-shrink: 0; }
.action-card .cooldown { margin: 0 clamp(0.375rem, 0.8vw, 0.5rem) clamp(0.375rem, 0.8vw, 0.5rem); background:#0b0d1e; }

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .warn-icon .pulse, .quick-card.appear { animation: none !important; }
}

/* ---- Warning icon & bubble ---- */
.warn-icon {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  display: none; /* toggled via JS */
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #f59e0b;
  color: #0b1220;
  border: 2px solid #f59e0b;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  z-index: var(--z-floating);
}
.warn-icon:hover { filter: brightness(0.95); }
.warn-icon .pulse {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  animation: warnPulse 1.6s infinite ease-out;
}
@keyframes warnPulse { to { box-shadow: 0 0 0 16px rgba(245, 158, 11, 0); } }

.warn-bubble {
  position: fixed;
  right: 64px;
  bottom: 24px;
  min-width: 240px;
  max-width: 300px;
  display: none; /* toggled via JS */
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  padding: 0.75rem 1rem;
  z-index: var(--z-floating);
}
.warn-bubble .title { font-weight: 600; margin-bottom: 0.25rem; }
.warn-bubble .muted { font-size: 0.9rem; }
.warn-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }

/* Recent drop rarity chips */
.drop { border: 1px solid var(--border); }
.drop.common { border-color: #6b7280; color: #e5e7eb; }
.drop.rare { border-color: #38BDF8; color: #dbeafe; }
.drop.epic { border-color: #a855f7; color: #ede9fe; }

/* spacing helpers for workers UI */
.mt-6 { margin-top: 6px; }
.mb-8 { margin-bottom: 8px; }
.mt-16 { margin-top: 1rem; }
.mb-16 { margin-bottom: 1rem; }
.gap-16 { gap: 1rem; }

/* Improve secondary button globally */
/* Secondary button global reinforcement */
button.secondary { background: #0f172a; border-color: #334155; color: #e5e7eb; }
button.secondary:hover { background: #111b2f; border-color: #3b4a66; }

/* ----- Desktop alternative layout ----- */
.desktop-alt-grid { display: grid; gap: 1rem; }
@media (min-width: 64rem) {
  .layout-desktop-alt .desktop-alt-grid {
    grid-template-columns: 320px 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "overview actions actions"
      "notes workers workers";
  }
  .layout-desktop-alt .area-overview { grid-area: overview; }
  .layout-desktop-alt .area-actions { grid-area: actions; }
  .layout-desktop-alt .area-notes { grid-area: notes; }
  .layout-desktop-alt .area-workers { grid-area: workers; }
}
/* ---- Tabs for Auth page ---- */
.tabs { display: grid; gap: var(--space-3); }
.tab-nav { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tab-btn { background: #0f172a; border-color: #334155; color: #e5e7eb; }
.tab-btn.active { background: var(--primary); border-color: var(--primary-dark); color: #fff; }
.tab-content { display: grid; gap: var(--space-3); }
.panel .password-wrap { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--space-2); }
.panel .password-wrap input { width: 100%; }
.panel .password-wrap .btn { min-width: 48px; }
/* Simple modal styles */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal .modal-content { background: #fff; color: #111; width: min(640px, 90vw); border-radius: 8px; padding: 16px; box-shadow: 0 6px 24px rgba(0,0,0,0.25); }
.modal .btn { margin-top: 8px; }

/* Toast notifications */
.toast-container { position: fixed; top: 16px; right: 16px; display: grid; gap: 10px; z-index: var(--z-toast); width: min(360px, 90vw); }
.toast { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 22px rgba(0,0,0,0.35); padding: 10px 12px; }
.toast.success { border-color: #16a34a; }
.toast.error { border-color: #ef4444; }
.toast.info { border-color: #3b82f6; }
.toast .icon { font-size: 18px; }
.toast .msg { overflow-wrap: anywhere; }
.toast .close { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.toast .close:focus { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* Loading states */
.btn[aria-busy="true"] { position: relative; pointer-events: none; opacity: 0.8; }
.btn[aria-busy="true"]::after { content: ''; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border: 2px solid #93c5fd; border-top-color: transparent; border-radius: 999px; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: translateY(-50%) rotate(1turn); } }