:root {
  --bg: #16111f;
  --bg-elev: #1e1629;
  --rail: #221a31;
  --surface: #2a2138;
  --surface-2: #322844;
  --text: #f4eef8;
  --text-dim: #b9adc8;
  --muted: #8d809f;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(216, 189, 152, 0.28);
  --gold: #d8bd98;
  --gold-deep: #c2a06c;
  --accent: #9b7ec8;
  --tip: #e8b86d;
  --danger: #e06258;
  --radius: 14px;
  --radius-sm: 10px;
  --font: "DM Sans", "Hiragino Sans", "Segoe UI", sans-serif;
  --display: "Fraunces", "Noto Serif JP", serif;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(155, 126, 200, 0.35); color: #fff; }
a { color: var(--gold); text-decoration: none; }
a:hover { color: #ecd9b8; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.error {
  color: #ffa39c;
  font-size: .88rem;
  margin: 0;
  padding: .55rem .75rem;
  background: rgba(224, 98, 88, 0.12);
  border: 1px solid rgba(224, 98, 88, 0.3);
  border-radius: var(--radius-sm);
}
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ---------- rail / slack-like ---------- */

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.1rem .9rem 1.2rem;
  background: linear-gradient(180deg, #2b213c 0%, var(--rail) 100%);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: #fff;
  padding: .2rem .35rem;
}
.brand:hover { color: #fff; opacity: .9; }
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.brand em {
  display: block;
  font-style: normal;
  font-size: .7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: .15rem;
}
.brand.compact strong { font-size: 1rem; }
.mask-icon { color: var(--gold); flex-shrink: 0; }

.wallet-panel {
  display: grid;
  gap: .5rem;
  padding: .75rem;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.wallet-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.wallet-id {
  font-size: .78rem;
  letter-spacing: .02em;
  color: #fff;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  padding: .45rem .55rem;
}
.wallet-hint { margin: 0; font-size: .68rem; color: var(--muted); }
.wallet-hint:empty { display: none; }

.chain-chip {
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .25rem .55rem;
  border-radius: 999px;
  background: rgba(216, 189, 152, 0.9);
  color: #2a1f18;
  font-weight: 600;
  border: none;
}
.chain-chip.bad {
  background: rgba(224, 98, 88, 0.16);
  color: #ffc9c4;
  border: 1px solid rgba(224, 98, 88, 0.45);
}

.channel-block { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.channel-label {
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .2rem .55rem .45rem;
  font-weight: 600;
}
.channel-list {
  display: grid;
  gap: .15rem;
  overflow: auto;
  padding-bottom: .4rem;
}
.channel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem .6rem;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: .92rem;
  font-weight: 500;
}
.channel:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}
.channel.is-active {
  background: rgba(155, 126, 200, 0.22);
  color: #fff;
}
.channel .count {
  font-size: .7rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  padding: .1rem .4rem;
  min-width: 1.4rem;
  text-align: center;
}

.rail-actions {
  display: grid;
  gap: .45rem;
  padding-top: .4rem;
  border-top: 1px solid var(--line);
}
.rail-compose { width: 100%; }
.rail-link {
  color: var(--muted);
  font-size: .82rem;
  padding: .25rem .45rem;
}
.rail-link:hover { color: var(--text); }

/* ---------- stage ---------- */

.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(22, 17, 31, 0.78) 0%, rgba(22, 17, 31, 0.7) 45%, rgba(22, 17, 31, 0.88) 100%),
    url("/home.jpg") center/cover no-repeat fixed;
}

