:root {
  --ether-purple: #1a0a2e;
  --ether-purple-mid: #2d1b4e;
  --ether-purple-soft: #382560;
  --crystal-teal: #2dd4bf;
  --crystal-teal-soft: #5eead4;
  --gold-accent: #d4af37;
  --gold-soft: #f0d875;
  --text: #ece6f5;
  --muted: #a89cc4;
  --danger: #f472b6;
  --ok: #6ee7b7;
  --card: rgba(45, 27, 78, 0.55);
  --card-edge: rgba(45, 212, 191, 0.16);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, var(--ether-purple-mid), var(--ether-purple));
  color: var(--text);
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

body.tg-webapp {
  touch-action: pan-y;
}

button,
.btn,
.tab,
.btn-locale,
.btn-ghost,
.btn-icon,
.stranger-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

/* Top bar */
.topbar {
  padding: 0.75rem 1rem 0.6rem;
  border-bottom: 1px solid rgba(212, 175, 55, 0.18);
  background: rgba(26, 10, 46, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.title {
  font-size: 1.2rem;
  margin: 0;
  color: var(--crystal-teal);
  letter-spacing: 0.04em;
  font-weight: 700;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.nav-hint {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
  opacity: 0.92;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.55rem;
  gap: 0.5rem;
}

.badge {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.45);
  background: rgba(26, 10, 46, 0.55);
  color: var(--gold-accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.coin-pill .muted {
  color: var(--muted);
  font-weight: 500;
}

.btn-locale {
  min-width: 2.6rem;
  height: 2.4rem;
  padding: 0 0.6rem;
  border-radius: 10px;
  border: 1px solid rgba(45, 212, 191, 0.45);
  background: rgba(45, 27, 78, 0.65);
  color: var(--crystal-teal);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-locale:active {
  transform: scale(0.97);
}

/* View / cards */
.view {
  flex: 1;
  padding: 0.75rem 0.9rem 1rem;
  position: relative;
  z-index: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.7rem;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
}

.card.hint {
  background: rgba(45, 27, 78, 0.35);
  font-size: 0.8rem;
  color: var(--muted);
}

.card h2,
.card h3 {
  margin: 0 0 0.55rem;
  font-size: 0.98rem;
  color: var(--crystal-teal);
}

.muted {
  color: var(--muted);
}

.xs {
  font-size: 0.72rem;
}

.big {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold-accent);
  letter-spacing: 0.02em;
}

.list-item {
  font-size: 0.85rem;
  margin: 0.25rem 0;
  color: var(--text);
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.row-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

/* Hero card */
.stranger-head {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 0.7rem;
}

.stranger-glyph {
  font-size: 2rem;
  width: 3rem;
  height: 3rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.18), rgba(212, 175, 55, 0.18));
  border: 1px solid rgba(212, 175, 55, 0.35);
  flex-shrink: 0;
}

.stranger-meta {
  flex: 1;
  min-width: 0;
}

.stranger-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.stranger-sub {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat-block {
  margin-top: 0.35rem;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.stat-row label {
  width: 7.5rem;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.74rem;
}

.stat-val {
  width: 1.8rem;
  text-align: right;
  color: var(--text);
  font-weight: 700;
  font-size: 0.78rem;
}

.bar {
  flex: 1;
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  overflow: hidden;
}

.bar.bar-thin {
  height: 5px;
}

.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--crystal-teal), var(--gold-accent));
  border-radius: 999px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  min-height: 2.6rem;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--ether-purple);
  background: linear-gradient(135deg, var(--crystal-teal), var(--crystal-teal-soft));
  box-shadow: 0 6px 14px rgba(45, 212, 191, 0.18);
}

.btn:active {
  transform: scale(0.98);
  filter: brightness(0.95);
}

.btn-ghost {
  background: transparent;
  color: var(--crystal-teal);
  border: 1px solid rgba(45, 212, 191, 0.45);
  box-shadow: none;
}

.btn-ghost:active {
  background: rgba(45, 212, 191, 0.1);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold-accent), var(--gold-soft));
  color: #1a0a2e;
  box-shadow: 0 6px 14px rgba(212, 175, 55, 0.22);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.2);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn-icon:active {
  background: rgba(255, 255, 255, 0.08);
}

