:root {
  --bg: #03060b;
  --panel: rgba(4, 12, 22, 0.78);
  --cyan: #8ce7ff;
  --cyan-dim: #3d8eaa;
  --line: rgba(140, 231, 255, 0.5);
  --pink: #ff5a9a;
  --gold: #f0c14b;
  --ok: #5dffc0;
  --text: #eaf6ff;
  --muted: #7d93a8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Rajdhani", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background-image:
    linear-gradient(rgba(10, 30, 50, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(10, 30, 50, 0.12) 1px, transparent 1px),
    radial-gradient(900px 500px at 50% 0%, rgba(40, 150, 210, 0.22), transparent 60%);
  background-size: 100% 5px, 48px 48px, auto;
  animation: gridDrift 18s linear infinite;
}

@keyframes gridDrift {
  from { background-position: 0 0, 0 0, 50% 0; }
  to { background-position: 0 80px, 48px 48px, 50% 0; }
}

.scan {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16),
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 8;
}

.sweep {
  pointer-events: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 18%;
  background: linear-gradient(to bottom, transparent, rgba(140, 231, 255, 0.07), transparent);
  animation: sweep 4.5s ease-in-out infinite;
  z-index: 7;
}

@keyframes sweep {
  0% { top: -20%; }
  100% { top: 110%; }
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  background:
    radial-gradient(circle at 50% 42%, rgba(40, 140, 200, 0.22), transparent 42%),
    #02050a;
  overflow: hidden;
  transition: opacity 0.8s ease, visibility 0.8s;
}
.boot.off {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-rings {
  position: absolute;
  width: min(72vw, 560px);
  height: min(72vw, 560px);
  border: 1px solid rgba(140, 231, 255, 0.18);
  border-radius: 50%;
  animation: spin 28s linear infinite;
}
.boot-rings::before,
.boot-rings::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 1px dashed rgba(140, 231, 255, 0.22);
  border-radius: 50%;
  animation: spin 16s linear infinite reverse;
}
.boot-rings::after {
  inset: 28%;
  border-style: solid;
  animation-duration: 22s;
}

.boot-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 48%, #fff 0%, #8ce7ff 28%, transparent 62%);
  opacity: 0;
  pointer-events: none;
}

.boot-mark {
  position: relative;
  color: var(--cyan);
  font-size: 42px;
  animation: pulse 1.4s ease-in-out infinite;
  text-shadow: 0 0 18px var(--cyan);
}

.boot-text {
  position: relative;
  margin-top: 14px;
  padding: 0 16px;
  text-align: center;
  font-family: "Share Tech Mono", monospace;
  letter-spacing: 0.46em;
  color: var(--cyan);
  font-size: clamp(18px, 4.2vw, 36px);
  animation: flicker 2.8s linear infinite;
}

.boot-tag {
  position: relative;
  margin-top: 8px;
  padding: 0 16px;
  text-align: center;
  font-family: "Share Tech Mono", monospace;
  letter-spacing: 0.28em;
  color: var(--muted);
  font-size: 15px;
}

.link-start {
  position: relative;
  margin-top: 52px;
  padding: 22px 84px;
  max-width: calc(100vw - 32px);
  border: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(80, 190, 255, 0.08));
  color: #fff;
  font-family: "Share Tech Mono", monospace;
  font-size: clamp(18px, 4vw, 36px);
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  cursor: pointer;
  touch-action: manipulation;
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 14px 100%, 0 50%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.85),
    0 0 28px rgba(140, 231, 255, 0.45),
    0 18px 40px rgba(0, 0, 0, 0.45);
  animation: floatBtn 3.2s ease-in-out infinite;
}
.link-start span { pointer-events: none; }
.link-start:hover {
  filter: brightness(1.2);
}
.link-start:disabled {
  cursor: default;
}

.boot-hint {
  position: relative;
  margin-top: 18px;
  padding: 0 16px;
  text-align: center;
  font-family: "Share Tech Mono", monospace;
  letter-spacing: 0.32em;
  color: var(--muted);
  font-size: 14px;
  animation: blink 1.6s step-end infinite;
}

@keyframes floatBtn {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-18px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.boot.firing .link-start {
  animation: launch 0.75s ease forwards;
}
.boot.firing .boot-flash {
  animation: flashOut 0.85s ease forwards;
}
.boot.firing .boot-rings {
  animation: ringsOut 0.8s ease forwards;
}

@keyframes launch {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-8px) scale(1.12); filter: brightness(2); }
  100% { transform: translateY(-20px) scale(6); opacity: 0; }
}

@keyframes flashOut {
  0% { opacity: 0; }
  35% { opacity: 0.95; }
  100% { opacity: 0; }
}

@keyframes ringsOut {
  to { transform: scale(1.6); opacity: 0; }
}

.wrap {
  height: 100dvh;
  width: 100%;
  padding: 0;
}

.term {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 0 80px rgba(80, 200, 255, 0.08) inset, 0 0 40px rgba(0, 160, 255, 0.12);
  padding: 18px 22px 16px;
  overflow: hidden;
  animation: panelIn 0.8s ease both;
}

