﻿/* ============================================================
   WANG 游戏厅 · 基础样式
   设计原则：扁平、克制的小圆角（4px）、无悬浮阴影、
   仅 1px 描边区分层次，深浅色跟随系统主题。
   ============================================================ */

:root {
  color-scheme: light dark;
  --bg: #eef1f3;
  --surface: #f8fafb;
  --surface-2: #f1f4f5;
  --surface-3: #e2e7ea;
  --table: #d7dde1;
  --line: #adb7bd;
  --border: #cbd3d8;
  --border-strong: #aab5bc;
  --text: #20262b;
  --muted: #66727a;
  --text-2: #3e4950;
  --text-3: #66727a;

  --accent: #35414a;
  --accent-hover: #263138;
  --accent-soft: #dce2e6;
  --accent-text: #263138;
  --on-accent: #f4f7f8;

  --danger: #d64545;
  --danger-hover: #b93333;
  --danger-soft: #faeaea;
  --warn: #b97a0e;
  --warn-soft: #faf0dc;
  --info: #2b6cb0;
  --info-soft: #e6effb;

  --r: 3px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "Bahnschrift Condensed", "Arial Narrow", var(--font);
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111518;
    --surface: #181d21;
    --surface-2: #20262b;
    --surface-3: #2a3237;
    --table: #252c31;
    --line: #465159;
    --border: #364047;
    --border-strong: #53616a;
    --text: #edf1f3;
    --muted: #9ca8af;
    --text-2: #cbd3d8;
    --text-3: #9ca8af;

    --accent: #d8e0e4;
    --accent-hover: #eef2f4;
    --accent-soft: #30393f;
    --accent-text: #edf1f3;
    --on-accent: #182025;

    --danger: #e4706f;
    --danger-hover: #ef8382;
    --danger-soft: #351c1e;
    --warn: #e0a23c;
    --warn-soft: #352a12;
    --info: #6ba7e8;
    --info-soft: #182a40;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  letter-spacing: 0;
}

::selection { background: var(--accent-soft); }

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

h1, h2, h3 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--text-3); font-size: 13px; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-family: var(--display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
}
.brand:hover { text-decoration: none; }
.brand-dot { color: var(--muted); }
.brand-sub { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 6px; }
.topbar-nav { display: flex; align-items: center; gap: 10px; }
.top-nick {
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: var(--r);
}

/* ---------------- 布局 ---------------- */
.view {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}

.landing-intro { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 18px 0 16px; border-bottom: 1px solid var(--line); }
.landing-intro h1 { margin: 0; font-family: var(--display); font-size: 28px; font-weight: 600; }
.section-index { margin: 0 0 4px; color: var(--muted); font: 11px/1.2 var(--mono); letter-spacing: 0.08em; }
.landing-status, .connection-state { display: inline-flex; align-items: center; gap: 7px; margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-mark { width: 6px; height: 6px; border-radius: 50%; background: #8a6a21; box-shadow: 0 0 0 2px color-mix(in srgb, #8a6a21 20%, transparent); }
.connection-state[data-state="connected"] .status-mark { background: #27894d; box-shadow: 0 0 0 2px color-mix(in srgb, #27894d 20%, transparent); }
.connection-state[data-state="disconnected"] .status-mark { background: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 20%, transparent); }
.game-directory { border-bottom: 1px solid var(--line); }
.directory-head, .catalog-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 90px; align-items: center; }
.directory-head { padding: 8px 12px; color: var(--muted); font: 10px/1.4 var(--mono); text-transform: uppercase; }
.catalog-row { width: 100%; min-height: 44px; padding: 8px 12px; border: 0; border-top: 1px solid var(--border); border-radius: 0; color: var(--text); background: transparent; font: inherit; text-align: left; cursor: pointer; transition: background-color 160ms ease, transform 140ms var(--ease-out); }
.catalog-row:hover { background: var(--surface); }
.catalog-row:active { transform: scale(0.995); }
.catalog-name { font-weight: 600; }
.catalog-count, .catalog-state { color: var(--muted); font: 12px/1.3 var(--mono); }
.catalog-state::before { content: ''; display: inline-block; width: 5px; height: 5px; margin-right: 7px; border-radius: 50%; background: #27894d; vertical-align: 1px; }
.landing-actions { display: grid; grid-template-columns: minmax(250px, 0.8fr) minmax(250px, 0.8fr) minmax(320px, 1.4fr); border-bottom: 1px solid var(--line); }
.action-section { min-width: 0; padding: 20px; border-right: 1px solid var(--line); }
.action-section:first-child { padding-left: 0; }
.action-section:last-child { border-right: 0; padding-right: 0; }
.empty-state { margin: 18px 0; color: var(--muted); font-size: 13px; }

/* ---------------- 面板 ---------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; }

/* ---------------- 表单 ---------------- */
.form label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 14px;
}
.form label > input,
.form label > select {
  display: block;
  margin-top: 5px;
}
input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
  border-color: var(--accent);
}
input::placeholder { color: var(--text-3); }
.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
}
.check input { width: auto; margin-top: 2px; accent-color: var(--accent); }