.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem .85rem;
  background: rgba(34, 26, 49, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.mobile-drawer {
  display: none;
  padding: .85rem 1rem 1rem;
  background: var(--rail);
  border-bottom: 1px solid var(--line);
  gap: .7rem;
}
.mobile-drawer:not([hidden]) { display: grid; }

main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.35rem 1.25rem 2.8rem;
  flex: 1;
  animation: fade-in .25s ease both;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  padding: .48rem 1rem;
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.07); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #e3c9a4, var(--gold-deep));
  border-color: var(--gold-deep);
  color: #1f1620;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger {
  border-color: rgba(224, 98, 88, 0.5);
  color: #ffb0a9;
  background: transparent;
}
.btn.tip {
  color: var(--tip);
  border-color: rgba(232, 184, 109, 0.4);
  background: rgba(232, 184, 109, 0.08);
  padding: .32rem .75rem;
  font-size: .78rem;
}
.btn.tip:hover { background: rgba(232, 184, 109, 0.16); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.connect {
  width: 100%;
  border-color: var(--gold);
  color: var(--gold);
}
.btn.connect .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}
.icon-btn { width: 2.2rem; height: 2.2rem; padding: 0; }

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

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .8rem 1rem;
  margin-bottom: 1.1rem;
}
.page-head h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.45rem, 3vw, 1.9rem);
  font-weight: 700;
  letter-spacing: .01em;
}
.page-head p {
  margin: .35rem 0 0;
  color: var(--text-dim);
  font-size: .95rem;
  line-height: 1.55;
  max-width: 36rem;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1.1rem;
  align-items: start;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .85rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: .35rem .8rem;
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: rgba(255,255,255,.14); }
.chip.is-active {
  background: rgba(155, 126, 200, 0.28);
  border-color: rgba(155, 126, 200, 0.45);
  color: #fff;
}

.feed { display: grid; gap: .65rem; }

.topic-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: .9rem;
  padding: .85rem .95rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
.topic-card:hover {
  color: inherit;
  border-color: rgba(216, 189, 152, 0.35);
  background: var(--surface-2);
  transform: translateY(-1px);
}
.topic-card h2 {
  margin: 0 0 .35rem;
  font-size: 1.02rem;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: .01em;
}
.topic-card .preview {
  margin: 0;
  color: var(--text-dim);
  font-size: .9rem;
  line-height: 1.5;
}
.topic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .7rem;
  margin-top: .55rem;
  color: var(--muted);
  font-size: .78rem;
  align-items: center;
}
.tag-pill {
  display: inline-flex;
  padding: .12rem .5rem;
  border-radius: 999px;
  background: rgba(155, 126, 200, 0.18);
  color: #d2c2ea;
  font-size: .72rem;
  font-weight: 600;
}

.topic-thumb {
  background-image: var(--thumb);
  background-size: var(--ts, 180%) auto;
  background-position: var(--tx, 50%) var(--ty, 40%);
  background-repeat: no-repeat;
  border-radius: 14px;
  border: 1px solid rgba(216, 189, 152, 0.22);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}
.topic-thumb-md {
  width: 92px;
  height: 92px;
}
.topic-thumb-lg {
  width: 120px;
  height: 120px;
  border-radius: 18px;
}

