:root {
  --bg: #0f1220;
  --panel: #1a1f35;
  --panel2: #232a45;
  --text: #eef1ff;
  --muted: #9aa3c7;
  --gold: #ffd76a;
  --dia: #7ad7ff;
  --accent: #6c8cff;
  --ok: #5dffa8;
  --danger: #ff6b8a;
  --radius: 16px;
  --me: #6c8cff;
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a1f55 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #1a3a4a 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button, a, input { touch-action: manipulation; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(15, 18, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.logo { font-size: 28px; }
.title { font-weight: 700; letter-spacing: 0.02em; }
.sub { font-size: 12px; color: var(--muted); }

.stats { display: flex; gap: 10px; flex-wrap: wrap; min-width: 0; }
.stat {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 110px;
}
.stat .ico { font-size: 20px; }
.stat > div { min-width: 0; }
.stat .label { font-size: 11px; color: var(--muted); }
.stat .val { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.gold .val { color: var(--gold); }
.stat.dia .val { color: var(--dia); }
.stat.cps .val { color: var(--ok); }

.meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); }
.me {
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--me) 25%, transparent);
  color: var(--me);
  border: 1px solid color-mix(in srgb, var(--me) 50%, transparent);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 360px);
  grid-template-rows: auto auto;
  gap: 12px;
  padding: 12px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.center {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 360px;
  position: relative;
}

.side {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; flex-direction: column;
  max-height: 48vh;
  min-height: 220px;
}
.side h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.facility-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.facility-heading h2 { margin: 0; }
.facility-pager { display: flex; align-items: center; gap: 6px; }
.facility-pager span {
  min-width: 34px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.facility-pager button {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.facility-pager button:disabled { opacity: 0.35; cursor: not-allowed; }

.click-stage {
  position: relative;
  width: min(320px, 80vw);
  height: min(320px, 80vw);
  display: flex; align-items: center; justify-content: center;
}

.big-btn {
  width: 220px; height: 220px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at 35% 30%, #ffe9a8, #f5b942 45%, #c47a12 80%, #7a4508);
  box-shadow:
    0 12px 0 #8a5a10,
    0 20px 40px rgba(0,0,0,0.45),
    inset 0 8px 20px rgba(255,255,255,0.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease;
  position: relative;
  color: #3a2200;
  font-weight: 800;
}
.big-btn * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.big-btn:active, .big-btn.pressed {
  transform: scale(0.92) translateY(6px);
  box-shadow:
    0 4px 0 #8a5a10,
    0 10px 20px rgba(0,0,0,0.4),
    inset 0 8px 20px rgba(255,255,255,0.25);
}
.big-btn.bounce {
  animation: bounce 0.35s cubic-bezier(.36,.07,.19,.97);
}
@keyframes bounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.88) translateY(8px); }
  55% { transform: scale(1.06) translateY(-4px); }
  100% { transform: scale(1); }
}
.coin-core { font-size: 72px; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0,0,0,0.2)); pointer-events: none; }
.btn-hint { font-size: 14px; opacity: 0.85; pointer-events: none; }
.power-tag {
  position: absolute; top: 18px; right: 28px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.float-num {
  position: absolute;
  pointer-events: none;
  font-weight: 800;
  font-size: 20px;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  animation: floatUp 0.9s ease-out forwards;
  z-index: 5;
}
.float-num.dia { color: var(--dia); font-size: 22px; }
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-80px) scale(1.2); }
}