@keyframes panelIn {
  from { opacity: 0; filter: blur(8px); }
  to { opacity: 1; filter: none; }
}

.term::before,
.term::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--cyan);
  animation: cornerPulse 2.8s ease-in-out infinite;
}
.term::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.term::after { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.term-foot { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
.term-foot::before,
.term-foot::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--cyan);
  bottom: -1px;
  animation: cornerPulse 2.8s ease-in-out infinite;
}
.term-foot::before { left: -1px; border-right: 0; border-top: 0; }
.term-foot::after { right: -1px; border-left: 0; border-top: 0; }

@keyframes cornerPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.brand {
  font-family: "Share Tech Mono", monospace;
  letter-spacing: 0.22em;
  font-size: 18px;
  color: var(--cyan);
  animation: flicker 5s linear infinite;
}
.brand small {
  display: block;
  margin-top: 4px;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-size: 14px;
}

@keyframes flicker {
  0%, 19%, 21%, 100% { opacity: 1; }
  20% { opacity: 0.55; }
  80% { opacity: 1; }
  81% { opacity: 0.7; }
}

.coins {
  display: flex;
  gap: 10px;
  align-items: center;
}
.coin {
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 6px 12px;
  min-width: 148px;
  text-align: right;
  font-family: "Share Tech Mono", monospace;
  animation: slideIn 0.6s ease both;
}
.coin em {
  font-style: normal;
  display: block;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: #c9a227;
}
.coin strong { font-size: 28px; font-weight: 600; }