.thread-hero {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  align-items: start;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: .95rem;
  color: #1f1620;
  background: linear-gradient(145deg, var(--gold), #9b7ec8);
  flex-shrink: 0;
}
.avatar.sm { width: 34px; height: 34px; border-radius: 11px; font-size: .82rem; }

/* tip rail on home */

.tip-aside {
  position: sticky;
  top: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.tip-aside h2 {
  margin: 0 0 .15rem;
  font-size: .95rem;
  font-weight: 700;
}
.tip-aside .sub {
  margin: 0 0 .85rem;
  color: var(--muted);
  font-size: .75rem;
}
.tip-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
  margin-bottom: .85rem;
}
.tip-stat {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem .55rem;
}
.tip-stat .tok {
  font-size: .65rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}
.tip-stat .amt {
  font-size: .95rem;
  font-weight: 650;
  margin-top: .15rem;
}
.tip-list { display: grid; gap: .55rem; }
.tip-item {
  display: grid;
  gap: .15rem;
  padding: .55rem 0;
  border-top: 1px solid var(--line);
  font-size: .8rem;
}
.tip-item:first-child { border-top: 0; padding-top: 0; }
.tip-item .amt-line {
  color: var(--tip);
  font-weight: 700;
}
.tip-item a { color: var(--text-dim); }
.tip-item a:hover { color: var(--gold); }
.tip-aside .more {
  display: inline-block;
  margin-top: .75rem;
  font-size: .8rem;
  font-weight: 600;
}

/* ---------- topic / messages ---------- */

.thread-head {
  margin-bottom: 1rem;
  padding-bottom: .9rem;
  border-bottom: 1px solid var(--line);
}
.thread-head h1 {
  margin: .4rem 0 .35rem;
  font-family: var(--display);
  font-size: clamp(1.35rem, 2.8vw, 1.75rem);
  line-height: 1.3;
}
.back-link {
  display: inline-flex;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 600;
  margin-bottom: .35rem;
}
.back-link:hover { color: var(--text); }

.message-list {
  display: grid;
  gap: .15rem;
  margin-bottom: 1.1rem;
}
.message {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: .75rem;
  padding: .7rem .65rem;
  border-radius: 12px;
}
.message:hover { background: rgba(255, 255, 255, 0.03); }
.message-head {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .65rem;
  align-items: center;
  margin-bottom: .2rem;
}
.message-head-main {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .65rem;
  align-items: baseline;
  flex: 1;
  min-width: 0;
}
.message-name { font-weight: 700; font-size: .92rem; }
.message-time { color: var(--muted); font-size: .75rem; }
.message-addr {
  color: var(--muted);
  font-size: .72rem;
  background: rgba(255,255,255,.04);
  border-radius: 999px;
  padding: .05rem .45rem;
}
.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
  color: var(--text);
  font-size: .95rem;
}
.message-actions {
  flex-shrink: 0;
  margin-left: auto;
}
.message .btn.tip {
  opacity: .72;
}
.message:hover .btn.tip {
  opacity: 1;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
}
.composer h2 {
  margin: 0 0 .75rem;
  font-size: 1rem;
}
.form-grid { display: grid; gap: .85rem; }
.form-grid > .btn,
.form-grid .row .btn { justify-self: start; }
label {
  display: grid;
  gap: .35rem;
  font-size: .84rem;
  font-weight: 600;
  color: var(--text-dim);
}
label.row { font-weight: 500; }
input, textarea, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .7rem .8rem;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
}
input::placeholder, textarea::placeholder { color: rgba(141, 128, 159, 0.75); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(216, 189, 152, 0.55);
  box-shadow: 0 0 0 3px rgba(216, 189, 152, 0.12);
}
input[type="checkbox"] {
  width: 1rem; height: 1rem; padding: 0;
  accent-color: var(--gold-deep);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.row { display: flex; gap: .55rem; align-items: center; }

.empty {
  color: var(--muted);
  padding: 2rem 1rem;
  text-align: center;
  background: rgba(255,255,255,.02);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  line-height: 1.7;
}
.skeleton {
  height: 88px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(100deg, transparent 30%, rgba(255,255,255,.05) 50%, transparent 70%) 0 0 / 200% 100%,
    var(--surface);
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0, 0 0; } }

/* dialog */

dialog {
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 0;
  width: min(92vw, 400px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 5, 14, 0.65); backdrop-filter: blur(3px); }
.tip-form { display: grid; gap: .85rem; padding: 1.25rem; }
.tip-form h2 { margin: 0; font-family: var(--display); font-size: 1.15rem; }
.tip-form .row { justify-content: flex-end; }

.ledger-page .tip-stats { max-width: 420px; }
.ledger-list {
  display: grid;
  gap: .55rem;
  margin-top: 1rem;
}
.ledger-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem 1rem;
  padding: .9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.ledger-row .amt { color: var(--tip); font-weight: 700; }

@media (max-width: 980px) {
  .home-grid { grid-template-columns: 1fr; }
  .tip-aside { position: static; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .mobile-bar { display: flex; }
  main { padding: 1rem .9rem 2.4rem; }
  .stage {
    background-attachment: scroll;
    background-position: center top;
  }
  .topic-card { grid-template-columns: 72px 1fr; gap: .7rem; }
  .topic-thumb-md { width: 72px; height: 72px; }
  .thread-hero { grid-template-columns: 84px 1fr; gap: .75rem; }
  .topic-thumb-lg { width: 84px; height: 84px; border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
