/* staking-v1 — self-contained per prototype principle. */

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ============ APP SHELL ============ */
.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 680px) 320px;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* ============ SIDEBAR ============ */
.sidebar { position: sticky; top: 24px; height: calc(100vh - 48px); display: flex; flex-direction: column; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 14px; font-size: 32px; font-weight: 800; margin-bottom: 36px; color: var(--text); }
.brand img { width: 42px; height: 42px; object-fit: contain; }
.sidebar nav { display: flex; flex-direction: column; gap: 8px; }
.sidebar nav a {
  padding: 14px 18px; color: var(--text-soft); border-radius: 999px; font-weight: 600; font-size: 16px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.sidebar nav a.active,
.sidebar nav a:hover { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.new-post { border-radius: 999px; background: var(--cta-bg); color: var(--cta-text); font-weight: 700; padding: 14px 22px; font-size: 16px; }

/* ============ MAIN ============ */
.main { min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 18px; min-height: 44px;
}
.topbar .back {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-soft);
  transition: background 0.15s, color 0.15s;
}
.topbar .back:hover { background: var(--surface-soft); color: var(--text); }
.topbar h1 { font-size: 28px; margin: 0; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
.topbar-brand { display: none; align-items: center; gap: 8px; color: var(--text); font-weight: 800; font-size: 22px; letter-spacing: -0.01em; }
.topbar-brand img { width: 24px; height: 24px; object-fit: contain; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.wallet-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700; font-size: 13px;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}
.wallet-chip:hover { background: var(--surface); border-color: var(--primary); transform: translateY(-1px); }
.wallet-chip .ic { display: inline-flex; align-items: center; line-height: 1; }
.wallet-chip .ic svg { display: block; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-card); }

/* ============ STAKING HERO ============ */
.staking-hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-md);
  padding: 24px;
  color: white;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.staking-hero::after {
  content: "";
  position: absolute;
  right: -90px;
  top: -90px;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,255,255,0.15), transparent);
  pointer-events: none;
}
.staking-hero .stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.staking-hero .stat .lbl {
  color: rgba(255,255,255,0.78);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin-bottom: 6px;
}
.staking-hero .stat .val {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.staking-hero .stat .val small {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.85;
  margin-left: 4px;
}
.staking-hero .stat.earned .val { color: #fde68a; }
.payout {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.18);
  font-size: 13px;
  color: rgba(255,255,255,0.78);
}
.payout b { color: white; font-weight: 800; }

/* ============ SECTION HEADER ============ */
.section-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 4px 12px;
}
.section-h h2 {
  font-size: 18px;
  font-weight: 800;
  margin: 0;
}
.section-h .count {
  color: var(--text-soft);
  font-size: 13px;
}

