/* ── ONYX Alpha — Design System B&W Glassmorphism ── */

/* ── Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=DM+Mono:wght@500&display=swap');

/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --bg:           #f6f6f6;
  --bg-2:         #ffffff;
  --bg-3:         #eeeeee;
  --border:       rgba(0,0,0,0.08);
  --border-md:    rgba(0,0,0,0.14);
  --text:         #000000;
  --text-2:       #444444;
  --text-3:       #888888;
  --glass:        rgba(255,255,255,0.80);
  --glass-border: rgba(0,0,0,0.09);
  --shadow:       0 1px 3px rgba(0,0,0,0.06), 0 4px 20px rgba(0,0,0,0.06);
  --shadow-lg:    0 4px 40px rgba(0,0,0,0.10);
  --radius:       14px;
  --radius-sm:    8px;
  --green:        #15803d;
  --green-bg:     #f0fdf4;
  --red:          #b91c1c;
  --red-bg:       #fff1f2;
  --header-h:     56px;
  --strip-h:      52px;
  --tabs-h:       44px;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; }

/* ── Header ─────────────────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
}
.logo {
  font-size: 1.1rem; font-weight: 600; letter-spacing: -0.02em;
  white-space: nowrap; display: flex; align-items: center; gap: 8px;
}
.badge-ver {
  font-size: 0.62rem; font-weight: 500; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
  background: var(--bg-3); padding: 2px 7px; border-radius: 99px;
}
.header-nav {
  display: flex; gap: 4px; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
.header-nav::-webkit-scrollbar { display: none; }
.header-nav .nav-link {
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500; color: var(--text-2);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.header-nav .nav-link:hover { background: var(--bg-3); color: var(--text); }
.header-nav .nav-link.active { background: var(--text); color: #fff; }
.header-user {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; white-space: nowrap; margin-left: auto;
}
.username { font-weight: 600; }
.btn-logout {
  font-size: 0.8rem; color: var(--text-3);
  padding: 4px 10px; border-radius: 99px;
  border: 1px solid var(--border-md);
  transition: all 0.15s;
}
.btn-logout:hover { background: var(--text); color: #fff; border-color: var(--text); }

/* ── Resource Strip ─────────────────────────────────────────────────── */
.resource-strip {
  position: sticky; top: var(--header-h); z-index: 90;
  height: var(--strip-h);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 0;
  overflow-x: auto; scrollbar-width: none;
  padding: 0 8px;
}
.resource-strip::-webkit-scrollbar { display: none; }
.res-item {
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 100%;
  border-right: 1px solid var(--border);
  flex-shrink: 0; white-space: nowrap;
}
.res-item:last-child { border-right: none; }
.res-icon { font-size: 1rem; }
.res-val {
  font-family: 'DM Mono', monospace; font-size: 0.95rem; font-weight: 500;
  transition: color 0.3s;
}
.res-label { font-size: 0.7rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.res-credits .res-val { font-weight: 600; }

/* ── Tab Bar ────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 0;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px; overflow-x: auto; scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab {
  padding: 0 18px; height: var(--tabs-h);
  font-size: 0.875rem; font-weight: 500; color: var(--text-3);
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }

/* ── Main content ───────────────────────────────────────────────────── */
.play-main {
  flex: 1; padding: 24px 24px 80px;
  max-width: 1100px; width: 100%; margin: 0 auto;
}

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.card-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); margin-bottom: 4px; }
.card-value { font-family: 'DM Mono', monospace; font-size: 1.4rem; font-weight: 500; }
.card-sub { font-size: 0.8rem; color: var(--text-3); margin-top: 2px; }

/* ── Grid layouts ───────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.section-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }
.section-gap { margin-bottom: 28px; }

/* ── Building Cards ─────────────────────────────────────────────────── */
.building-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow 0.2s, transform 0.2s;
}
.building-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.building-name { font-weight: 600; font-size: 0.95rem; }
.building-level { font-size: 0.75rem; color: var(--text-3); }
.building-prod { font-size: 0.82rem; color: var(--text-2); }
.progress-bar-wrap { background: var(--bg-3); border-radius: 99px; height: 4px; overflow: hidden; }
.progress-bar { background: var(--text); height: 4px; border-radius: 99px; transition: width 0.6s cubic-bezier(0.4,0,0.2,1); }
.building-cost { font-size: 0.75rem; color: var(--text-3); }
.building-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 20px;
  background: var(--text); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.82; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border-md);
}
.btn-secondary:hover { background: var(--bg-3); opacity: 1; }
.btn-danger { background: var(--red); }
.btn-ghost { background: transparent; color: var(--text-3); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); opacity: 1; }

