:root {
  --bg: #f6f1e8;
  --panel: #fffdf9;
  --panel-solid: #fffdf9;
  --line: rgba(36, 28, 18, 0.12);
  --cyan: #17324a;
  --pink: #e07a2a;
  --yellow: #e07a2a;
  --purple: #17324a;
  --text: #1c1915;
  --muted: #6d645b;
  --dim: #8d847a;
  --danger: #c44536;
  --up: #d23b3b;
  --down: #1f8a4c;
  --sage: #d7ebe4;
  --navy: #17324a;
  --ink: #1c1915;
  --font: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: var(--font);
  --shadow: 0 12px 32px rgba(60, 40, 20, 0.06);
}

@view-transition {
  navigation: auto;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  line-height: 1.5;
  background-color: var(--bg);
}

/* A fixed layer instead of background-attachment: fixed, which forces a full repaint on every scroll. */
body::before {
  content: none;
}

::selection {
  background: #f3c9a0;
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

a {
  color: var(--navy);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(36, 28, 18, 0.16);
  border-radius: 999px;
  padding: 8px 16px;
  background: #fffdf9;
  color: var(--ink);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

button:hover:not(:disabled) {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.secondary {
  border-color: var(--pink);
  color: #fff;
  background: var(--pink);
}

button.secondary:hover:not(:disabled) {
  background: #c8661c;
  border-color: #c8661c;
  color: #fff;
}

button.link,
button.link:hover:not(:disabled) {
  background: none;
  border: 0;
  box-shadow: none;
  color: var(--cyan);
  padding: 4px 6px;
}

button.link:hover:not(:disabled) {
  text-decoration: underline;
}

button.link.danger,
button.link.danger:hover:not(:disabled) {
  color: var(--danger);
}

button.icon {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  padding: 6px 9px;
  font-size: 18px;
  line-height: 1.2;
}

input,
textarea {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  outline: none;
  border-radius: 12px;
}

input:focus,
textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(224, 122, 42, 0.18);
}

input::placeholder,
textarea::placeholder {
  color: var(--dim);
}

input[type='checkbox'] {
  accent-color: var(--pink);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 0;
  font-size: 14px;
}

.empty {
  color: var(--dim);
  text-align: center;
  padding: 24px 0;
  margin: 0;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: #fffdf9;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0;
  white-space: nowrap;
  color: var(--navy);
}

.brand:hover {
  text-decoration: none;
  color: var(--pink);
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.nav a {
  color: var(--ink);
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 15px;
}

.nav a:hover {
  color: var(--ink);
  background: rgba(36, 28, 18, 0.05);
  text-decoration: none;
}

.nav a.active {
  color: #fff;
  border-color: var(--pink);
  background: var(--pink);
}

.account {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-switch {
  display: flex;
  gap: 2px;
}

.lang-switch button {
  padding: 2px 7px;
  font-size: 12px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.lang-switch button.active {
  color: #fff;
  background: var(--pink);
  border-color: var(--pink);
}

.weather {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  cursor: default;
}

.weather:empty {
  display: none;
}

.weather-main {
  color: var(--text);
  font-weight: 700;
}

.weather-aqi {
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid currentColor;
}

.weather-aqi.good { color: var(--down); }
.weather-aqi.fair { color: #b86a12; }
.weather-aqi.bad { color: var(--danger); }

.login-link {
  color: #fff;
  background: var(--pink);
  border: 1px solid var(--pink);
  padding: 6px 16px;
  border-radius: 999px;
  white-space: nowrap;
}

.login-link:hover {
  background: #c8661c;
  border-color: #c8661c;
  color: #fff;
  text-decoration: none;
}

.user-btn,
.user-btn:hover:not(:disabled) {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  box-shadow: none;
  padding: 2px 4px;
  color: var(--text);
}

.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 130px;
  display: flex;
  flex-direction: column;
}

.user-menu button {
  background: none;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 8px 12px;
}

.user-menu button:hover:not(:disabled) {
  background: var(--sage);
  color: var(--ink);
  box-shadow: none;
}

/* ---------- Avatars ---------- */

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  background: var(--navy);
  border: 0;
}

.avatar.small {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

/* ---------- Pages ---------- */

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.page.narrow {
  max-width: 760px;
}

.page.wide {
  max-width: 1200px;
}

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

/* ---------- Ticker ---------- */

.ticker {
  overflow: hidden;
  white-space: nowrap;
  background: #efe8dc;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 28px;
  height: 28px;
  flex-shrink: 0;
}

.ticker-track {
  display: inline-flex;
  animation: ticker-scroll 30s linear infinite;
}

.ticker:hover .ticker-track {
  animation-play-state: paused;
}

@keyframes ticker-scroll {
  to {
    transform: translateX(-50%);
  }
}

.ticker-item {
  display: inline-flex;
  gap: 8px;
  padding: 0 22px;
  border-right: 1px solid var(--line);
}

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

.ticker-label {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  margin-left: 12px;
  color: #fff;
  background: var(--navy);
  font-weight: 700;
  font-size: 12px;
}

a.ticker-news {
  color: var(--text);
}

a.ticker-news:hover {
  color: var(--cyan);
  text-decoration: none;
}

.ticker-price {
  color: var(--text);
  font-weight: 700;
}

.ticker-item.up .ticker-price,
.ticker-item.up .ticker-change {
  color: var(--up);
}

.ticker-item.down .ticker-price,
.ticker-item.down .ticker-change {
  color: var(--down);
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track {
    animation: none;
  }
}

.hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  margin-bottom: 20px;
}

.quote-box,
.stock,
.feed,
.article-card,
.discussion,
.game-panel {
  background: var(--panel);
  border: 0;
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.quote-box {
  position: relative;
  overflow: hidden;
  padding: 28px 32px;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 28px;
  align-items: center;
}

.quote-box::before {
  content: none;
}

.quote-label {
  margin: 0 0 8px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--pink);
  letter-spacing: 0.04em;
  font-weight: 700;
}

.quote {
  margin: 0 0 12px;
  font-size: 30px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--ink);
}

.quote-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.quote-box .link {
  padding: 2px 0;
  font-family: var(--mono);
}

.excerpt {
  margin: 0;
  padding-left: 22px;
  border-left: 1px solid rgba(36, 28, 18, 0.12);
  display: flex;
  flex-direction: column;
  min-height: 100%;
  justify-content: center;
}

.excerpt .quote-label {
  color: var(--navy);
}

.excerpt-text {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  min-height: 5.25em;
}

.excerpt-disclaimer {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.excerpt-source {
  margin: 0 0 4px;
  align-self: flex-end;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font);
}

.excerpt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.vote-btn,
.vote-btn:hover:not(:disabled) {
  padding: 4px 12px;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: none;
}

.vote-btn:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--ink);
}

.vote-btn.active,
.vote-btn.active:hover:not(:disabled) {
  color: #fff;
  background: var(--navy);
  border-color: var(--navy);
}

#excerpt-down.active,
#excerpt-down.active:hover:not(:disabled) {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

.excerpt-nav {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.excerpt-position {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}

.stock {
  padding: 18px 18px 16px;
  background: var(--sage);
}

.stock {
  display: flex;
  flex-direction: column;
}

.stock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.stock-nav,
.stock-nav:hover:not(:disabled) {
  font-size: 22px;
  line-height: 1;
  padding: 0 8px;
  color: var(--yellow);
}

.stock-rows {
  flex: 1;
}

.stock-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 13px;
}

.stock-dots {
  display: flex;
  gap: 5px;
  flex: 1;
  flex-wrap: wrap;
}

.stock-dot,
.stock-dot:hover:not(:disabled) {
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: rgba(23, 50, 74, 0.2);
  box-shadow: none;
}

.stock-dot.active,
.stock-dot.active:hover:not(:disabled) {
  background: var(--navy);
}

.stock-foot .link {
  padding: 2px 4px;
  font-size: 13px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  flex: 1;
  min-width: 0;
}

.stock-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
}

