:root {
  --bg: #091629;
  --bg2: #0f2742;
  --panel: rgba(13, 27, 47, 0.9);
  --panel-soft: rgba(23, 44, 72, 0.9);
  --line: #2a4468;
  --text: #e7f0ff;
  --muted: #91a7ca;
  --good: #31dba7;
  --bad: #ff6f7d;
  --accent: #5cb6ff;
  --phase-glow: rgba(100, 176, 255, 0.22);
  --phase-glow-2: rgba(67, 212, 170, 0.14);
  --phase-rim: #57b7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Bahnschrift", "DIN Alternate", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 8% 10%, var(--phase-glow) 0%, transparent 40%),
    radial-gradient(circle at 86% 4%, var(--phase-glow-2) 0%, transparent 36%),
    linear-gradient(135deg, var(--bg2), var(--bg) 46%, #071221 100%);
  color: var(--text);
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -20%;
  pointer-events: none;
  z-index: -1;
}

body::before {
  background:
    conic-gradient(from 120deg, rgba(92, 182, 255, 0), rgba(92, 182, 255, 0.1), rgba(92, 182, 255, 0)),
    radial-gradient(circle at 30% 25%, rgba(122, 184, 255, 0.16), transparent 44%);
  filter: blur(28px);
  animation: float-field 18s linear infinite;
}

body::after {
  background-image: url("/assets/grain.svg");
  background-repeat: repeat;
  background-size: 280px 280px;
  opacity: 0.02;
  mix-blend-mode: screen;
}

body[data-phase="countdown"] {
  --accent: #ffbf4a;
  --phase-glow: rgba(255, 198, 102, 0.28);
  --phase-glow-2: rgba(255, 146, 92, 0.18);
  --phase-rim: #ffc667;
}

body[data-phase="running"] {
  --accent: #4dd4ff;
  --phase-glow: rgba(92, 182, 255, 0.22);
  --phase-glow-2: rgba(67, 212, 170, 0.14);
  --phase-rim: #63d6ff;
}

body[data-phase="ended"] {
  --accent: #68f7c3;
  --phase-glow: rgba(88, 245, 194, 0.18);
  --phase-glow-2: rgba(132, 198, 255, 0.18);
  --phase-rim: #71f0c7;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
}

.join-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.join-card {
  width: min(480px, 100%);
  background: rgba(17, 31, 53, 0.95);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin: 0 auto;
}

.join-card h1 {
  margin: 0 0 8px;
}

.join-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

#join-form {
  display: grid;
  gap: 12px;
}

#join-form label {
  display: grid;
  gap: 6px;
  color: #cde0ff;
  font-size: 14px;
}

#join-form input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: #0a1729;
  color: var(--text);
  font-size: 16px;
}

#join-form button,
.trade-actions button,
.offer-actions button,
.contract-actions button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #081324;
  font-weight: 700;
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.2s ease;
}

#join-form button:hover,
.trade-actions button:hover,
.offer-actions button:hover,
.contract-actions button:hover {
  filter: brightness(1.08);
}

#join-form button:active,
.trade-actions button:active,
.offer-actions button:active,
.contract-actions button:active {
  transform: scale(0.98);
}

.trade-actions button.action-fired,
.offer-actions button.action-fired,
.contract-actions button.action-fired {
  box-shadow: 0 0 0 4px rgba(124, 206, 255, 0.18);
  transform: translateY(-1px);
}

.error {
  margin-top: 8px;
  color: var(--bad);
  min-height: 18px;
}

.join-version {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.join-author {
  margin-top: 6px;
  text-align: center;
  color: #c7dcff;
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 19, 36, 0.82);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(6px);
}

.topbar-main,
.topbar-timers,
.topbar-wallet {
  min-width: 0;
}

.event-ticker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 22, 40, 0.9);
}

.event-ticker-label {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: #9cc4ff;
}

.event-marquee {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 12px;
  color: #d9e8ff;
}

.event-marquee-track {
  display: inline-flex;
  align-items: center;
  min-width: max-content;
  will-change: transform;
  animation: marquee-scroll var(--marquee-duration, 60s) linear infinite;
}

.event-marquee-item {
  display: inline-block;
  padding-right: 48px;
}

.title-line {
  font-size: 18px;
  font-weight: 700;
}

.meta,
.timers,
.wallet {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

#cash-text,
#asset-text {
  transition: color 0.2s ease, text-shadow 0.25s ease;
}

#cash-text.value-up,
#asset-text.value-up {
  color: #8bf1ca;
  text-shadow: 0 0 14px rgba(88, 245, 191, 0.4);
}

#cash-text.value-down,
#asset-text.value-down {
  color: #ff9da8;
  text-shadow: 0 0 12px rgba(255, 135, 150, 0.35);
}

