/* 沿用「小寰的窩」www 的配色與字型 */
:root {
  --primary-color: #333333;
  --accent-color: #0066cc;
  --tea: #d97706;          /* 米博士暖橘 */
  --tea-dark: #b45309;
  --tea-ink: #78350f;
  --tea-wash: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  --tea-line: #fde68a;
  --bg-color: #f8f9fa;
  --card-bg: #ffffff;
  --text-color: #333333;
  --text-muted: #666666;
  --border-color: #e0e0e0;
  --danger: #b91c1c;
  --screen: #000000;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background: #b5874f;   /* 首頁 BBS 的奶茶黃；不動 --bg-color，其他元件不受影響 */
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent-color); outline-offset: 2px; }

/* ---------- 頂部列 ---------- */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.75rem; margin-right: auto; }
.avatar {  /* 與站台切換列「電子佈告欄」同一個圖示，維持一致 */
  width: 2.75rem; height: 2.75rem; border-radius: 0.85rem; flex: none;
  background: linear-gradient(160deg, #fff7e6, #f6dfb5);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 5px rgba(0, 0, 0, 0.08);
  display: grid; place-items: center; font-size: 1.6rem; line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { color: var(--text-muted); font-size: 0.8rem; }

/* 站台切換：Mac Dock 風格的小方塊，底下的小圓點表示「你在這裡」 */
.dock {
  display: flex; gap: 0.35rem; align-items: flex-start;
  /* 「你在這裡」的顏色：用本站方塊的顏色（BBS = 橘色），跟首頁的粉紅、MUD 的綠色區分 */
  --here: #f97316;
  --here-text: #c2410c;
  --here-glow: rgba(249, 115, 22, 0.28);
}
.dock-item {
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
  width: 5.4rem; padding: 0.25rem 0.1rem 0.45rem; border-radius: 10px;
  color: var(--text-muted); position: relative;
  transition: transform .18s ease, color .18s ease;
}
.dock-icon {
  width: 2.5rem; height: 2.5rem; border-radius: 0.8rem;
  display: grid; place-items: center; font-size: 1.45rem; line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 5px rgba(0, 0, 0, 0.08);
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.dock-label { font-size: 0.72rem; line-height: 1.2; white-space: nowrap; }
.t-www .dock-icon { background: linear-gradient(160deg, #fff0f5, #fbd3e0); }   /* 粉紅 */
.t-bbs .dock-icon { background: linear-gradient(160deg, #fff7e6, #f6dfb5); }   /* 橘色 */
.t-mud .dock-icon { background: linear-gradient(160deg, #eefbe9, #cfeec3); }   /* 綠色 */
.t-yt  .dock-icon { background: linear-gradient(160deg, #eaf4ff, #cfe4fb); }   /* 淺藍 */
.dock-item:hover { transform: translateY(-3px); color: var(--text-color); }
.dock-item:hover .dock-icon { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), 0 6px 12px rgba(0, 0, 0, 0.12); }
.dock-item.current { color: var(--here-text); font-weight: 600; }
.dock-item.current .dock-icon { box-shadow: inset 0 0 0 2px var(--here), 0 2px 6px var(--here-glow); }
.dock-item.current::after {
  content: ""; position: absolute; bottom: 0; left: 50%; width: 5px; height: 5px;
  margin-left: -2.5px; border-radius: 50%; background: var(--here);
}
/* 電子佈告欄的下拉：滑鼠移上去（或鍵盤選到、手機點一下）時，下方左右並排 [BBS連線] [跨站轉錄] */
.dock-group { position: relative; display: flex; }
.dock-pop {
  position: absolute; top: 100%; left: 50%; z-index: 30;
  display: flex; gap: 0.35rem; padding: 0.4rem; margin-top: 6px;
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
  opacity: 0; visibility: hidden; transform: translate(-50%, -4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
}
.dock-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }
.dock-group:hover .dock-pop, .dock-group:focus-within .dock-pop, .dock-group.open .dock-pop {
  opacity: 1; visibility: visible; transform: translate(-50%, 0);
}
.dock-pop a {
  white-space: nowrap; padding: 0.4rem 0.8rem; border-radius: 7px; font-size: 0.85rem;
  color: var(--text-color); border: 1px solid var(--border-color); background: var(--bg-color);
}
.dock-pop a:hover, .dock-pop a:focus-visible { border-color: var(--tea); color: var(--tea-dark); outline: none; }
.dock-pop a[aria-current="page"] { background: var(--tea); border-color: var(--tea); color: #fff; font-weight: 600; }

.menu-wrap { position: relative; }
.menu-btn {
  width: 40px; height: 40px; border-radius: 6px;
  border: 1px solid var(--border-color); background: var(--card-bg);
  font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.menu-btn[aria-expanded="true"] { border-color: var(--tea); color: var(--tea-dark); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 200px; padding: 0.4rem;
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 0.55rem 0.75rem; border: 0; border-radius: 6px; background: none; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--bg-color); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border-color); margin: 0.3rem 0; }

/* ---------- 主內容 ---------- */
.page { max-width: 1040px; margin: 0 auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }

.intro {
  background: var(--tea-wash); border: 1px solid var(--tea-line); border-radius: 8px;
  padding: 1rem 1.25rem; color: var(--tea-ink);
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.intro p { flex: 1 1 320px; }
.intro-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.notice {
  background: var(--card-bg); border: 1px solid var(--border-color); border-left: 4px solid var(--tea);
  border-radius: 8px; padding: 0.85rem 1rem; display: flex; gap: 1rem; align-items: flex-start;
}
.notice[hidden], .intro[hidden] { display: none; }
.notice-body { flex: 1; }
.notice-main { font-weight: 600; }
.notice-body p + p { color: var(--text-muted); font-size: 0.92rem; }
.notice-close { border: 0; background: none; cursor: pointer; color: var(--text-muted); padding: 0 0.25rem; }

/* ---------- 終端機卡片與分頁 ---------- */
.console { display: flex; flex-direction: column; }
.tabbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.5rem; }
.tabs { display: flex; gap: 0.25rem; }
.tabs [role=tab] {
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border-color); border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--bg-color); color: var(--text-muted);
  cursor: pointer; position: relative; top: 1px;
}
.tabs [role=tab]:hover { color: var(--text-color); }
.tabs [role=tab][aria-selected="true"] {
  background: var(--card-bg); color: var(--text-color); font-weight: 600;
  box-shadow: inset 0 3px 0 var(--tea);
}
/* 連線狀態直接放在奶茶黃底色上：文字用白色，圓點加白邊才看得清楚 */
.conn { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: #ffffff; padding-bottom: 0.4rem; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); }
.conn.on .dot { background: #16a34a; box-shadow: 0 0 0 2px #ffffff; }

.view {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0 8px 8px 8px;
}
.view[hidden] { display: none; }

.view-raw { padding: 0.5rem; position: relative; }
.screen-scroll { overflow-x: auto; background: var(--screen); border-radius: 6px; padding: 8px; }
.screen { width: max-content; margin: 0 auto; }
.screen .xterm { padding: 0; }
.screen .xterm-viewport { overflow-y: hidden !important; background: var(--screen) !important; }

.closed {
  position: absolute; inset: 0.5rem; border-radius: 6px;
  background: rgba(0, 0, 0, 0.72); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem;
}
.closed[hidden] { display: none; }

.vkeys { display: none; gap: 0.35rem; flex-wrap: wrap; padding-top: 0.5rem; }
.vkeys button {
  flex: 1 0 calc(20% - 0.35rem); min-height: 44px;
  border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-color);
  font-size: 0.95rem; cursor: pointer; touch-action: manipulation;
}
.vkeys button:active { background: #fef3c7; border-color: var(--tea); }
.vkeys .wide { font-weight: 600; }
.rotate-hint { display: none; color: var(--text-muted); font-size: 0.85rem; text-align: center; padding-top: 0.4rem; }
@media (max-width: 600px) and (orientation: portrait) { .rotate-hint { display: block; } }
@media (pointer: coarse), (max-width: 700px) { .vkeys { display: flex; } }

/* ---------- 表單 ---------- */
.view-form { padding: 1.5rem; }
.form { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.form.narrow { max-width: 420px; }
.form h2 { font-size: 1.35rem; }
.lead { color: var(--text-muted); margin-top: -0.5rem; }
fieldset { border: 1px solid var(--border-color); border-radius: 8px; padding: 1rem 1.1rem 1.1rem; display: flex; flex-direction: column; gap: 1rem; }
legend { padding: 0 0.4rem; font-weight: 600; }
.note { background: var(--tea-wash); border: 1px solid var(--tea-line); color: var(--tea-ink); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.92rem; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span, .choice-title { font-weight: 600; font-size: 0.95rem; }
input[type=text], input[type=password] {
  width: 100%; padding: 0.6rem 0.75rem; font: inherit;
  border: 1px solid #cfcfcf; border-radius: 6px; background: #fff;
}
input:focus-visible { outline: 3px solid rgba(0, 102, 204, 0.35); outline-offset: 0; border-color: var(--accent-color); }
input:disabled { background: var(--bg-color); color: #999; }
.hint { color: var(--text-muted); font-size: 0.85rem; }
.err { color: var(--danger); font-size: 0.88rem; min-height: 0; }
.err:empty { display: none; }

.choice { display: flex; flex-direction: column; gap: 0.35rem; }
.choice-input { margin-left: 1.6rem; width: calc(100% - 1.6rem) !important; }
.radio, .check { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.radio input, .check input { width: 1.1rem; height: 1.1rem; accent-color: var(--tea); flex: none; }

.form-error {
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
  border-radius: 6px; padding: 0.6rem 0.75rem;
}
.form-error[hidden] { display: none; }
.aside { color: var(--text-muted); font-size: 0.92rem; text-align: center; }
.link { border: 0; background: none; color: var(--accent-color); cursor: pointer; text-decoration: underline; }
.reg-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.6rem 1.1rem; min-height: 42px;
  border-radius: 6px; border: 1px solid transparent; cursor: pointer; font-weight: 600;
}
.btn-tea { background: var(--tea); color: #fff; box-shadow: 0 2px 6px rgba(217, 119, 6, 0.25); }
.btn-tea:hover { background: var(--tea-dark); }
.btn-tea:disabled { background: #e5a55a; cursor: progress; }
.btn-plain { background: var(--card-bg); border-color: var(--border-color); color: var(--text-color); }
.btn-plain:hover { border-color: #bdbdbd; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

/* ---------- 對話框 ---------- */
.dlg {
  border: 1px solid var(--border-color); border-radius: 10px; padding: 1.5rem;
  width: min(440px, calc(100vw - 2rem)); margin: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}
.dlg-wide { width: min(620px, calc(100vw - 2rem)); }
.dlg::backdrop { background: rgba(0, 0, 0, 0.35); }
.dlg form { display: flex; flex-direction: column; gap: 0.85rem; }
.dlg h2 { font-size: 1.2rem; }
.dlg h3 { font-size: 1rem; margin-top: 0.4rem; }
.dlg p { color: var(--text-color); }
#dlg-body { display: flex; flex-direction: column; gap: 0.5rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

.dlg-congrats { text-align: center; overflow: visible; }
.dlg-congrats::backdrop { background: rgba(20, 12, 0, 0.55); }
.dlg-congrats form { position: relative; z-index: 1; }
.dlg-congrats .fireworks { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; }
.congrats-mark { font-size: 2.6rem; line-height: 1; }
.congrats-id { color: var(--tea-dark); font-weight: 700; font-size: 1.1rem; }
.dlg-actions.center { justify-content: center; }

/* ===== 米博士開課頻道：半透明浮動影片視窗 ===== */
.rh-yt-float {
  position: fixed; left: 0; top: 0; z-index: 2147483000;
  width: 480px; height: 320px; min-width: 300px; min-height: 210px;
  max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  display: flex; flex-direction: column; overflow: hidden; resize: both;
  background: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.65); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  opacity: 0.85; transition: opacity 0.2s ease;
}
.rh-yt-float:hover, .rh-yt-float.dragging { opacity: 1; }
.rh-yt-head {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0.5rem 0.35rem 0.85rem;
  cursor: move; user-select: none; touch-action: none; color: #0C447C;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 0.85rem; line-height: 1.4;
}
.rh-yt-title { font-weight: 600; margin-right: auto; }
.rh-yt-go { color: #185FA5; text-decoration: none; font-size: 0.8rem; }
.rh-yt-go:hover { text-decoration: underline; }
.rh-yt-close {
  width: 26px; height: 26px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(255, 255, 255, 0.75); color: #333333; font: inherit; line-height: 1;
}
.rh-yt-close:hover { background: #ffffff; }
.rh-yt-frame { flex: 1; min-height: 0; margin: 0 8px 10px; border: 0; border-radius: 8px; display: block; background: #000; }
.rh-yt-float.dragging .rh-yt-frame { pointer-events: none; }
.rh-dock-item.rh-open, .dock-item.rh-open { color: #185FA5; font-weight: 600; }
.rh-dock-item.rh-open .rh-dock-icon, .dock-item.rh-open .dock-icon {
  box-shadow: inset 0 0 0 2px #378ADD, 0 2px 6px rgba(55, 138, 221, 0.28);
}
@media (max-width: 640px) {
  .rh-yt-float { width: calc(100vw - 16px); height: calc((100vw - 32px) * 9 / 16 + 48px); resize: none; }
}
@media (prefers-reduced-motion: reduce) { .rh-yt-float { transition: none; } }
/* 浮動影片視窗打開時：原本「你在這裡」暗掉，改由頻道按鈕亮起藍框和藍點 */
.rh-yt-on .rh-dock-item.current, .rh-yt-on .dock-item.current { color: #666666; font-weight: normal; }
.rh-yt-on .rh-dock-item.current .rh-dock-icon, .rh-yt-on .dock-item.current .dock-icon {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 5px rgba(0, 0, 0, 0.08);
}
.rh-yt-on .rh-dock-item.current::after, .rh-yt-on .dock-item.current::after { display: none; }
.rh-dock-item.rh-open::after, .dock-item.rh-open::after {
  content: ""; position: absolute; bottom: 0; left: 50%; width: 5px; height: 5px;
  margin-left: -2.5px; border-radius: 50%; background: #378ADD;
}
/* ===== 浮動影片視窗結束 ===== */

.link-tip {
  position: fixed; z-index: 30; max-width: 320px; padding: 0.3rem 0.6rem;
  background: #1f1f1f; color: #fff; border-radius: 6px; font-size: 0.8rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none;
}

.sink { position: absolute; width: 0; height: 0; border: 0; visibility: hidden; }

/* ---------- 手機 ---------- */
@media (max-width: 640px) {
  .topbar { padding: 0.6rem 0.8rem; gap: 0.6rem; }
  .brand { display: none; } /* 螢幕太窄：只留站台切換列和選單 */
  .dock { flex: 1 1 auto; min-width: 0; justify-content: space-between; gap: 0.2rem; }
  .dock-item { width: auto; flex: 1 1 0; min-width: 0; }
  .dock-group { flex: 1 1 0; min-width: 0; }
  .dock-group .dock-item { flex: 1 1 auto; }
  .dock-icon { width: 2.2rem; height: 2.2rem; font-size: 1.25rem; border-radius: 0.7rem; }
  .dock-label { font-size: 0.68rem; }
  .page { padding: 0.75rem; }
  .tabs [role=tab] { padding: 0.45rem 0.7rem; font-size: 0.92rem; }
  .conn #conn-text { display: none; }
  .view-form { padding: 1rem; }
  .view-raw { padding: 0.35rem; }
  .screen-scroll { padding: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .dock-item:hover { transform: none; }
}