.stock-result,
.stock-result:hover:not(:disabled) {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  text-align: left;
  color: var(--text);
  border-color: var(--line);
  background: #fff;
  box-shadow: none;
}

.stock-result:hover:not(:disabled) {
  border-color: var(--navy);
  color: var(--navy);
  background: #fff;
}

.stock-result-code {
  font-family: var(--mono);
  color: var(--muted);
}

.stock-title {
  margin: 0;
  font-weight: 800;
  color: var(--navy);
  font-family: var(--font);
  letter-spacing: 0;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'market price' 'market change';
  padding: 6px 0;
  border-top: 1px solid rgba(23, 50, 74, 0.12);
}

.stock-market {
  grid-area: market;
  color: var(--muted);
  font-size: 14px;
  align-self: center;
}

.stock-price {
  grid-area: price;
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 700;
  text-align: right;
}

.stock-change {
  grid-area: change;
  font-family: var(--mono);
  font-size: 13px;
  text-align: right;
}

/* A-share convention: red means up, green means down. */
.stock-row.up .stock-price,
.stock-row.up .stock-change {
  color: var(--up);
}

.stock-row.down .stock-price,
.stock-row.down .stock-change {
  color: var(--down);
}

.stock-time,
.stock-loading {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--dim);
  font-family: var(--mono);
}