/* ── Forms ──────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 500; }
.field input, .field select {
  height: 42px; padding: 0 14px;
  background: var(--bg-3); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--text);
  background: var(--bg-2);
}
.field-hint { font-size: 0.75rem; color: var(--text-3); }
.field-opt { font-weight: 400; color: var(--text-3); }

/* ── Alerts ─────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.875rem; margin-bottom: 16px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(185,28,28,0.15); }
.alert-ok { background: var(--green-bg); color: var(--green); border: 1px solid rgba(21,128,61,0.15); }

/* ── Auth page ──────────────────────────────────────────────────────── */
.auth-main {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px 16px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.auth-logo { font-size: 2rem; font-weight: 600; letter-spacing: -0.04em; text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-3); font-size: 0.82rem; margin-bottom: 24px; }
.auth-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.auth-tab {
  flex: 1; text-align: center; padding: 10px;
  font-size: 0.875rem; font-weight: 500; color: var(--text-3);
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }

/* ── Setup Nation ───────────────────────────────────────────────────── */
.setup-card { max-width: 480px; }
.setup-title { font-size: 1.2rem; font-weight: 600; text-align: center; margin-bottom: 4px; }
.start-resources { background: var(--bg-3); border-radius: var(--radius-sm); padding: 14px; }
.start-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 10px; }
.start-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.start-res { display: flex; align-items: center; gap: 5px; font-size: 0.82rem; background: var(--bg-2); padding: 5px 10px; border-radius: 99px; border: 1px solid var(--border); }

/* ── Market Table ───────────────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3);
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-3); }
.res-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-3); border-radius: 99px;
  padding: 2px 8px; font-size: 0.75rem; font-weight: 500;
}
.own-offer td { background: rgba(0,0,0,0.025); }
.price-up { color: var(--green); }
.price-down { color: var(--red); }

/* ── Leaderboard ────────────────────────────────────────────────────── */
.rank-row td:first-child { font-family: 'DM Mono', monospace; color: var(--text-3); }
.rank-me td { font-weight: 600; background: rgba(0,0,0,0.04); }
.rank-badge {
  display: inline-block; width: 32px; height: 32px; line-height: 32px;
  text-align: center; border-radius: 50%; background: var(--text); color: #fff;
  font-size: 0.78rem; font-weight: 600;
}

/* ── Alliance / Diplomacy ───────────────────────────────────────────── */
.nation-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.nation-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.nation-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--text); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; flex-shrink: 0;
}
.nation-name { font-weight: 600; font-size: 0.95rem; }
.nation-motto { font-size: 0.78rem; color: var(--text-3); font-style: italic; }
.nation-stats { font-size: 0.78rem; color: var(--text-2); }
.alliance-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.72rem; padding: 2px 8px; border-radius: 99px;
  font-weight: 500;
}
.alliance-active { background: var(--green-bg); color: var(--green); }
.alliance-pending { background: #fefce8; color: #854d0e; }

/* ── Journal / Event log ────────────────────────────────────────────── */
.event-list { display: flex; flex-direction: column; gap: 0; }
.event-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.event-item:last-child { border-bottom: none; }
.event-time { font-size: 0.72rem; color: var(--text-3); white-space: nowrap; min-width: 90px; padding-top: 2px; }
.event-msg { font-size: 0.875rem; }
.event-world { background: var(--bg-3); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; }
.event-world-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.event-world-desc { font-size: 0.8rem; color: var(--text-2); }
.event-world-time { font-size: 0.7rem; color: var(--text-3); margin-top: 4px; }

/* ── Footer / Ticker ────────────────────────────────────────────────── */
.site-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 36px;
  background: var(--text); color: rgba(255,255,255,0.85);
  overflow: hidden; z-index: 100;
}
.ticker { display: flex; align-items: center; height: 100%; }
#ticker-text {
  font-size: 0.75rem; font-weight: 500; letter-spacing: 0.03em;
  white-space: nowrap;
  animation: ticker-scroll 30s linear infinite;
}
@keyframes ticker-scroll {
  0%   { transform: translateX(100vw); }
  100% { transform: translateX(-100%); }
}