.top-holdings {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.holding-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0d1b30;
  color: #b6c9e8;
  padding: 2px 7px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mini-icon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  object-fit: cover;
  flex: 0 0 auto;
}

.commodity-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.holding-chip strong {
  color: #e8f1ff;
  font-size: 11px;
}

.holding-chip.hot {
  border-color: #3b5f8f;
  background: #122744;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  gap: 10px;
  padding: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 76vh;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 34px rgba(3, 10, 22, 0.45), inset 0 1px 0 rgba(144, 188, 255, 0.08);
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.market-list {
  display: grid;
  gap: 8px;
}

.commodity-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--panel-soft);
  cursor: pointer;
}

.commodity-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 48%, transparent), 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.commodity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 6px;
}

.price-up {
  color: var(--good);
}

.price-down {
  color: var(--bad);
}

.spark {
  width: 100%;
  height: 48px;
  border-radius: 6px;
  background: #091628;
}

#big-chart {
  width: 100%;
  height: 220px;
  background: #091628;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.selected-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.trade-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.buy-btn {
  background: #3ed0a4 !important;
}

.sell-btn {
  background: #ff7e86 !important;
}

.help-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.avg-cost-text {
  margin-top: 8px;
  font-size: 12px;
  color: #c7dcff;
}

.contracts-inline-wrap {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.contracts-inline-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.contract-inline-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d1b30;
  padding: 8px;
  font-size: 12px;
}

.contracts-side-section {
  display: none;
}

.inventory-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #0d1b30;
  margin-bottom: 8px;
}

.inventory-grid-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.inventory-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  max-height: none;
  overflow: auto;
  padding-right: 0;
  margin-bottom: 8px;
}

.inventory-cell {
  border: 1px solid var(--line);
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: #0d1b30;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d8e8ff;
  font-size: 12px;
}

.inventory-cell.empty {
  color: #617a9d;
}

.panel-block {
  margin-bottom: 10px;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 3px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #0d1b30;
  font-size: 12px;
}

.item .main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.detail-line {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.offer-actions,
.contract-actions {
  display: flex;
  gap: 6px;
}

.offer-actions button,
.contract-actions button {
  padding: 6px 8px;
  font-size: 12px;
}

.profit-good {
  margin-top: 6px;
  color: #55e3b3;
  font-weight: 700;
}

.profit-bad {
  margin-top: 6px;
  color: #ff8a93;
  font-weight: 700;
}

.mobile-tabs {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(17, 31, 53, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}

.broadcast-feed {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 620px);
  display: grid;
  gap: 8px;
  z-index: 135;
  pointer-events: none;
}

.broadcast-card {
  border: 1px solid rgba(93, 204, 255, 0.72);
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(16, 46, 74, 0.95), rgba(14, 32, 53, 0.95));
  color: #eaf4ff;
  padding: 9px 12px;
  box-shadow: 0 10px 26px rgba(2, 9, 18, 0.55), 0 0 0 1px rgba(110, 201, 255, 0.1) inset;
  display: grid;
  gap: 3px;
  animation: broadcast-slide-in 240ms ease-out;
}

.broadcast-card .head {
  font-size: 11px;
  color: #9fd8ff;
  letter-spacing: 0.03em;
}

.broadcast-card .body {
  font-size: 13px;
  font-weight: 700;
}

.broadcast-card.fade-out {
  animation: broadcast-fade-out 260ms ease-in forwards;
}

.cash-fly {
  position: fixed;
  z-index: 140;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(15, 38, 62, 0.9);
  border: 1px solid #2f5e90;
  color: #bde0ff;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: transform 0.85s cubic-bezier(0.2, 0.8, 0.18, 1), opacity 0.85s ease;
}

.cash-fly.up {
  color: #90f0cb;
  border-color: #3ca180;
}

.cash-fly.down {
  color: #ffadb5;
  border-color: #ac5762;
}

.cash-fly.run {
  opacity: 1;
  transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(0.94);
}

.audio-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 120;
  border: 1px solid #2d4d76;
  border-radius: 999px;
  background: rgba(9, 24, 44, 0.92);
  color: #d9e9ff;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
}

.audio-toggle:hover {
  filter: brightness(1.08);
}

.audio-toggle.muted {
  color: #90a7c7;
  border-color: #2a3d5a;
}

.summary-view {
  position: relative;
  min-height: calc(100vh - 12px);
  padding: 26px 14px 20px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(78, 205, 255, 0.18), transparent 42%),
    radial-gradient(circle at 85% 0%, rgba(66, 255, 192, 0.12), transparent 38%),
    linear-gradient(135deg, #081426, #0d1f36 42%, #0a1526 100%);
}

.summary-glow {
  position: absolute;
  inset: -30% -10%;
  background: conic-gradient(from 120deg, rgba(94, 255, 208, 0), rgba(94, 255, 208, 0.1), rgba(110, 190, 255, 0));
  filter: blur(26px);
  animation: spin-glow 10s linear infinite;
  pointer-events: none;
}