.card {
  background: var(--panel2);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.04);
}
.card .row { display: flex; gap: 8px; align-items: center; }
.card .ico { flex: 0 0 32px; font-size: 22px; width: 32px; text-align: center; }
.card .info { flex: 1; min-width: 0; }
.card .name { font-weight: 650; font-size: 14px; }
.card .desc {
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.facility-detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
  color: #c3cae8;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.meta-line span { min-width: 0; overflow-wrap: anywhere; }
.status {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 12px; color: #22c55e; font-weight: 600;
}
.status-dot {
  width: 6px; height: 6px; background: #22c55e; border-radius: 50%;
  box-shadow: 0 0 6px #22c55e; animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.buy-btn, .enh-btn {
  border: none; border-radius: 10px;
  padding: 8px 10px;
  font-weight: 700; font-size: 12px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
  touch-action: none;
  flex: 0 0 auto;
}
.buy-btn:disabled, .enh-btn:disabled {
  opacity: 0.4; cursor: not-allowed;
}
.buy-btn.afford { background: linear-gradient(135deg, #5d8cff, #7a5dff); box-shadow: 0 0 12px rgba(108,140,255,0.35); }
.click-up-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.enh-btn {
  background: linear-gradient(135deg, #3ec7ff, #7a8cff);
  margin-left: 6px;
  padding: 8px 8px;
}

.facility-list { overflow: auto; flex: 1; padding-right: 2px; }
.facility-list::-webkit-scrollbar { width: 6px; }
.facility-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.chat-log {
  flex: 1; overflow: auto;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  padding: 8px;
  font-size: 13px;
  line-height: 1.45;
}
.chat-item { margin-bottom: 8px; word-break: break-word; }
.chat-item .who { font-weight: 700; margin-right: 6px; }
.chat-item.notify { color: var(--muted); font-size: 12px; }
.chat-item.notify .who { font-weight: 600; }

.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  user-select: text;
}
.chat-form button {
  border: none; border-radius: 10px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff; font-weight: 700; cursor: pointer;
}

.site-footer {
  padding: 4px 12px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.site-footer a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}
.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--text);
  text-decoration: underline;
}

.toast-area {
  position: fixed; top: 72px; right: 12px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 50; pointer-events: none;
  max-height: min(360px, calc(100dvh - 84px));
  max-width: min(320px, 90vw);
  overflow: hidden;
}
.toast {
  background: rgba(26, 31, 53, 0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.4s forwards;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.toast.err { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  .center { grid-column: 1; grid-row: 1; min-height: 300px; }
  .upgrades { grid-row: 2; max-height: 40vh; }
  .chat-panel { grid-row: 3; max-height: 35vh; }
  .topbar { padding: 10px; }
  .stat { min-width: 90px; padding: 6px 8px; }
}

@media (max-width: 480px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }
  .brand { gap: 7px; }
  .logo { font-size: 24px; }
  .title { font-size: 14px; }
  .sub { font-size: 10px; }
  .meta { font-size: 10px; }
  .me { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stats {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }
  .stat {
    min-width: 0;
    gap: 5px;
    padding: 6px;
    border-radius: 8px;
  }
  .stat .ico { flex: 0 0 auto; font-size: 16px; }
  .stat .label { font-size: 10px; }
  .stat .val { font-size: 12px; }

  .layout { gap: 8px; padding: 8px; }
  .center { min-height: 250px; }
  .click-stage { width: min(260px, 88vw); height: min(260px, 88vw); }
  .big-btn { width: 190px; height: 190px; }
  .coin-core { font-size: 62px; }

  .side { min-width: 0; padding: 8px; border-radius: 12px; }
  .card { padding: 8px; }
  .facility-list .card .row {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: start;
    gap: 6px;
  }
  .facility-list .card .ico {
    grid-column: 1;
    grid-row: 1;
    width: 28px;
    font-size: 20px;
  }
  .facility-list .card .info {
    grid-column: 2 / -1;
    grid-row: 1;
  }
  .facility-list .buy-btn {
    grid-column: 2;
    grid-row: 2;
    width: 100%;
  }
  .facility-list .enh-btn {
    grid-column: 3;
    grid-row: 2;
    min-width: 40px;
    margin-left: 0;
  }
  .chat-form { gap: 6px; }
  .chat-form input { padding: 9px; }
  .chat-form button { padding: 0 11px; }
  .toast-area {
    top: 112px;
    right: 8px;
    max-height: min(220px, calc(100dvh - 128px));
    max-width: calc(100vw - 16px);
    gap: 6px;
  }
  .toast {
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.35;
  }
}

@media (max-width: 360px) {
  .stat .ico { display: none; }
  .stat { justify-content: center; }
  .stat .val { font-size: 11px; }
  .layout { padding: 6px; }
  .big-btn { width: 172px; height: 172px; }
  .coin-core { font-size: 54px; }
  .power-tag { top: 14px; right: 20px; }
  .card .name { font-size: 13px; }
}
