/* ============================================================
   theme.css —— UI 主题 + 移动端适配
   通过 build.mjs 内嵌进 Worker，由 index.html 在 style.css 之后引入。
   主题通过 <html data-theme="..."> 切换，仅覆盖 CSS 变量与少量硬编码表面。
   ============================================================ */

/* ---------- 1. 主题变量 ---------- */
/* 经典（默认红金）—— 与 style.css 的 :root 一致，便于在切换时还原 */
[data-theme="classic"]{
  --bg:#8e1116; --bg-2:#7c0f14;
  --felt:#2f9455; --felt-2:#1f7a44; --felt-3:#145a32; --felt-hi:#4cb271;
  --rail:#f2dca4;
  --panel:rgba(255,252,243,.94); --panel-2:rgba(255,250,240,.97);
  --line:rgba(150,108,44,.22); --line-2:rgba(212,152,62,.55);
  --gold:#d98f1f; --gold-2:#b06f10; --gold-3:#ffd98a;
  --text:#43301a; --muted:#8a7350;
  --pos:#e23c3c; --neg:#1fa856; --accent:#e8762a; --danger:#e23c3c;
  --cta-hi:#ff8a4d; --cta:#e8482f; --cta-lo:#b02a1a;
  --radius:16px; --shadow:0 16px 38px rgba(140,90,20,.22);
  --lobby-grad:linear-gradient(180deg,#cf2c24,#a5161a 44%,#7c0f14);
  --card-bg:linear-gradient(165deg,#680e0ec7,#480808b3);
  --card-shadow:0 8px 20px #38060466,inset 0 1px #ffdc9638;
  --card-fg:#ffe9bd; --card-sub:rgba(255,226,180,.72); --card-border:rgba(255,206,110,.55);
  --chip-bg:linear-gradient(180deg,#4e0a0aa8,#680e0e85);
  --bar-bg:linear-gradient(180deg,#921218f7,#700d12eb); --bar-fg:#ffe9bd;
  --glass:rgba(8,52,26,.62); --glass-border:rgba(255,232,180,.35);
  --accent-text:#ffd98a;
}
/* 暗夜（黑金） */
[data-theme="dark"]{
  --bg:#14151a; --bg-2:#0e0f13;
  --felt:#1f8a55; --felt-2:#176b42; --felt-3:#0f4e30; --felt-hi:#3fbf7e;
  --rail:#cbb486;
  --panel:rgba(30,32,40,.95); --panel-2:rgba(36,38,48,.97);
  --line:rgba(255,255,255,.12); --line-2:rgba(240,200,120,.5);
  --gold:#e9b84a; --gold-2:#c79221; --gold-3:#ffe6a8;
  --text:#e9e7e1; --muted:#9a958c;
  --pos:#ff6b6b; --neg:#4fd98a; --accent:#f0954a; --danger:#ff5b5b;
  --cta-hi:#ffa866; --cta:#e8652f; --cta-lo:#9c3318;
  --radius:16px; --shadow:0 16px 38px rgba(0,0,0,.5);
  --lobby-grad:linear-gradient(180deg,#23252e,#16171d 44%,#0c0d11);
  --card-bg:linear-gradient(165deg,#262833e6,#181a21d9);
  --card-shadow:0 8px 20px rgba(0,0,0,.5),inset 0 1px rgba(255,255,255,.05);
  --card-fg:#f3ead2; --card-sub:rgba(243,234,210,.72); --card-border:rgba(240,200,120,.4);
  --chip-bg:linear-gradient(180deg,#2a2c36d0,#1b1d24c0);
  --bar-bg:linear-gradient(180deg,#262833e6,#16171dd9); --bar-fg:#f3ead2;
  --glass:rgba(22,24,31,.72); --glass-border:rgba(255,255,255,.14);
  --accent-text:#ffd98a;
}
/* 清新（浅色） */
[data-theme="light"]{
  --bg:#eef1f7; --bg-2:#e2e7f0;
  --felt:#3aa56a; --felt-2:#2f8c58; --felt-3:#236b43; --felt-hi:#5cc488;
  --rail:#caa84e;
  --panel:rgba(255,255,255,.97); --panel-2:rgba(255,255,255,.99);
  --line:rgba(60,70,95,.16); --line-2:rgba(210,160,60,.6);
  --gold:#c8901f; --gold-2:#a87410; --gold-3:#ffe1a0;
  --text:#2a2f3a; --muted:#6b7280;
  --pos:#e23c3c; --neg:#1a9c52; --accent:#ef7a2e; --danger:#e23c3c;
  --cta-hi:#ff9a5e; --cta:#ee5a36; --cta-lo:#c23a1e;
  --radius:16px; --shadow:0 16px 38px rgba(60,70,95,.18);
  --lobby-grad:linear-gradient(180deg,#ffffff,#f1f4fa 44%,#e2e7f0);
  --card-bg:linear-gradient(165deg,#ffffffe6,#f0f3f9cc);
  --card-shadow:0 8px 20px rgba(60,70,95,.16),inset 0 1px #fff;
  --card-fg:#3a2f1a; --card-sub:rgba(58,47,26,.7); --card-border:rgba(210,160,60,.55);
  --chip-bg:linear-gradient(180deg,#ffffffe0,#f4f6fbc0);
  --bar-bg:linear-gradient(180deg,#ffffffe8,#eef1f7ea); --bar-fg:#3a2f1a;
  --glass:rgba(255,255,255,.78); --glass-border:rgba(60,70,95,.18);
  --accent-text:#b8860b;
}
/* 海洋（蓝） */
[data-theme="ocean"]{
  --bg:#0f2a4a; --bg-2:#0a1f38;
  --felt:#1f7e8c; --felt-2:#14606c; --felt-3:#0c4651; --felt-hi:#46c2d4;
  --rail:#bfe3ef;
  --panel:rgba(238,248,252,.95); --panel-2:rgba(245,251,254,.97);
  --line:rgba(120,180,210,.28); --line-2:rgba(120,210,240,.6);
  --gold:#f0c24a; --gold-2:#c89a1c; --gold-3:#ffe9a8;
  --text:#1d3346; --muted:#5f7d92;
  --pos:#e23c3c; --neg:#1cae6a; --accent:#1fa6c4; --danger:#e23c3c;
  --cta-hi:#5fd0e6; --cta:#1f9fc4; --cta-lo:#137a98;
  --radius:16px; --shadow:0 16px 38px rgba(8,30,55,.4);
  --lobby-grad:linear-gradient(180deg,#1b4a7e,#123a64 44%,#0a1f38);
  --card-bg:linear-gradient(165deg,#10365ec7,#0a2444b3);
  --card-shadow:0 8px 20px #03101fee,inset 0 1px #9fd4ee38;
  --card-fg:#eaf6ff; --card-sub:rgba(191,227,242,.75); --card-border:rgba(120,210,240,.55);
  --chip-bg:linear-gradient(180deg,#143a64a8,#0a244485);
  --bar-bg:linear-gradient(180deg,#143a64f7,#0a2444eb); --bar-fg:#eaf6ff;
  --glass:rgba(10,36,68,.62); --glass-border:rgba(150,220,240,.35);
  --accent-text:#ffe9a8;
}
/* 森林（绿） */
[data-theme="forest"]{
  --bg:#1c3a22; --bg-2:#143019;
  --felt:#2f9455; --felt-2:#1f7a44; --felt-3:#145a32; --felt-hi:#4cb271;
  --rail:#d8e9b0;
  --panel:rgba(244,250,238,.95); --panel-2:rgba(248,252,244,.97);
  --line:rgba(80,140,80,.26); --line-2:rgba(150,210,90,.6);
  --gold:#e7b53a; --gold-2:#bb8e1c; --gold-3:#ffe7a0;
  --text:#233018; --muted:#5f7a4e;
  --pos:#e23c3c; --neg:#1c9c52; --accent:#e8902a; --danger:#e23c3c;
  --cta-hi:#ffae5e; --cta:#e07a2f; --cta-lo:#a8521a;
  --radius:16px; --shadow:0 16px 38px rgba(10,30,12,.4);
  --lobby-grad:linear-gradient(180deg,#2f6b3a,#235029 44%,#143019);
  --card-bg:linear-gradient(165deg,#1e4a28c7,#143019b3);
  --card-shadow:0 8px 20px #051a0fee,inset 0 1px #c8e89a38;
  --card-fg:#eef7e0; --card-sub:rgba(207,230,189,.75); --card-border:rgba(150,210,90,.55);
  --chip-bg:linear-gradient(180deg,#1e4a28a8,#14301985);
  --bar-bg:linear-gradient(180deg,#1e4a28f7,#143019eb); --bar-fg:#eef7e0;
  --glass:rgba(14,40,20,.62); --glass-border:rgba(180,220,140,.35);
  --accent-text:#ffe7a0;
}

/* ---------- 2. 表面覆盖（任何主题均应用变量） ---------- */
[data-theme] .lobby-bg{background:var(--lobby-grad)}
[data-theme] .mode-card{background:var(--card-bg);border-color:var(--card-border);box-shadow:var(--card-shadow);color:var(--card-fg)}
[data-theme] .mode-card__title{color:var(--card-fg)}
[data-theme] .mode-card__desc{color:var(--card-sub)}
[data-theme] .player-chip{background:var(--chip-bg)}
[data-theme] .casual-bar{background:var(--bar-bg);color:var(--bar-fg)}
[data-theme] .casual-bar__title{color:var(--bar-fg)}
[data-theme] .topbar,
[data-theme] .seat--side,
[data-theme] .counter,
[data-theme] .myinfo,
[data-theme] .teammate{background:var(--glass);border-color:var(--glass-border)}
[data-theme] .player-chip__name,
[data-theme] .player-chip__beans{color:var(--bar-fg)}
[data-theme] .section-title,
[data-theme] .room-tip,
[data-theme] .strength-chip,
[data-theme] .sub{color:var(--accent-text);border-color:var(--card-border)}
[data-theme] .section-title::after,
[data-theme] .section-title::before{background:var(--card-border)}

/* 浅色主题下部分金字的对比度修正 */
[data-theme="light"] .player-chip__beans{color:var(--gold-2)}
[data-theme="light"] .seat__name{color:#fff;text-shadow:0 1px 2px rgba(0,30,12,.4)}
[data-theme="light"] .seat__count{color:#7a4a00}

/* ---------- 3. 通用表单控件主题化 ---------- */
input, textarea, select{
  font-family:inherit;
  background:var(--panel-2);
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:10px 12px;
  font-size:14px;
  box-sizing:border-box;
}
input::placeholder{color:var(--muted)}
.dock__btn,
button{cursor:pointer}

/* ---------- 4. 主题选择浮层 ---------- */
.theme-btn{position:relative}
.theme-pop{
  position:fixed;z-index:80;top:72px;right:14px;width:268px;
  background:var(--panel-2);border:1px solid var(--line-2);border-radius:18px;
  box-shadow:var(--shadow);padding:14px 14px 12px;display:none;
  backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
}
.theme-pop.is-open{display:block;animation:popIn .18s cubic-bezier(.2,1.3,.4,1)}
.theme-pop__title{font-size:13px;font-weight:800;color:var(--text);letter-spacing:1px;margin-bottom:10px;display:flex;align-items:center;gap:6px}
.theme-pop__grid{display:grid;grid-template-columns:repeat(2,1fr);gap:9px}
.theme-swatch{
  display:flex;align-items:center;gap:8px;width:100%;text-align:left;
  padding:8px 10px;border-radius:12px;border:1px solid var(--line);
  background:var(--panel);color:var(--text);font-size:12.5px;font-weight:700;
  box-shadow:none;
}
.theme-swatch:hover{border-color:var(--line-2);filter:none}
.theme-swatch.is-active{outline:2px solid var(--gold-2);outline-offset:-1px;border-color:var(--gold-2)}
.sw{width:20px;height:20px;border-radius:6px;border:1px solid rgba(0,0,0,.18);flex:0 0 auto}
.sw-classic{background:linear-gradient(135deg,#e8482f,#cf2c24)}
.sw-dark{background:linear-gradient(135deg,#2a2c34,#0e0f13)}
.sw-light{background:linear-gradient(135deg,#ffffff,#dde3ee);border-color:rgba(0,0,0,.12)}
.sw-ocean{background:linear-gradient(135deg,#1b4a7e,#0a2444)}
.sw-forest{background:linear-gradient(135deg,#2f6b3a,#143019)}
.sw-auto{background:linear-gradient(135deg,#cf2c24 0 50%,#0e0f13 50% 100%)}
.theme-pop__close{width:100%;margin-top:10px;padding:8px;font-size:12.5px;color:var(--muted)}

/* ============================================================
   5. 移动端适配（手机也能好用）
   ============================================================ */
@media (max-width:880px){
  .lobby-top{flex-wrap:wrap;row-gap:8px}
  .lobby-stage__inner{padding:2px 12px 8px}
  .brand h1{font-size:42px;letter-spacing:4px}
  .room-grid{grid-template-columns:repeat(2,1fr)}
}

@media (max-width:560px){
  /* 顶栏：玩家卡 + 在线人数一行，功能坞整行可横滑 */
  .lobby-top{padding:8px 8px 4px;gap:6px;align-items:center}
  .player-chip{order:1;flex:1 1 auto;max-width:none}
  .online-pill{order:2}
  .dock{order:3;width:100%;justify-content:flex-start;gap:6px;overflow-x:auto;padding-bottom:2px}
  .dock__btn{flex:1 1 0;min-width:62px}
  .spacer{flex:1 1 auto}

  /* 大厅内容收紧 */
  .lobby-stage__inner{padding:2px 8px}
  .brand{margin:2px 0 8px}
  .brand h1{font-size:32px;letter-spacing:2px}
  .sub{font-size:11px;letter-spacing:2px;padding:3px 14px}
  .section-title{letter-spacing:2px;font-size:11px;margin:6px 0}
  .room-grid{grid-template-columns:1fr 1fr;gap:8px}
  .mode-cards{gap:9px;margin:6px 0 12px}
  .mode-card{padding:11px;gap:10px}
  .mode-card__desc{font-size:10.5px;line-height:1.45}
  .mode-card__icon{flex:0 0 auto}
  .mode-card__go{padding:6px 10px;font-size:11px}
  .mode-card__tag{font-size:9px;right:8px}

  /* 自定义房间 / 大厅表单 */
  .casual-bar{flex-wrap:wrap;gap:6px;padding:calc(7px + env(safe-area-inset-top)) 8px}
  .custom-stage{padding:12px 10px}
  .field input,.username-display,.input-room{font-size:16px}
  .rules-wrap{max-width:100%}

  /* 牌桌：缩小两侧座位与出牌区，给中央留空间 */
  .topbar{gap:4px;padding:calc(5px + env(safe-area-inset-top)) 6px 5px}
  .topbar .pill,.topbar button{padding:4px 7px;font-size:10.5px}
  .topbar .spacer{display:none}
  .seat--side{width:31vw;max-width:118px;padding:7px 3px 5px;top:3px}
  .seat--left{left:2px}.seat--right{right:2px}
  .seat__name{font-size:10px}
  .seat__count{font-size:10px;min-width:18px;height:18px;top:-6px;right:-7px}
  .played{top:40%;max-width:36%}
  .played--left{left:3px}.played--right{right:3px}
  .card{width:36px;height:51px}
  .lastplay,.my-played{min-height:40px}
  .bottom{padding:6px 6px calc(8px + env(safe-area-inset-bottom))}
  .myinfo{font-size:11px;gap:5px;padding:5px 7px}
  .myinfo .spacer{display:none}
  .chat-box{min-width:84px;max-width:140px}
  .chat-input{font-size:16px}
  .actions{gap:8px;min-height:50px}
  .actions button{flex:1;padding:12px 6px;font-size:14px;letter-spacing:1px}
  .hand{min-height:74px;padding:12px 6px 2px}
  .hand-viewport{min-height:92px;padding:16px 6px 2px}
  /* 手牌：缩小并控制重叠，20 张也能在一屏内完整显示，不再被裁切 */
  .hand .card{width:34px;height:48px;margin-left:-18px}
  .hand .card:first-child{margin-left:0}
  .counter{font-size:10px;gap:6px;padding:5px 8px;margin-top:4px}

  /* 浮层 / 弹窗 */
  .overlay{padding:8px}
  .result-card{max-width:calc(100vw - 16px);padding:18px 14px;border-radius:18px}
  .hist-list,.lb-list{max-height:60vh;max-height:60dvh}

  /* 主题浮层在手机上变底部抽屉 */
  .theme-pop{left:0;right:0;top:auto;bottom:0;width:100%;border-radius:18px 18px 0 0;border-bottom:0;animation:popUpSheet .22s ease}
  .theme-pop__grid{grid-template-columns:repeat(3,1fr)}
}
@keyframes popUpSheet{from{transform:translateY(20px);opacity:.6}to{transform:translateY(0);opacity:1}}

@media (max-width:380px){
  .room-grid{grid-template-columns:1fr}
  .card{width:31px;height:44px}
  .hand .card{width:30px;height:42px;margin-left:-15px}
  .dock__btn{flex-direction:column;gap:1px;font-size:9.5px;padding:6px 2px}
  .dock__btn span{font-size:9.5px}
  .dock__btn svg{width:15px;height:15px}
  .seat--side{width:33vw;max-width:104px}
  .mode-card__desc{font-size:10px}
}

/* 桌面端 hover 时，主题按钮高亮 */
@media (hover:hover){
  .theme-btn:hover{filter:brightness(1.05);border-color:var(--line-2)}
}