.hint { color: var(--text-3); font-size: 13px; margin: 10px 0 0; }

/* ---------------- 按钮 ---------------- */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform 160ms var(--ease-out), background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
.btn:active:not(:disabled) { background: var(--surface-3); transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------------- 徽标 ---------------- */
.badge {
  display: inline-block;
  font-size: 12px;
  line-height: 1;
  padding: 4px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  color: var(--text-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge-accent { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; }
.badge-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.badge-warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge-muted { color: var(--text-3); background: transparent; border-color: var(--border); }

/* ---------------- 房间列表 ---------------- */
.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 8px;
  background: var(--surface);
}
.room-list li:hover { border-color: var(--border-strong); background: var(--surface-2); }
.room-list .rl-name { font-weight: 600; }
.room-list .rl-meta { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13px; }

/* ---------------- 房间页 ---------------- */
.room-head { position: relative; z-index: 2; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.room-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.room-meta h1 { margin: 0; font-size: 20px; }
.code-chip {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 2px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--text);
}
.code-chip:hover { border-color: var(--text); color: var(--text); }
.connection-state { margin-left: auto; }
.chat-toggle { min-width: 84px; }

.room-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}
.room-content { min-width: 0; min-height: calc(100svh - 108px); padding-top: 14px; }
.room-body.chat-collapsed { gap: 0; }
.room-body.chat-collapsed .chat-panel { width: 0; min-width: 0; opacity: 0; visibility: hidden; pointer-events: none; border-width: 0; }

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

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 10px;
}
.player-tile {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.player-tile.self { border-color: var(--accent); background: var(--accent-soft); }
.player-tile:hover { border-color: var(--text-3); }
.player-tile .pt-top { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--r);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--on-accent);
  flex: none;
}
.player-tile .pt-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-tile .pt-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ready-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.ready-dot.yes { background: var(--accent); }
.ready-dot.no { background: var(--text-3); }
.tag {
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.game-card-list { display: flex; flex-direction: column; gap: 8px; }
.game-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: var(--text);
  transition: border-color 160ms ease, background-color 160ms ease;
}
.game-card:hover:not(:disabled) { border-color: var(--text); background: var(--surface-2); }
.game-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.game-card .gc-name { font-weight: 600; font-size: 14px; }
.game-card .gc-meta { font-size: 12px; color: var(--text-3); }

.rules-box {
  margin-top: 14px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 13px;
  color: var(--text-2);
}
.rules-box ul { margin: 8px 0 0; padding-left: 18px; }
.rules-box li { margin-bottom: 4px; }

.control-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- 聊天 ---------------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r);
  width: 286px;
  min-width: 286px;
  background: var(--surface);
  height: calc(100vh - 140px);
  min-height: 320px;
  position: sticky;
  top: 70px;
  overflow: hidden;
  transition: opacity 160ms ease, transform 180ms var(--ease-out);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 0 10px 0 12px; border-bottom: 1px solid var(--border); color: var(--muted); font: 11px/1 var(--mono); }
.chat-close { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 2px; color: var(--muted); background: transparent; font-size: 18px; cursor: pointer; }
.chat-close:hover { color: var(--text); background: var(--surface-2); }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-msg { line-height: 1.5; }
.chat-msg .cm-name { font-weight: 600; margin-right: 6px; }
.chat-msg.cm-system { color: var(--text-3); font-size: 12px; }
.chat-msg.cm-guess {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  padding: 3px 8px;
  margin: 3px 0;
  color: var(--accent-text);
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.chat-form input { flex: 1; }
.chat-form .btn { flex: none; }

/* ---------------- Toast ---------------- */
.toast-root {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 12px 26px rgba(10, 24, 18, 0.17);
  animation: toast-in 0.28s var(--ease-out);
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--accent); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .landing-actions { grid-template-columns: 1fr 1fr; }
  .action-section:nth-child(2) { border-right: 0; padding-right: 0; }
  .rooms-panel { grid-column: 1 / -1; padding-left: 0; border-top: 1px solid var(--line); }
  .lobby-grid { grid-template-columns: 1fr; }
  .room-body { grid-template-columns: 1fr; }
  .chat-panel { position: fixed; inset: auto 0 0; z-index: 120; width: 100%; min-width: 0; height: min(62svh, 520px); min-height: 280px; border-width: 1px 0 0; border-radius: 3px 3px 0 0; box-shadow: 0 -12px 32px rgba(0,0,0,0.16); transform: translateY(100%); opacity: 0; visibility: hidden; transition: transform 240ms var(--ease-out), opacity 160ms ease, visibility 0s linear 240ms; }
  .chat-panel.is-open { transform: translateY(0); opacity: 1; visibility: visible; transition-delay: 0s; }
  .room-body.chat-collapsed .chat-panel { width: 100%; min-width: 0; border-width: 1px 0 0; }
}