/* ---------- Feed ---------- */

.feed {
  padding: 8px 20px 12px;
}

.feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}

.tab:hover:not(:disabled) {
  background: #fff;
  color: var(--ink);
  border-color: rgba(36, 28, 18, 0.2);
  box-shadow: none;
}

.tab.active,
.tab.active:hover:not(:disabled) {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

.custom-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
  font-family: var(--mono);
}

.feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed-item {
  display: flex;
  gap: 14px;
  padding: 14px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--line);
  border-radius: 12px;
  transition: background 0.15s;
}

.feed-item:hover {
  background: rgba(36, 28, 18, 0.03);
}

.feed-item:last-child {
  border-bottom: 0;
}

.rank {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 0;
  background: var(--sage);
  color: var(--navy);
  font-family: var(--mono);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feed-item:nth-child(-n + 3) .rank {
  color: #fff;
  background: var(--pink);
}

.feed-body {
  flex: 1;
  min-width: 0;
}

.feed-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.feed-title:hover {
  color: var(--pink);
}

.feed-desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.feed-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--dim);
}

.discuss-link {
  flex-shrink: 0;
  font-size: 13px;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--navy);
  background: #fff;
}

.discuss-link:hover {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  text-decoration: none;
}

/* ---------- 开喷 ---------- */

.rant {
  padding: 18px 18px 16px;
  background: var(--navy);
  color: #f6f1e8;
  border: 0;
  border-radius: 24px;
  box-shadow: none;
}

.rant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.rant-head h2 {
  margin: 0;
  font-size: 22px;
  font-family: var(--font);
  letter-spacing: 0;
  font-weight: 800;
  color: #fffdf9;
}

.rant-head button {
  padding: 6px 14px;
  background: #f6f1e8;
  color: var(--navy);
  border-color: #f6f1e8;
}

.rant-head button:hover:not(:disabled) {
  background: #fff;
  color: var(--navy);
  border-color: #fff;
}

.rant .empty,
.rant .thread-excerpt,
.rant .thread-meta {
  color: rgba(246, 241, 232, 0.72);
}

.rant .thread-title {
  color: #fffdf9;
}

.rant .thread-title:hover {
  color: #f3c9a0;
}

.rant .thread-item {
  border-bottom-color: rgba(255, 255, 255, 0.12);
}

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.thread-item {
  padding: 11px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.thread-item:last-child {
  border-bottom: 0;
}

.thread-title {
  display: block;
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

.thread-title:hover {
  color: var(--pink);
}

.thread-excerpt {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
  word-break: break-word;
}

.thread-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--dim);
}

.thread-meta .post-author {
  font-weight: 500;
}

