:root {
  --bg: #14111c;
  --panel: #1b1722;
  --card: #241d33;
  --card-hi: #2c2440;
  --line: #332a47;
  --text: #efe7ff;
  --muted: #a99fbe;
  --accent: #9881bb;
  --accent-hi: #c9a7ff;
  --danger: #e0809a;
  --good: #8fd6a8;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #241d38 0%, var(--bg) 60%) no-repeat, var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "DejaVu Sans", sans-serif;
  min-height: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0.01em; }
h1 { font-size: 1rem; }
h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }

a { color: var(--accent-hi); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(20, 17, 28, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.6rem; }

.sigil {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, var(--accent), #5d4a86, var(--accent));
  box-shadow: 0 0 14px rgba(152, 129, 187, 0.55);
}

.who { display: flex; align-items: center; gap: 0.6rem; }

.chip {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- layout ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  margin-bottom: 1rem;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.panel-head h2 { margin: 0; }

.count { color: var(--muted); font-size: 0.8rem; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- sign in ---------- */

.signin { max-width: 560px; margin: 3rem auto; text-align: center; }
.signin form { text-align: left; }
.signin h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.25rem; margin-bottom: 0.5rem; }
.signin .muted { margin: 0.6rem auto; max-width: 44ch; }

.bigcode {
  display: block;
  font: 700 2.4rem/1.2 ui-monospace, "DejaVu Sans Mono", monospace;
  letter-spacing: 0.32em;
  padding: 0.9rem 0 0.9rem 0.32em;
  margin: 1rem 0;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent-hi);
  text-shadow: 0 0 24px rgba(201, 167, 255, 0.45);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
.tab:hover { color: var(--text); background: var(--card); }
.tab[aria-selected="true"] {
  color: #1a1425;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- clue grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }

.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #1e1830;
  display: block;
}

.card .noart {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(45deg, #1e1830, #1e1830 10px, #221a35 10px, #221a35 20px);
  color: var(--muted);
  font-size: 1.6rem;
}

.card .meta {
  padding: 0.4rem 0.5rem 0.5rem;
  border-top: 1px solid var(--line);
}
.card .name { font-size: 0.78rem; line-height: 1.25; }
.card .tier { font-size: 0.72rem; color: var(--muted); }

.empty { color: var(--muted); font-style: italic; padding: 0.5rem 0; }

/* ---------- forms ---------- */

.form { display: grid; gap: 0.65rem; }
.row { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1 1 8rem;
}

input, select, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 0.5rem 0.6rem;
  font: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, "DejaVu Sans Mono", monospace; font-size: 0.85rem; }

button { font: inherit; border-radius: 9px; padding: 0.5rem 0.95rem; cursor: pointer; border: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }

.primary { background: var(--accent); color: #1a1425; border-color: var(--accent); font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--accent-hi); border-color: var(--accent-hi); }

.ghost { background: transparent; color: var(--muted); }
.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }

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

/* ---------- trades ---------- */

.trade {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.5rem;
  background: var(--card);
  display: grid;
  gap: 0.4rem;
}
.trade .line { font-size: 0.85rem; }
.trade .acts { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.trade .acts button { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ---------- library ---------- */

.bar {
  height: 8px;
  background: #1e1830;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0;
  border: 1px solid var(--line);
}
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hi)); }

.bookline {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.bookline:hover { background: var(--card); border-color: var(--line); }
.bookline .cat { color: var(--muted); font-size: 0.75rem; }

.node {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.88rem;
}
.node:last-child { border-bottom: 0; }
.node .at {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.node.done .at { color: var(--good); }
.node .detail { color: var(--muted); font-size: 0.8rem; }

/* ---------- power ---------- */

.bigunit {
  font: 700 2.6rem/1 ui-monospace, "DejaVu Sans Mono", monospace;
  color: var(--accent-hi);
  margin: 0.3rem 0 0.9rem;
}

.ranked { margin: 0; padding-left: 1.4rem; }
.ranked li { padding: 0.25rem 0; }
.ranked li .u { color: var(--accent-hi); font-variant-numeric: tabular-nums; }
.ranked li.me { font-weight: 700; }

/* ---------- toast ---------- */

.toast {
  border: 1px solid var(--accent);
  background: #241d33;
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.toast.err { border-color: var(--danger); color: #ffd9e2; }

[hidden] { display: none !important; }

/* ---------- modal ---------- */

dialog.panel {
  padding: 0;
  width: min(420px, 92vw);
  max-width: min(420px, 92vw);
  max-height: 88vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  margin: auto;
}
dialog.panel::backdrop { background: rgba(9, 7, 14, 0.68); }
dialog.panel .sheet {
  display: grid;
  gap: 0.7rem;
  padding: 1.05rem 1.1rem 1.15rem;
  max-height: 88vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
dialog.panel h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.05rem; }
dialog.panel .row { margin-top: 0.25rem; }
dialog.panel .row button { flex: 1 1 auto; }

/* ---------- phones ---------- */

html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }

.topbar { padding: 0.8rem max(1.25rem, env(safe-area-inset-left)) 0.8rem max(1.25rem, env(safe-area-inset-right)); }
main { padding: 1.25rem max(1.25rem, env(safe-area-inset-left)) 2.5rem max(1.25rem, env(safe-area-inset-right)); }

@media (hover: none) {
  .card:hover { transform: none; border-color: var(--line); }
}

@media (max-width: 640px) {
  .topbar { padding: 0.65rem max(0.8rem, env(safe-area-inset-left)) 0.65rem max(0.8rem, env(safe-area-inset-right)); }
  main { padding: 0.8rem max(0.8rem, env(safe-area-inset-left)) 2rem max(0.8rem, env(safe-area-inset-right)); }
  .panel { padding: 0.85rem 0.9rem 1rem; border-radius: 12px; }
  .brand h1 { font-size: 0.92rem; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chip { font-size: 0.78rem; padding: 0.2rem 0.55rem; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .who { gap: 0.4rem; }
  .who button { white-space: nowrap; }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.45rem;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(94px, 1fr)); gap: 0.45rem; }
  .card .name { font-size: 0.73rem; }
  .card .tier { font-size: 0.68rem; }

  /* 16px stops iOS from zooming the page when a field gets focus. */
  input, select, textarea { font-size: 16px; }
  textarea { font-size: 15px; }
  label { flex: 1 1 100%; }
  .row > * { flex: 1 1 100%; }
  .row > button { flex: 1 1 auto; min-height: 44px; }
  button { min-height: 42px; }

  .signin { margin: 1rem auto; }
  .bigcode { font-size: clamp(1.35rem, 8.5vw, 2rem); letter-spacing: 0.2em; padding: 0.7rem 0 0.7rem 0.2em; }
  .bigunit { font-size: 2.1rem; }

  .node { grid-template-columns: 1.9rem 1fr; gap: 0.45rem; font-size: 0.85rem; }
  .trade .acts button { min-height: 38px; }
}

@media (max-width: 380px) {
  .brand h1 { font-size: 0.85rem; }
  .chip { max-width: 30vw; }
  .tab { padding: 0.45rem 0.75rem; }
}

