/* ---------- 主題：淺色（預設） ---------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg2: #f4f4f5;
  --card: #ffffff;
  --line: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --invert-bg: #18181b;
  --invert-text: #ffffff;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --info-bg: #f4f4f5;
  --tab-active: #ffffff;
  --tenen: #b7791f;
  --kyokuho: #2563eb;
  --kyokuma: #c026d3;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
  --radius: 12px;
}

/* ---------- 主題：深色 ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a;
  --bg2: #18181b;
  --card: #111111;
  --line: #27272a;
  --text: #fafafa;
  --muted: #a1a1aa;
  --invert-bg: #fafafa;
  --invert-text: #0a0a0a;
  --green: #4ade80;
  --green-bg: rgba(74,222,128,.12);
  --red: #f87171;
  --red-bg: rgba(248,113,113,.12);
  --info-bg: #18181b;
  --tab-active: #3f3f46;
  --tenen: #fbbf24;
  --kyokuho: #60a5fa;
  --kyokuma: #e879f9;
  --shadow: 0 10px 30px rgba(0,0,0,.5);
}

/* ---------- 跟隨系統（沒有指定主題時） ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0a0a0a;
    --bg2: #18181b;
    --card: #111111;
    --line: #27272a;
    --text: #fafafa;
    --muted: #a1a1aa;
    --invert-bg: #fafafa;
    --invert-text: #0a0a0a;
    --green: #4ade80;
    --green-bg: rgba(74,222,128,.12);
    --red: #f87171;
    --red-bg: rgba(248,113,113,.12);
    --info-bg: #18181b;
  --tab-active: #3f3f46;
    --tenen: #fbbf24;
    --kyokuho: #60a5fa;
    --kyokuma: #e879f9;
    --shadow: 0 10px 30px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 18px; }

.brand { font-size: 26px; font-weight: 800; letter-spacing: .04em; }
.brand.small { font-size: 18px; }
.sub { color: var(--muted); margin: 0 0 20px; }

/* 表單 */
.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; outline: none;
}
input:focus, select:focus { border-color: var(--text); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 16px;
  color: var(--text); background: var(--bg2); transition: opacity .15s, transform .05s;
}
.btn:hover:not(:disabled) { opacity: .85; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--invert-bg); color: var(--invert-text); border-color: var(--invert-bg); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

.tabs { display: flex; gap: 4px; background: var(--bg2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.tab {
  flex: 1; font: inherit; font-size: 14px; color: var(--muted); background: transparent;
  border: 0; border-radius: 7px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--tab-active); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tabs.sm .tab { padding: 3px 10px; font-size: 13px; }

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

/* 登入頁 */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 22px; }
.auth-card .tabs { margin-bottom: 18px; }
.auth-theme { position: fixed; top: 16px; right: 16px; }

/* 主畫面 */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.me { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.me b { color: var(--text); }

.layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 20px;
  max-width: 1280px; margin: 0 auto; padding: 20px;
}
.side { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.lobby-head h2 { margin: 0; }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); grid-column: 1 / -1; }

/* 房間卡片 */
.room {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
.room::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent, var(--text)); }
.t-天元 { --accent: var(--tenen); }
.t-極法 { --accent: var(--kyokuho); }
.t-極媽 { --accent: var(--kyokuma); }
.room-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.raid { font-weight: 800; font-size: 18px; color: var(--accent, var(--text)); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.badge.open { color: var(--green); }
.badge.closed { color: var(--text); }
.badge.drawn { color: var(--muted); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.count { font-size: 22px; font-weight: 800; }
.count small { font-size: 13px; font-weight: 400; color: var(--muted); }

.result { padding: 8px 10px; border-radius: 8px; font-weight: 700; text-align: center; }
.result.lost { background: var(--red-bg); color: var(--red); }
.result.wait { background: var(--info-bg); color: var(--muted); }
.result.won { background: var(--green-bg); color: var(--green); }

.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: .05em; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row .btn { flex: 1; }

/* 房主控制面板 */
.host-panel h2 { display: flex; justify-content: space-between; align-items: center; }
.host-room { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.host-room:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.entrants { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 180px; overflow: auto; }
.entrants li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.entrants li.win { color: var(--green); font-weight: 700; }
.entrants .id { color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }

/* modal / toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.modal-box p { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--invert-bg); color: var(--invert-text);
  padding: 10px 18px; border-radius: 10px; z-index: 30; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast.err { background: var(--red); color: #fff; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .topbar { padding: 10px 16px; }
}