.thread-replies {
  margin-left: auto;
}

.thread-more {
  display: block;
  margin: 6px auto 0;
}

.thread-text {
  margin: 14px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
}

.article-card .post-head {
  margin-top: 10px;
}

.reply-quote {
  display: block;
  margin: 6px 0 0;
  padding: 6px 10px;
  border-left: 2px solid var(--pink);
  background: rgba(224, 122, 42, 0.08);
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.reply-quote strong {
  color: var(--pink);
  font-weight: 600;
}

.reply-target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(224, 122, 42, 0.45);
  border-radius: 4px;
  font-size: 13px;
  color: var(--pink);
}

.reply-target span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Article & posts ---------- */

.back-link {
  display: inline-block;
  margin-bottom: 12px;
  font-family: var(--mono);
}

.article-card {
  padding: 20px 22px;
  margin-bottom: 16px;
}

.article-source {
  margin: 0 0 6px;
  color: var(--pink);
  font-size: 13px;
  font-family: var(--mono);
}

.article-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  word-break: break-word;
}

.article-desc {
  color: var(--muted);
  margin: 10px 0 0;
}

.article-links {
  display: flex;
  gap: 16px;
  margin: 12px 0 0;
  font-size: 14px;
}

.discussion {
  padding: 18px 22px;
}