@media (max-width: 640px) {
  .view { padding-inline: 12px; }
  .topbar-inner { padding-inline: 12px; }
  .landing-intro { align-items: center; }
  .landing-actions { grid-template-columns: 1fr; }
  .action-section, .action-section:first-child, .action-section:nth-child(2), .action-section:last-child { padding: 18px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .rooms-panel { grid-column: auto; border-top: 0; }
  .directory-head, .catalog-row { grid-template-columns: minmax(0, 1fr) 58px 60px; padding-inline: 8px; }
  .room-meta { gap: 7px; }
  .connection-state { margin-left: 0; font-size: 11px; }
  .room-list li { align-items: flex-start; flex-wrap: wrap; }
  .room-list .rl-meta { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ---------------- 私人牌室壳层 ---------------- */
:root {
  --room-perimeter: var(--bg);
  --room-chrome: var(--surface);
  --room-table: var(--table);
  --room-table-edge: var(--border-strong);
  --room-control: var(--surface-2);
}

body[data-view="room"] { background: var(--room-perimeter); }
body[data-view="room"] .topbar { display: none; }
body[data-view="room"] #view-room {
  width: 100%;
  max-width: none;
  min-height: 100svh;
  padding: 0;
}
body[data-view="room"] .room-head {
  min-height: 58px;
  padding: 9px 18px;
  background: var(--room-chrome);
  border-bottom-color: var(--line);
}
body[data-view="room"] .room-meta { min-height: 40px; flex-wrap: nowrap; }
.room-brand {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font: 12px/1 var(--mono);
  white-space: nowrap;
}
.room-brand span { color: var(--text); font-weight: 700; }
.room-brand b { color: var(--text); font-weight: 500; }
body[data-view="room"] .room-meta h1 {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body[data-view="room"] .code-chip,
body[data-view="room"] .badge {
  background: transparent;
}
body[data-view="room"] .leave-room-btn {
  border-color: color-mix(in srgb, var(--danger) 58%, var(--line));
  color: var(--danger);
}

body[data-room-scene="game"] .room-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  gap: 0;
  align-items: stretch;
}
body[data-room-scene="game"] .room-content {
  height: calc(100svh - 58px);
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
body[data-room-scene="game"] .chat-panel {
  position: relative;
  top: auto;
  width: 286px;
  min-width: 286px;
  height: calc(100svh - 58px);
  min-height: 0;
  border-width: 0 0 0 1px;
  border-radius: 0;
  background: var(--room-chrome);
}
body[data-room-scene="game"] .chat-head {
  min-height: 42px;
  padding-inline: 14px 8px;
  letter-spacing: 0;
}
body[data-room-scene="game"] .chat-form { background: var(--room-chrome); }

body[data-room-scene="lobby"] .room-body {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px;
}
body[data-room-scene="lobby"] .panel {
  background: color-mix(in srgb, var(--room-table) 74%, var(--room-chrome));
}
body[data-room-scene="lobby"] .avatar {
  color: var(--text) !important;
  background: transparent !important;
  border: 1px solid var(--line);
}

@media (max-width: 900px) {
  body[data-view="room"] .room-head { min-height: 52px; padding: 6px 10px; }
  body[data-view="room"] .room-meta { min-height: 40px; gap: 6px; }
  body[data-view="room"] .room-meta h1 { max-width: 34vw; font-size: 16px; }
  body[data-view="room"] #room-vis,
  body[data-view="room"] #room-count { display: none; }
  body[data-room-scene="game"] .room-body { display: block; }
  body[data-room-scene="game"] .room-content { height: calc(100svh - 52px); }
  body[data-room-scene="game"] .chat-panel {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    min-width: 0;
    height: min(62svh, 520px);
    min-height: 280px;
    border-width: 1px 0 0;
    transform: translateY(100%);
  }
  body[data-room-scene="game"] .chat-panel.is-open { transform: translateY(0); }
}

@media (max-width: 540px) {
  body[data-view="room"] .room-brand { padding-right: 7px; }
  body[data-view="room"] .room-meta h1 { display: none; }
  body[data-view="room"] #room-game-badge { display: none; }
  body[data-view="room"] .connection-label { display: none; }
  body[data-view="room"] .connection-state { margin-left: auto; }
  body[data-view="room"] .chat-toggle { min-width: 58px; padding-inline: 8px; }
  body[data-view="room"] .leave-room-btn { padding-inline: 8px; }
}