/* Status pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-pill.idle {
  background: rgba(45, 27, 78, 0.6);
  color: var(--muted);
}

.status-pill.ok {
  color: var(--ok);
  border-color: rgba(110, 231, 183, 0.35);
  background: rgba(45, 90, 78, 0.18);
}

.status-pill.running {
  color: var(--gold-accent);
  border-color: rgba(212, 175, 55, 0.45);
  background: rgba(60, 30, 12, 0.25);
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-accent);
  box-shadow: 0 0 8px var(--gold-accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.4;
    transform: scale(0.85);
  }
}

/* Islands */
.island-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}

.island-head h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.progress-wrap {
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.progress-bg {
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--crystal-teal), var(--gold-accent));
  transition: width 0.4s ease;
}

/* Fragments */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.frag-card {
  margin-bottom: 0;
}

.frag-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
}

.frag-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  margin-top: 0.55rem;
}

.frag-cell {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.frag-cell.owned {
  color: var(--ether-purple);
  background: linear-gradient(135deg, var(--gold-accent), var(--gold-soft));
  border-color: var(--gold-accent);
}

/* Market */
.lot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.lot-title {
  font-weight: 700;
  font-size: 0.92rem;
}

/* Spiral */
.spiral-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 0.3rem 0 0.65rem;
}

.spiral-stats > div {
  background: rgba(26, 10, 46, 0.45);
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

.num {
  width: 5.5rem;
  height: 2.6rem;
  padding: 0 0.7rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(15, 5, 30, 0.6);
  border: 1px solid rgba(45, 212, 191, 0.35);
  border-radius: 10px;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.shop-row:last-child {
  border-bottom: none;
}

.shop-text {
  flex: 1;
  min-width: 0;
}

.shop-title {
  font-weight: 700;
  font-size: 0.88rem;
}

.stars-shop {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Tabs */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(22, 10, 38, 0.96), rgba(12, 6, 22, 0.99));
  border-top: 1px solid rgba(212, 175, 55, 0.22);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  z-index: 50;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 3.35rem;
  padding: 8px 4px;
  margin: 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.tab:active {
  background: rgba(45, 212, 191, 0.08);
}

.tab.active {
  color: var(--text);
  background: rgba(45, 212, 191, 0.14);
  box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.4);
}

.tab-icon {
  font-size: 1.45rem;
  line-height: 1;
  filter: grayscale(0.2);
}

.tab.active .tab-icon {
  filter: none;
}

.tab-label {
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0;
}

.modal.hidden {
  display: none;
}

.modal-panel {
  background: linear-gradient(180deg, var(--ether-purple-soft), var(--ether-purple-mid));
  border-top: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 18px 18px 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--gold-accent);
}

.modal-body {
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
  justify-content: flex-end;
}

.modal-actions .btn {
  flex: 1;
}

/* Stranger picker */
.stranger-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stranger-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
  background: rgba(26, 10, 46, 0.55);
  border: 1px solid rgba(45, 212, 191, 0.2);
  border-radius: 12px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.stranger-card.active {
  border-color: var(--gold-accent);
  box-shadow: 0 0 0 1px var(--gold-accent) inset;
}

.stranger-card:active {
  transform: scale(0.99);
}

.badge-on {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ether-purple);
  background: var(--gold-accent);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.reward-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.reward-list li {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
}

.boss-result .log {
  margin-top: 0.7rem;
}

/* Skeleton */
.skel {
  pointer-events: none;
}

.skel-line {
  height: 12px;
  border-radius: 6px;
  margin: 0.45rem 0;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skel-line.w50 {
  width: 50%;
}
.skel-line.w70 {
  width: 70%;
}
.skel-line.w90 {
  width: 90%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* Logs */
.log {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  max-width: 90%;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 12px;
  background: rgba(20, 10, 36, 0.95);
  color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.4);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 300;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-kind="success"] {
  border-color: rgba(110, 231, 183, 0.45);
}

.toast[data-kind="error"] {
  border-color: rgba(244, 114, 182, 0.6);
  color: var(--danger);
}