.discussion h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--cyan);
  font-family: var(--mono);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.post-body {
  flex: 1;
  min-width: 0;
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.post-author {
  font-weight: 700;
  color: var(--navy);
}

.post-author.anonymous {
  color: var(--muted);
}

.post-time {
  color: var(--dim);
  font-size: 12px;
}

.post-head .link {
  margin-left: auto;
  font-size: 12px;
}

.post-text {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post-form textarea {
  resize: vertical;
  width: 100%;
}

.post-options {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.post-options input[name='name'] {
  width: 160px;
}

.post-options button {
  margin-left: auto;
}

.post-as {
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Login ---------- */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--cyan);
  padding: 28px 24px;
  border-radius: 6px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow);
  border-radius: 24px;
  border-color: transparent;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h1 {
  margin: 0 0 8px;
  text-align: center;
  font-size: 20px;
  font-family: var(--mono);
  color: var(--cyan);
  letter-spacing: 2px;
  letter-spacing: 0;
}

/* ---------- Chat ---------- */

body.chat-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  background: transparent;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.chat-title {
  padding: 14px 14px 10px;
  font-weight: 800;
  font-family: var(--font);
  letter-spacing: 0;
  color: var(--navy);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.load-more {
  display: block;
  margin: 0 auto 12px;
  font-size: 13px;
}

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.msg.mine {
  flex-direction: row-reverse;
}

.msg-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 75%;
  min-width: 0;
}

.msg.mine .msg-content {
  align-items: flex-end;
}

.meta {
  font-size: 12px;
  color: var(--muted);
  margin: 0 4px 3px;
}

.bubble {
  max-width: 100%;
  background: #fff;
  border: 0;
  padding: 9px 12px;
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.mine .bubble {
  background: var(--navy);
  color: #fffdf9;
  border-radius: 16px 4px 16px 16px;
  box-shadow: none;
}

.msg .bubble.image {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.bubble.image img {
  display: block;
  max-width: min(260px, 100%);
  max-height: 320px;
  border-radius: 6px;
  background: #1a1735;
  border: 1px solid var(--line);
}

.bubble.voice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}

.bubble.voice audio {
  height: 36px;
  max-width: 230px;
}

.duration {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.composer {
  border-top: 1px solid var(--line);
  background: #fffdf9;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.composer button[type='submit'],
#record-send {
  border-color: var(--pink);
  background: var(--pink);
  color: #fff;
  border-radius: 999px;
}

.composer-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.composer-row textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  overflow-y: hidden;
  min-height: 38px;
}

.status {
  font-size: 12px;
  color: var(--muted);
  padding: 0 2px 6px;
}

.recording {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
  animation: blink 1s infinite;
}

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

/* ---------- Games ---------- */

.game-panel {
  padding: 16px 20px 18px;
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.game-stats {
  display: flex;
  gap: 16px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
}

.game-stats strong {
  color: var(--navy);
  font-size: 18px;
  margin-left: 4px;
}

.game-board {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-board.tall {
  width: min(100%, 390px);
  aspect-ratio: 3 / 4;
}

.game-board.wide {
  width: 100%;
  aspect-ratio: 16 / 9;
}

.game-controls button {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.snake-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.grid-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  height: 100%;
  padding: 10px;
  background: #bbada0;
  border: 0;
  border-radius: 16px;
  box-shadow: none;
}

.grid-2048 .cell {
  position: relative;
  border-radius: 8px;
  background: rgba(238, 228, 218, 0.35);
  border: 0;
}

.tile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-family: var(--font);
  font-weight: 800;
  font-size: clamp(18px, 7vw, 34px);
  border: 0;
  background: #eee4da;
  color: #776e65;
  box-shadow: none;
}

.tile.v2 { background: #eee4da; color: #776e65; }
.tile.v4 { background: #ede0c8; color: #776e65; }
.tile.v8 { background: #f2b179; color: #f9f6f2; }
.tile.v16 { background: #f59563; color: #f9f6f2; }
.tile.v32 { background: #f67c5f; color: #f9f6f2; }
.tile.v64 { background: #f65e3b; color: #f9f6f2; }
.tile.v128 { background: #edcf72; color: #f9f6f2; font-size: clamp(16px, 6vw, 30px); }
.tile.v256 { background: #edcc61; color: #f9f6f2; font-size: clamp(16px, 6vw, 30px); }
.tile.v512 { background: #edc850; color: #f9f6f2; font-size: clamp(16px, 6vw, 30px); }
.tile.v1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(13px, 5vw, 26px); }
.tile.v2048,
.tile.vsuper {
  background: #edc22e;
  color: #f9f6f2;
  font-size: clamp(13px, 5vw, 26px);
  border: 0;
  box-shadow: none;
}

.tile.new {
  animation: tile-pop 0.18s ease-out;
}

.tile.merged {
  animation: tile-merge 0.18s ease-out;
}

@keyframes tile-pop {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
}

@keyframes tile-merge {
  50% {
    transform: scale(1.15);
  }
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  background: rgba(246, 241, 232, 0.88);
  color: var(--ink);
  backdrop-filter: blur(3px);
  border-radius: 6px;
}

.overlay-title {
  margin: 0;
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--navy);
  letter-spacing: 0;
}

.overlay-text {
  margin: 0 0 10px;
  color: var(--muted);
}

.overlay-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 44px);
  gap: 6px;
}

.dpad button {
  padding: 0;
  font-size: 16px;
}

.dpad [data-dir='up'] { grid-column: 2; grid-row: 1; }
.dpad [data-dir='left'] { grid-column: 1; grid-row: 2; }
.dpad [data-dir='down'] { grid-column: 2; grid-row: 2; }
.dpad [data-dir='right'] { grid-column: 3; grid-row: 2; }

.game-actions {
  display: flex;
  gap: 10px;
}

.game-hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--dim);
}

.game-stats .fullscreen-btn {
  padding: 4px 10px;
  font-size: 13px;
}

.dpad button.held {
  background: var(--sage);
  color: var(--navy);
  border-color: var(--sage);
}

.rotate-hint {
  display: none;
}

@media (pointer: coarse) {
  .dpad {
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(2, 54px);
    gap: 8px;
  }

  .dpad button {
    font-size: 20px;
  }

  .game-actions button {
    min-height: 48px;
  }

  .game-actions #jump-btn,
  .game-actions #fire-btn,
  .game-actions #ult-btn,
  .game-actions #drop-btn {
    min-width: 72px;
  }
}

.game-panel.no-dpad .dpad {
  display: none;
}

/* Full-screen play: the panel covers the viewport and the board grows to the largest size
   that keeps its aspect ratio (cq units are relative to .board-wrap). */
body.game-fullscreen {
  overflow: hidden;
  overscroll-behavior: none;
}

body.game-fullscreen .game-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body.game-fullscreen .game-head {
  margin-bottom: 8px;
}

body.game-fullscreen #game-tabs,
body.game-fullscreen .game-hint,
body.game-fullscreen .fullscreen-btn {
  display: none;
}

body:not(.game-fullscreen) #exit-fullscreen-btn {
  display: none;
}

body.game-fullscreen .game-stats {
  flex: 1;
  justify-content: space-between;
  align-items: center;
}

body.game-fullscreen .board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

body.game-fullscreen .game-board {
  width: min(100cqw, 100cqh);
  margin: 0;
}

body.game-fullscreen .game-board.tall {
  width: min(100cqw, 100cqh * 3 / 4);
}

body.game-fullscreen .game-board.wide {
  width: min(100cqw, 100cqh * 16 / 9);
}

body.game-fullscreen .game-controls {
  margin-top: 10px;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 12px;
}

body.game-fullscreen .game-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (orientation: portrait) {
  body.game-fullscreen:has(#board.wide) .rotate-hint {
    display: block;
    margin: 8px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--yellow);
  }
}

/* Landscape phones: the controls float over the sides of the board instead of taking a row. */
@media (orientation: landscape) and (max-height: 560px) {
  body.game-fullscreen .game-head {
    position: absolute;
    top: max(6px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 2;
    margin: 0;
    pointer-events: none;
  }

  body.game-fullscreen .game-stats {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  /* Wide games draw their own score in the corners. */
  body.game-fullscreen:has(#board.wide) .game-head {
    display: none;
  }

  body.game-fullscreen .game-controls {
    position: absolute;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 2;
    margin: 0;
    align-items: flex-end;
    pointer-events: none;
  }

  body.game-fullscreen .game-controls > * {
    pointer-events: auto;
  }

  body.game-fullscreen .game-actions {
    flex-direction: column-reverse;
    flex-wrap: nowrap;
    align-items: flex-end;
  }

  body.game-fullscreen .game-controls button {
    background: rgba(10, 9, 24, 0.55);
  }
}

.leaderboard-panel {
  margin-top: 16px;
  padding: 18px 22px;
  background: var(--panel);
  border: 0;
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.leaderboard-head h2 {
  margin: 0;
  font-size: 17px;
  font-family: var(--mono);
  letter-spacing: 1px;
  color: var(--navy);
  letter-spacing: 0;
  font-weight: 800;
}

.player-name {
  font-size: 14px;
  color: var(--muted);
}

.player-name input {
  width: 150px;
  padding: 5px 8px;
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
}

.board-row {
  display: grid;
  grid-template-columns: 30px 28px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  border-radius: 10px;
}

.board-row:last-child {
  border-bottom: 0;
}

.board-row.me {
  background: var(--sage);
  box-shadow: none;
}

.board-rank {
  font-family: var(--mono);
  font-weight: 800;
  text-align: center;
  color: var(--cyan);
}

.board-row:nth-child(1) .board-rank {
  color: var(--pink);
}

.board-row:nth-child(2) .board-rank,
.board-row:nth-child(3) .board-rank {
  color: var(--navy);
}

.board-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.guest-tag {
  flex-shrink: 0;
  font-size: 11px;
  padding: 0 6px;
  border: 1px solid var(--dim);
  border-radius: 999px;
  color: var(--muted);
}

.board-score {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 17px;
  color: var(--yellow);
}

.board-time {
  font-size: 12px;
  color: var(--dim);
  min-width: 72px;
  text-align: right;
}

/* ---------- Dialog ---------- */

dialog {
  border: 0;
  border-radius: 24px;
  padding: 22px;
  width: min(340px, 90vw);
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(28, 25, 21, 0.35);
  backdrop-filter: blur(2px);
}

dialog.wide-dialog {
  width: min(560px, 92vw);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

dialog textarea {
  resize: vertical;
}

dialog h2 {
  margin: 0;
  font-size: 18px;
  color: var(--cyan);
  font-family: var(--mono);
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Mobile ---------- */

/* ---------- Admin ---------- */

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-head h1 {
  margin: 0;
  font-family: var(--mono);
  color: var(--yellow);
  letter-spacing: 2px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card,
.admin-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 800;
  color: var(--navy);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.admin-panel {
  padding: 14px 16px;
  overflow-x: auto;
}

.admin-panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
  font-family: var(--mono);
  color: var(--pink);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 7px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.admin-table th {
  color: var(--dim);
  font-weight: 600;
}

.admin-table td.empty {
  text-align: center;
}

.ip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.bar {
  display: inline-block;
  width: 90px;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}

.bar-fill {
  display: block;
  height: 100%;
  background: var(--pink);
}

.badge {
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 11px;
  color: #fff;
  background: var(--pink);
  border-radius: 3px;
}

button.small {
  padding: 3px 10px;
  font-size: 12px;
}

.reset-result {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--yellow);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  white-space: normal;
}

.reset-result code {
  margin: 0 4px;
  padding: 2px 6px;
  font-size: 15px;
  color: var(--navy);
  background: rgba(224, 122, 42, 0.12);
  user-select: all;
}

@media (max-width: 1100px) {
  .weather-extra {
    display: none;
  }
}

@media (max-width: 720px) {
  .site-header {
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 8px 12px;
  }

  .weather {
    gap: 6px;
    font-size: 11px;
  }

  .quote-box {
    grid-template-columns: 1fr;
  }

  .excerpt {
    padding-left: 0;
    padding-top: 16px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .nav {
    order: 3;
    flex-basis: 100%;
  }

  .account {
    margin-left: auto;
  }

  .hero,
  .home-grid {
    grid-template-columns: 1fr;
  }

  .rant {
    order: 2;
  }

  .quote {
    font-size: 21px;
  }

  .feed,
  .article-card,
  .discussion,
  .game-panel {
    padding-left: 14px;
    padding-right: 14px;
  }

  .feed-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .game-controls {
    gap: 16px;
  }

  .leaderboard-panel {
    padding-left: 14px;
    padding-right: 14px;
  }

  .board-time {
    display: none;
  }

  .board-row {
    grid-template-columns: 26px 28px 1fr auto;
  }

  .chat-body {
    flex-direction: column;
  }

  .member-list {
    width: auto;
    max-height: 132px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

.chat {
  max-width: 1040px;
}

.chat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 0;
}

.chat-bar .chat-title {
  flex: 1;
  border-bottom: 0;
  text-align: left;
  padding: 10px 4px;
}

.chat-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.member-list {
  width: 210px;
  flex-shrink: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  padding: 14px 12px;
}

.member-list h2 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.member {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 14px;
}

.member-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence {
  margin-left: auto;
  font-size: 11px;
  color: var(--down);
}

.chat-lobby {
  width: min(680px, 100%);
  margin: 32px auto;
  padding: 0 16px 48px;
}

.chat-lobby h1 {
  margin: 0 0 16px;
  font-size: 28px;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-card,
.room-card:hover:not(:disabled) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  border-radius: 18px;
  padding: 16px 18px;
  background: #fffdf9;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.room-name {
  font-weight: 800;
  font-size: 18px;
}

.room-count {
  color: var(--muted);
  font-size: 13px;
}

.mask-line {
  display: block;
  height: 0.85em;
  margin: 0.4em 0;
  border-radius: 6px;
  background: currentColor;
  opacity: 0.28;
}

.mask-note {
  display: inline-block;
  margin-top: 4px;
  font-size: 13px;
}

.rant .mask-note {
  color: #f6f1e8;
}

.skin-choices {
  display: flex;
  gap: 10px;
}

.skin-choices button {
  flex: 1;
}

.skin-choices button.active,
.skin-choices button.active:hover {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

.room-add {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.room-add input {
  flex: 1;
  min-width: 0;
}

.room-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.room-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.room-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
