:root {
  --bg: #05060f;
  --panel: rgba(14, 17, 34, 0.86);
  --panel-solid: #0e1122;
  --line: rgba(140, 160, 220, 0.18);
  --text: #e6e9f5;
  --muted: #9aa3c4;
  --accent: #8db4ff;
  --gold: #ffd27a;
  --err: #ff8a8a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#sky { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hidden { display: none !important; }

/* Top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top)) 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(5,6,15,0.85), transparent);
}
.brand { font-weight: 700; letter-spacing: 0.5px; font-size: 18px; color: var(--text); }
.brand::first-letter { color: var(--gold); }
.spacer { flex: 1; }
#userbox { display: flex; align-items: center; gap: 8px; }
#points { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; }
#points::after { content: " pt"; color: var(--muted); font-weight: 400; }

button {
  font: inherit; cursor: pointer; border-radius: 999px; border: 1px solid var(--line);
  padding: 8px 14px; color: var(--text); background: rgba(255,255,255,0.04);
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: rgba(255,255,255,0.09); }
button.primary { background: var(--accent); color: #071022; border-color: transparent; font-weight: 600; }
button.primary:hover { background: #a6c6ff; }
button.ghost { background: transparent; }
button.wide { width: 100%; padding: 12px; margin-top: 6px; }
button.x {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; padding: 0;
  font-size: 22px; line-height: 1; border: none; background: transparent; color: var(--muted);
}

/* Search */
#searchbar { position: fixed; top: 62px; left: 16px; z-index: 9; width: min(340px, calc(100vw - 32px)); }
#search {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; backdrop-filter: blur(8px);
}
#search::placeholder { color: var(--muted); }
#search-results {
  margin-top: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; backdrop-filter: blur(8px);
}
#search-results:empty { display: none; }
.sr-item { padding: 9px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.sr-item:hover { background: rgba(255,255,255,0.06); }
.sr-item .con { color: var(--muted); font-size: 13px; }

#hint {
  position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); left: 0; right: 0; z-index: 8;
  text-align: center; color: var(--muted); font-size: 13px; pointer-events: none;
}
#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 20; color: var(--muted); background: var(--bg); font-size: 15px; letter-spacing: 0.3px;
}

/* Detail panel */
#panel {
  position: fixed; z-index: 12; right: 16px; top: 62px; width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 90px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
@media (max-width: 560px) {
  #panel { right: 12px; left: 12px; width: auto; top: auto; bottom: 12px; max-height: 70vh; }
}
#panel h3 { margin: 0 0 4px; font-size: 20px; }
#panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv .k { color: var(--muted); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.free { background: rgba(141,180,255,0.16); color: var(--accent); }
.badge.taken { background: rgba(255,210,122,0.16); color: var(--gold); }
.owned-name { font-size: 22px; color: var(--gold); margin: 8px 0 2px; }
.owned-msg { color: var(--text); font-style: italic; margin: 8px 0; opacity: 0.9; }

#panel input, #panel textarea {
  width: 100%; margin-top: 8px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text); font: inherit;
}
#panel textarea { resize: vertical; min-height: 60px; }
.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 14px; cursor: pointer; }
.cost-line { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }
.cost-line b { color: var(--gold); }

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(3,4,10,0.7); backdrop-filter: blur(4px); padding: 20px;
}
.modal-card {
  position: relative; width: min(400px, 100%); background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-card h2 { margin: 0 0 16px; font-size: 22px; }
.modal-card input {
  width: 100%; margin-bottom: 10px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text); font: inherit;
}
.switch { color: var(--muted); font-size: 14px; text-align: center; margin: 14px 0 0; }
.switch a { color: var(--accent); text-decoration: none; }
.err { background: rgba(255,138,138,0.12); color: var(--err); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }

#mine-list { max-height: 60vh; overflow-y: auto; }
.mine-item { padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mine-item:hover { opacity: 0.85; }
.mine-item .n { font-size: 17px; color: var(--gold); }
.mine-item .d { color: var(--muted); font-size: 13px; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--panel-solid); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  animation: toastin 0.2s ease;
}
.toast.good { border-color: rgba(141,180,255,0.5); }
.toast.bad { border-color: rgba(255,138,138,0.5); }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
