:root {
  --bg: #111214;
  --bg-2: #1a1b1e;
  --panel: #232428;
  --panel-2: #2b2d31;
  --border: #35373c;
  --text: #f2f3f5;
  --muted: #a4a8b0;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --red: #da373c;
  --yellow: #f0b232;
  --radius: 12px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, .btn:focus-visible { outline: 2px solid #a5acff; outline-offset: 2px; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 60; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; }
.skip-link:focus { top: 12px; }
main:focus { outline: none; }
img { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
code { font-family: Consolas, "Cascadia Code", monospace; }

/* ---------- 頂部導覽 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 64px;
  padding: 0 24px;
  background: rgba(17, 18, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand-logo {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #eb459e);
  font-size: 20px;
}
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topnav a:hover, .topnav a.active { color: var(--text); background: var(--panel); }

.user-area { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex-shrink: 0; }
.avatar.lg { width: 48px; height: 48px; }

/* ---------- 按鈕與表單 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border: 0; border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: background .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.success { background: var(--green); }
.btn.danger { background: transparent; color: #ff7a7e; box-shadow: inset 0 0 0 1px rgba(218, 55, 60, .6); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.lg { padding: 12px 24px; font-size: 16px; border-radius: 10px; }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.field small { color: var(--muted); font-size: 12px; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text);
  font: inherit; font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 100px; }
input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-grid .form-actions { margin-top: 0; }
.full { grid-column: 1 / -1; }
.stack > * + * { margin-top: 20px; }
.card p.muted { margin: 12px 0 0; }

/* ---------- 首頁 ---------- */

.hero {
  max-width: 960px;
  margin: 0 auto;
  padding: 96px 24px 48px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(36px, 6vw, 60px);
  font-weight: 900;
  background: linear-gradient(135deg, #fff 30%, #a5acff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { max-width: 620px; margin: 20px auto 32px; color: var(--muted); font-size: 18px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 24px 96px;
}
.container.narrow { max-width: 760px; padding-top: 0; padding-bottom: 8px; }
.status-card { text-align: left; }
.status-card .emoji { font-size: 36px; }
.status-card h2 { margin: 8px 0 12px; }
.status-card p, .status-card li { color: var(--muted); font-size: 15px; }
.status-card ul { padding-left: 1.3em; margin: 8px 0 16px; }
.status-card li { margin-bottom: 6px; }
.status-card code { padding: 1px 6px; border-radius: 4px; background: var(--bg-2); color: var(--text); font-size: 13px; word-break: break-all; }
.status-card .hero-actions { justify-content: flex-start; margin-top: 16px; }

.feature { padding: 24px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.feature .emoji { font-size: 32px; }
.feature h3 { margin: 12px 0 6px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- 伺服器列表 ---------- */

.container { max-width: 1100px; margin: 0 auto; padding: 40px 24px 80px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 28px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.server-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 28px 20px 20px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  text-align: center;
  transition: transform .15s, border-color .15s;
}
.server-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.server-card .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.server-card .btn { width: 100%; }
.guild-icon {
  display: grid; place-items: center;
  width: 80px; height: 80px;
  border-radius: 24px;
  background: var(--panel-2);
  font-size: 26px; font-weight: 800;
  object-fit: cover;
  flex-shrink: 0;
}
.guild-icon.sm { width: 40px; height: 40px; border-radius: 12px; font-size: 15px; }
.server-card.missing .guild-icon { filter: grayscale(1); opacity: .6; }

/* ---------- 伺服器管理版面 ---------- */

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 64px); }
.sidebar {
  position: sticky; top: 64px;
  height: calc(100vh - 64px);
  padding: 16px 12px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar-guild { display: flex; align-items: center; gap: 12px; padding: 8px; margin-bottom: 8px; }
.sidebar-guild .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-back { display: block; padding: 6px 10px; margin-bottom: 12px; color: var(--muted); font-size: 13px; border-radius: 6px; }
.sidebar-back:hover { color: var(--text); background: var(--panel); }
.sidebar-label { padding: 12px 10px 6px; font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: .04em; }
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
}
.side-link:hover { color: var(--text); background: var(--panel); }
.side-link.active { color: var(--text); background: var(--panel-2); }
.side-link .icon { width: 22px; text-align: center; }

.content { padding: 32px 40px 80px; min-width: 0; }
.content > * + * { margin-top: 20px; }

.card { padding: 24px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.card h2 { font-size: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat { padding: 20px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat .value { font-size: 30px; font-weight: 800; margin-top: 4px; }

.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: 10px; font-size: 14px; }
.alert.warn { background: rgba(240, 178, 50, .1); border: 1px solid rgba(240, 178, 50, .4); }
.alert.info { background: rgba(88, 101, 242, .1); border: 1px solid rgba(88, 101, 242, .4); }

.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.quick-link {
  display: flex; gap: 14px; align-items: center;
  padding: 16px;
  border-radius: 10px;
  background: var(--panel-2);
  transition: background .15s;
}
.quick-link:hover { background: var(--border); }
.quick-link .emoji { font-size: 26px; }
.quick-link .desc { color: var(--muted); font-size: 13px; }

/* ---------- 遊戲場次 ---------- */

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.live { background: rgba(35, 165, 90, .15); color: #57d98c; }
.badge.wait { background: rgba(88, 101, 242, .15); color: #a5acff; }
.badge.host { background: rgba(240, 178, 50, .15); color: var(--yellow); padding: 1px 8px; }
.muted { color: var(--muted); font-size: 14px; }

.session-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted a { color: inherit; text-decoration: underline dotted; }

.channel-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 16px; }
.channel-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px; font-weight: 600;
  text-decoration: none;
  transition: border-color .15s;
}
.channel-chip:hover { border-color: var(--accent); }
.channel-chip.missing { opacity: .5; text-decoration: line-through; }
.card .alert + .table-wrap, .card .alert + .empty { margin-top: 16px; }
.card-head + .alert { margin-top: -4px; }

.table-wrap { overflow-x: auto; margin: 0 -24px -24px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 10px 12px; text-align: left; color: var(--muted); font-size: 12px; font-weight: 800; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 24px; text-align: right; }
td select, td input { padding: 6px 8px; min-width: 110px; }
.seat { font-family: Consolas, monospace; font-weight: 800; color: var(--muted); }
.player { display: flex; align-items: center; gap: 10px; }
.nick-preview { padding: 3px 8px; border-radius: 6px; background: var(--bg-2); font-size: 13px; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .emoji { font-size: 40px; }

/* ---------- 暱稱設定 ---------- */

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.preview-list { display: flex; flex-direction: column; gap: 8px; }
.preview-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; background: var(--bg-2); }
.preview-item .nick { font-weight: 600; }
.preview-item .len { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ---------- Discord 訊息預覽 ---------- */

.discord-preview { padding: 16px; border-radius: 8px; background: #313338; }
.embed { max-width: 520px; padding: 12px 16px; border-radius: 4px; background: #2b2d31; border-left: 4px solid var(--accent); }
.embed-title { font-weight: 700; margin-bottom: 4px; }
.embed-desc { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.embed-footer { margin-top: 8px; font-size: 12px; color: var(--muted); }
.mention { padding: 0 2px; border-radius: 3px; background: rgba(88, 101, 242, .3); color: #c9cdfb; font-weight: 600; }

/* ---------- 提示訊息 ---------- */

.toasts { position: fixed; right: 24px; bottom: 24px; z-index: 50; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 48px)); }
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border-left: 4px solid var(--green);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  white-space: pre-line;
  font-size: 14px;
  animation: toast-in .2s ease-out;
}
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--yellow); }
.toast a { color: #a5acff; text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.loading { display: grid; place-items: center; min-height: 50vh; color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar nav { display: flex; gap: 4px; overflow-x: auto; }
  .sidebar-label { display: none; }
  .side-link { flex-shrink: 0; }
  .content { padding: 24px 16px 60px; }
  .topbar { gap: 12px; padding: 0 12px; }
  .topnav { gap: 0; overflow-x: auto; }
  .topnav a { padding: 6px 8px; font-size: 14px; white-space: nowrap; }
  .user-chip span { display: none; }
}

@media (max-width: 560px) {
  .brand > span:last-child { display: none; }
}