/* ============ POSITIONS ============ */
.positions { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.position {
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.position .pool-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 12px;
}
.position .amount {
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.position .amount small { font-size: 12px; opacity: 0.6; margin-left: 3px; }
.position .meta {
  flex: 1; min-width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.position .meta .k {
  display: block;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 10px;
  margin-bottom: 4px;
}
.position .meta .v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.position .meta .v.earned { color: var(--success); }
.position .actions {
  display: flex;
  gap: 8px;
  width: 100%;
}
.position .actions button {
  flex: 1;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  transition: background 0.15s;
}
.position .actions button:hover { background: var(--surface-soft); }
.position .actions button.withdraw {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-color: transparent;
}
.position .actions button.locked { opacity: 0.45; cursor: not-allowed; }
.position .actions button.locked:hover { background: var(--surface); }

/* ============ POOLS ============ */
.pools { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.pool {
  padding: 18px 20px;
  position: relative;
}
.pool .top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.pool h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}
.pool .apy {
  font-size: 24px;
  font-weight: 900;
  color: var(--success);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.pool .apy small {
  font-size: 11px;
  color: var(--text-soft);
  font-weight: 700;
  margin-left: 3px;
}
.pool .desc {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 12px;
}
.pool .info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border-radius: 12px;
  font-size: 12px;
  margin-bottom: 14px;
}
.pool .info .k {
  display: block;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 10px;
  margin-bottom: 3px;
}
.pool .info .v {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.pool .stake-btn {
  display: block;
  width: 100%;
  padding: 12px;
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-text);
  font-weight: 700;
  font-size: 14px;
  transition: opacity 0.15s;
}
.pool .stake-btn:hover { opacity: 0.88; }
.pool.featured {
  border-color: var(--primary);
  background: linear-gradient(180deg, var(--surface), var(--primary-soft));
}
.pool.featured::before {
  content: "創作者推薦";
  position: absolute;
  top: -10px;
  left: 20px;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.06em;
}
.pool.featured .stake-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}

/* ============ RIGHT PANEL ============ */
.right-panel { display: flex; flex-direction: column; gap: 18px; }
.right-panel .card { padding: 18px; }
.right-panel h2 { font-size: 16px; margin: 0 0 12px; font-weight: 700; }
.right-panel p { font-size: 13px; line-height: 1.6; margin: 0 0 8px; color: var(--text); }
.right-panel p:last-child { margin-bottom: 0; }

.howto { background: linear-gradient(180deg, var(--surface), var(--primary-soft)); }
.howto ol {
  padding-left: 0;
  margin: 8px 0 0;
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.howto ol li {
  counter-increment: step;
  padding-left: 28px;
  position: relative;
  font-size: 13px;
  line-height: 1.55;
}
.howto ol li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.token-card .rate {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.token-card .rate small { font-size: 12px; color: var(--text-soft); font-weight: 600; margin-left: 4px; }
.token-card .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.token-card .row:last-of-type { border-bottom: 0; }
.token-card .row .k { color: var(--text-soft); }
.token-card .row .v { font-weight: 700; font-variant-numeric: tabular-nums; }

.risk { background: rgba(245,158,11,0.06); border-color: rgba(245,158,11,0.2); }
.risk h2 { color: #b45309; display: flex; align-items: center; gap: 6px; }
.risk h2::before { content: "⚠"; font-size: 14px; }

/* ============ BACK TO TOP ============ */
.to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 50;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--text);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.32);
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
}
.to-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
@media (hover: hover) {
  .to-top:hover { background: var(--primary-dark); }
}
.to-top:active { transform: translateY(0) scale(0.94); }

/* ============ MOBILE NAV ============ */
.mobile-nav { display: none; }

/* ============ RESPONSIVE ============ */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
    padding-bottom: 96px;
    gap: 12px;
  }
  .sidebar, .right-panel { display: none; }

  .topbar {
    position: sticky; top: 0; z-index: 10;
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 12px 4px; margin: 0 0 12px;
  }
  .topbar h1 { display: none; }
  .topbar-brand { display: inline-flex; flex: 1; }

  .position .meta { grid-template-columns: 1fr 1fr; }
  .staking-hero .stat .val { font-size: 24px; }

  .mobile-nav {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow-card);
    padding: 10px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 20;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s;
  }
  .mobile-nav.nav-hidden {
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }
  .mobile-nav a { text-align: center; font-size: 12px; color: var(--text-soft); padding: 8px 4px; }
  .mobile-nav a.active { color: var(--text); font-weight: 600; }
  .mobile-nav .compose-btn {
    width: 46px; height: 46px;
    margin: auto; padding: 0;
    border-radius: 50%;
    background: var(--cta-bg); color: var(--cta-text);
    display: grid; place-items: center; line-height: 1;
  }

  .to-top {
    bottom: 88px; right: 16px; width: 42px; height: 42px;
    transition: opacity 0.2s, transform 0.2s, background 0.15s,
                bottom 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  body.nav-hidden .to-top { bottom: 28px; }
}