.summary-card {
  position: relative;
  z-index: 1;
  width: min(860px, 96vw);
  margin: 0 auto;
  border: 1px solid #2a456c;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(17, 34, 57, 0.95), rgba(12, 26, 45, 0.92));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(170, 210, 255, 0.2);
  padding: 18px;
}

.summary-head h2 {
  margin: 0;
  font-size: clamp(24px, 4.5vw, 34px);
  letter-spacing: 0.02em;
}

.summary-room {
  margin-top: 8px;
  color: #9cc2ef;
  font-size: 13px;
}

.summary-subtitle {
  margin: 8px 0 0;
  color: #d5e7ff;
  font-size: 14px;
}

.summary-metrics {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-metric {
  border: 1px solid #2a476f;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(16, 35, 59, 0.85), rgba(11, 24, 41, 0.88));
  padding: 10px;
}

.summary-metric span {
  color: #91afda;
  font-size: 12px;
}

.summary-metric strong {
  margin-top: 5px;
  display: block;
  font-size: 22px;
  color: #f0f7ff;
}

.summary-section-title {
  margin-top: 14px;
  margin-bottom: 8px;
  color: #bcd6fb;
  font-weight: 700;
  font-size: 13px;
}

.summary-ranking {
  display: grid;
  gap: 6px;
}

.summary-rank-row {
  border: 1px solid #264261;
  border-radius: 10px;
  background: #0d1d33;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.summary-rank-row.you {
  border-color: #66d0ff;
  background: linear-gradient(90deg, rgba(64, 200, 255, 0.2), rgba(7, 30, 53, 0.95));
}

.summary-rank-row strong {
  color: #82f6ca;
  font-size: 16px;
}

.summary-rank-row strong.profit-good {
  color: #55e3b3;
}

.summary-rank-row strong.profit-bad {
  color: #ff8a93;
}

.summary-highlights {
  display: grid;
  gap: 7px;
}

.summary-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.summary-actions button {
  border: 1px solid #3ea37f;
  border-radius: 12px;
  background: linear-gradient(180deg, #7df0c7, #4dd2a5);
  color: #062218;
  font-weight: 800;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease;
}

.summary-actions button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.summary-actions button:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.summary-highlight-item {
  border: 1px solid #214364;
  border-radius: 10px;
  background: rgba(11, 25, 42, 0.92);
  padding: 9px 10px;
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.summary-highlight-item strong {
  color: #d7ebff;
}

.summary-highlight-item span {
  color: #92b0d9;
}

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

@keyframes float-field {
  from {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  50% {
    transform: translate3d(-2.5%, 1.5%, 0) rotate(180deg);
  }
  to {
    transform: translate3d(0, 0, 0) rotate(360deg);
  }
}

@keyframes marquee-scroll {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(calc(-1 * var(--marquee-shift, 50%)), 0, 0);
  }
}

@keyframes broadcast-slide-in {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes broadcast-fade-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-6px) scale(0.99);
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 280px 1fr;
  }
  #side-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 6px;
  }

  .topbar-main,
  .topbar-timers,
  .topbar-wallet {
    width: 100%;
  }

  .topbar-main {
    text-align: left;
  }

  .title-line {
    font-size: 16px;
  }

  .meta,
  .timers,
  .wallet {
    font-size: 12px;
    line-height: 1.3;
  }

  .topbar-timers {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    text-align: center;
  }

  .topbar-wallet {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px 6px;
    text-align: center;
  }

  .top-holdings {
    grid-column: 1 / -1;
    justify-content: flex-start;
    margin-top: 0;
  }

  .event-ticker {
    padding: 6px 8px;
  }

  .mobile-tabs {
    display: flex;
    gap: 8px;
    padding: 6px 8px 0;
  }

  .tab-btn {
    flex: 1;
    border: 1px solid var(--line);
    background: #0f2037;
    color: var(--text);
    border-radius: 8px;
    padding: 8px;
    font-weight: 600;
  }

  .tab-btn.active {
    border-color: var(--accent);
    color: #cfe7ff;
  }

  .layout {
    display: block;
    padding: 8px;
  }

  .panel {
    min-height: auto;
    margin-bottom: 10px;
    padding: 8px;
  }

  #side-panel {
    display: block;
  }

  .tab-panel {
    display: none;
  }

  .tab-panel.active {
    display: block;
  }

  .panel-block.tab-panel {
    display: none;
  }

  .panel-block.tab-panel.active {
    display: block;
  }

  .summary-metrics {
    grid-template-columns: 1fr;
  }

  .contracts-inline-wrap {
    display: none;
  }

  .contracts-side-section {
    display: block;
  }

  .audio-toggle {
    top: auto;
    right: 10px;
    bottom: 12px;
  }
}