/* ── Toast notifications ────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 52px; right: 16px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  background: var(--text); color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 3.7s forwards;
  max-width: 320px;
}
.toast.toast-ok  { background: var(--green); }
.toast.toast-err { background: var(--red); }
@keyframes toastIn  { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform:none; } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; pointer-events:none; } }

/* ── Loading state ──────────────────────────────────────────────────── */
.loading-state {
  padding: 60px; text-align: center; color: var(--text-3); font-size: 0.9rem;
}
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row .field { flex: 1; }

/* ── Admin ──────────────────────────────────────────────────────────── */
.admin-main { max-width: 1000px; margin: 0 auto; padding: 28px 24px 80px; }
.admin-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 24px; }
.admin-header h1 { font-size: 1.5rem; font-weight: 600; }
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
.stat-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-val { font-family: 'DM Mono', monospace; font-size: 1.35rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-label { font-size: 0.72rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 4px; }
.admin-section { margin-bottom: 28px; }
.admin-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.text-muted { color: var(--text-3); font-size: 0.82rem; }

/* ── Page layout ────────────────────────────────────────────────────── */
.page-main {
  flex: 1; padding: 28px 24px 80px;
  max-width: 1100px; width: 100%; margin: 0 auto;
}
.page-title { font-size: 1.4rem; font-weight: 600; letter-spacing: -0.02em; }
.page-sub { color: var(--text-3); font-style: italic; font-size: 0.9rem; margin-top: 2px; }
.page-hero {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
}
.nation-initial {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--text); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; flex-shrink: 0;
}

/* ── Building new classes ────────────────────────────────────────────── */
.building-header { display: flex; align-items: center; gap: 10px; }
.building-icon { font-size: 1.4rem; }
.building-cost-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; margin-top: 4px;
}
.building-cost { font-size: 0.75rem; color: var(--text-3); }

/* ── Market form ─────────────────────────────────────────────────────── */
.sell-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.sell-form .field { min-width: 120px; flex: 1; }
.table-card { padding: 0; overflow: auto; }
.sub-hint { font-size: 0.75rem; color: var(--text-3); font-weight: 400; }

/* ── Nation card head ────────────────────────────────────────────────── */
.nation-card-head { display: flex; align-items: center; gap: 10px; }

/* ── Empty states ────────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--text-3); padding: 28px; }
.empty-state-box {
  text-align: center; padding: 48px 24px;
  border: 1px dashed var(--border-md); border-radius: var(--radius);
  color: var(--text-2);
}

/* ── Utility classes ─────────────────────────────────────────────────── */
.mono    { font-family: 'DM Mono', monospace; }
.strong  { font-weight: 600; }
.italic  { font-style: italic; }
.btn-meta {
  font-size: 0.78rem; color: var(--text-2); padding: 4px 10px;
  border: 1px solid var(--border-md); border-radius: var(--radius-sm);
}
.btn-meta:hover { background: var(--bg-3); }

/* ── Responsive Mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .page-main   { padding: 16px 12px 108px; }
  .grid-2, .grid-3, .grid-5 { grid-template-columns: 1fr; }
  .stats-row   { grid-template-columns: repeat(2, 1fr); }
  .sell-form   { flex-direction: column; }
  .auth-card   { padding: 28px 20px; }
  .nation-cards { grid-template-columns: 1fr; }
  .data-table  { font-size: 0.78rem; }
  .data-table th, .data-table td { padding: 8px 6px; }
  .page-hero   { gap: 12px; }
  .building-cost-row { flex-direction: column; align-items: flex-start; }

  /* Bottom nav on mobile */
  .tab-bar {
    position: fixed; bottom: 36px; left: 0; right: 0; z-index: 95;
    background: var(--glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    border-bottom: none;
    height: 54px; align-items: stretch;
    gap: 0; padding: 0;
    justify-content: space-around;
  }
  .tab {
    flex: 1; height: 54px; font-size: 0.7rem; padding: 0 4px;
    border-bottom: none; border-top: 2px solid transparent;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none;
  }
  .tab.active { border-top-color: var(--text); border-bottom-color: transparent; }
}

@media (min-width: 769px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .tab { text-decoration: none; display: inline-flex; align-items: center; }
}

@media (hover: hover) {
  .card:hover          { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
  .building-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
  .nation-card:hover   { box-shadow: var(--shadow); }
}