.player {
  font-family: "Share Tech Mono", monospace;
  font-size: 15px;
  color: var(--muted);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.player a {
  color: var(--cyan);
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.player a:hover { text-decoration: underline; }
.addr-short { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  flex: 0 0 auto;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: #071018;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  font-family: "Share Tech Mono", monospace;
  font-size: 16px;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

button, .toggle {
  background: transparent;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  padding: 8px 12px;
  font-family: "Rajdhani", sans-serif;
  font-weight: 600;
  letter-spacing: 0.12em;
  cursor: pointer;
  text-transform: uppercase;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: rgba(140, 231, 255, 0.18);
}
button:hover, .toggle.active {
  background: rgba(140, 231, 255, 0.15);
}

.toggle-wrap { display: flex; gap: 0; }
.toggle { border-right: 0; }
.toggle:last-child { border-right: 1px solid var(--cyan); }

.status {
  font-family: "Share Tech Mono", monospace;
  font-size: 14px;
  color: var(--ok);
  min-height: 16px;
  margin-bottom: 10px;
  flex: 0 0 auto;
}
.status::after {
  content: "▌";
  margin-left: 6px;
  animation: blink 1s step-end infinite;
}
.status.err { color: var(--pink); }

@keyframes blink {
  50% { opacity: 0; }
}

.grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(420px, 1.35fr);
  gap: 20px;
  flex: 1;
  min-height: 0;
}
.raw .grid {
  grid-template-columns: 0.83fr 1.17fr;
}

h2 {
  margin: 0 0 10px;
  font-size: 16px;
  letter-spacing: 0.28em;
  color: var(--cyan);
  font-weight: 600;
  text-transform: uppercase;
}

.col {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.vault {
  display: grid;
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  padding: 10px 10px 8px;
  background: rgba(0, 0, 0, 0.28);
  animation: slideIn 0.5s ease both;
}
.item:nth-child(1) { animation-delay: 0.05s; }
.item:nth-child(2) { animation-delay: 0.12s; }
.item:nth-child(3) { animation-delay: 0.19s; }
.item:nth-child(4) { animation-delay: 0.26s; }
.item:nth-child(5) { animation-delay: 0.33s; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: none; }
}

.item .name {
  font-size: 20px;
  font-weight: 650;
}
.item .meta {
  font-family: "Share Tech Mono", monospace;
  font-size: 14px;
  color: var(--muted);
}
.item .meta.raw-only {
  word-break: break-all;
  line-height: 1.45;
  color: var(--cyan-dim);
  background: #04080e;
  border: 1px solid #123;
  padding: 8px;
  margin-top: 8px;
}
.item.legendary { border-color: var(--gold); }
.item.unique { border-color: var(--pink); }
.item.uncommon { border-color: var(--cyan-dim); }
.item.resource { border-color: var(--ok); }
.badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 1px 6px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.oracles { display: grid; gap: 16px; align-content: start; }

.skill {
  display: grid;
  grid-template-columns: minmax(0, 150px) minmax(0, 1fr) minmax(0, 150px);
  gap: 10px;
  align-items: center;
  font-size: 18px;
  margin-bottom: 8px;
  animation: slideIn 0.45s ease both;
}
.skill > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}
.bar {
  height: 12px;
  background: #0c1822;
  border: 1px solid var(--line);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #1ea8d0, var(--ok));
  animation: fillBar 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: var(--d, 0.2s);
}
@keyframes fillBar {
  to { width: var(--w, 0%); }
}
.xp {
  font-family: "Share Tech Mono", monospace;
  font-size: 14px;
  color: var(--muted);
  text-align: right;
}

.raw .skill { display: none; }
.human-only { display: block; }
.raw-only { display: none; }
.raw .human-only { display: none; }
.raw .raw-only { display: block; }

.hex {
  font-family: "Share Tech Mono", monospace;
  font-size: 13px;
  color: var(--cyan-dim);
  white-space: pre-wrap;
  word-break: break-all;
  background: #04080e;
  border: 1px solid #123;
  padding: 10px;
  max-height: 280px;
  overflow: auto;
}

.quests {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.q {
  border: 1px solid var(--line);
  padding: 8px 12px;
  font-size: 16px;
  color: var(--muted);
  animation: slideIn 0.4s ease both;
}
.q.on {
  border-color: var(--ok);
  color: var(--ok);
  box-shadow: 0 0 10px rgba(93, 255, 192, 0.2);
}

/* --- Mobile / tablet --- */
@media (max-width: 1024px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .raw .grid {
    grid-template-columns: 1fr;
  }
  html, body {
    overflow: auto;
    height: auto;
  }
  .wrap {
    height: auto;
    min-height: 100dvh;
    min-height: 100svh;
  }
  .term {
    height: auto;
    min-height: 100dvh;
    min-height: 100svh;
    overflow: visible;
  }
  .col {
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .term {
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      max(12px, env(safe-area-inset-right, 0px))
      max(16px, env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
  }

  .boot-text {
    letter-spacing: 0.16em;
    font-size: clamp(16px, 5.4vw, 26px);
  }
  .boot-tag {
    letter-spacing: 0.12em;
    font-size: 12px;
  }
  .boot-hint {
    letter-spacing: 0.14em;
    font-size: 12px;
  }
  .link-start {
    margin-top: 36px;
    padding: 16px 28px;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
    font-size: clamp(16px, 5vw, 24px);
    min-height: 52px;
  }
  .boot-mark { font-size: 34px; }
  .boot-rings {
    width: min(86vw, 420px);
    height: min(86vw, 420px);
  }

  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding-bottom: 10px;
    margin-bottom: 10px;
  }
  .brand {
    font-size: 15px;
    letter-spacing: 0.12em;
  }
  .brand small {
    font-size: 11px;
    letter-spacing: 0.08em;
  }
  .player { font-size: 13px; }
  .addr-full { display: none; }
  .addr-short { display: inline; }

  .coins {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .coin {
    min-width: 0;
    padding: 6px 10px;
    text-align: left;
  }
  .coin strong { font-size: 22px; }

  .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
  }
  #sync {
    min-height: 44px;
    min-width: 72px;
    padding: 10px 14px;
  }
  .toggle-wrap {
    grid-column: 1 / -1;
    width: 100%;
  }
  .toggle {
    flex: 1;
    min-height: 44px;
    text-align: center;
  }

  .status { font-size: 13px; }

  h2 {
    font-size: 13px;
    letter-spacing: 0.18em;
  }

  .skill {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name xp"
      "bar bar";
    gap: 4px 10px;
    font-size: 15px;
    margin-bottom: 12px;
  }
  .skill > span:first-child { grid-area: name; }
  .skill .bar { grid-area: bar; }
  .skill .xp {
    grid-area: xp;
    font-size: 12px;
    white-space: nowrap;
  }

  .item .name { font-size: 18px; }
  .q {
    font-size: 14px;
    padding: 8px 10px;
  }
  .hex {
    font-size: 12px;
    max-height: none;
  }

  .grid { gap: 28px; }
}

@media (max-width: 420px) {
  .boot-text { letter-spacing: 0.1em; }
  .link-start {
    padding: 14px 18px;
    letter-spacing: 0.14em;
    text-indent: 0.14em;
    width: calc(100% - 24px);
  }
  .coins { grid-template-columns: 1fr; }
  .coin strong { font-size: 20px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .boot-rings {
    width: min(42vh, 280px);
    height: min(42vh, 280px);
  }
  .boot-mark { font-size: 28px; }
  .boot-text { margin-top: 8px; font-size: 18px; }
  .boot-tag { font-size: 11px; }
  .link-start {
    margin-top: 16px;
    padding: 12px 28px;
    font-size: 18px;
  }
  .boot-hint { margin-top: 8px; font-size: 11px; }
}

@media (hover: none) {
  button:hover { background: transparent; }
  button:active,
  .toggle.active {
    background: rgba(140, 231, 255, 0.15);
  }
  .link-start:hover { filter: none; }
  .link-start:active { filter: brightness(1.2); }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .scan,
  .sweep,
  .boot-rings,
  .boot-rings::before,
  .boot-rings::after,
  .boot-mark,
  .boot-text,
  .boot-hint,
  .link-start,
  .brand,
  .status::after,
  .badge {
    animation: none;
  }
}
