:root {
  /* 亮色模式色彩規範 (Light Theme) */
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-hover: #f8fafc;
  
  --text-main: #0f172a;
  --text-sub: #64748b;
  --text-mut: #94a3b8;
  
  --color-blue: #2563eb;
  --color-blue-bg: #eff6ff;
  --color-blue-border: #bfdbfe;
  
  --color-green: #10b981;
  --color-red: #ef4444;
  
  --border-line: #e2e8f0;
  
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-btn: 0 1px 2px rgba(0, 0, 0, 0.05);
  
  /* 統一形狀與間距 */
  --radius-card: 16px;
  --radius-btn: 12px;
  --gap-unified: 12px;
  --pad-card: 16px;
}

/* ====================================================
   OLED 極致深色模式 (Pure Dark Theme)
   ==================================================== */
[data-theme="dark"] {
  --bg-page: #000000;       /* OLED 純黑背景 */
  --bg-card: #121212;       /* 極深灰卡片，拉出空間層次 */
  --bg-hover: #1e1e1e;      /* 點擊懸停回饋色 */
  
  --text-main: #f8fafc;     /* 主文字亮白 */
  --text-sub: #9ca3af;      /* 次文字柔灰 */
  --text-mut: #6b7280;      /* 弱化文字 */
  
  --color-blue: #60a5fa;    /* OLED 友善亮藍色 */
  --color-blue-bg: rgba(59, 130, 246, 0.15);
  --color-blue-border: rgba(59, 130, 246, 0.3);
  
  --color-green: #34d399;   /* OLED 友善亮綠色 */
  --color-red: #f87171;     /* OLED 友善亮紅色 */
  
  --border-line: #2a2a2a;   /* 柔和的深灰邊框，純黑中不刺眼 */
  
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.8);
  --shadow-btn: 0 1px 2px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page); 
  color: var(--text-main); 
  padding: 16px; margin: 0; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  touch-action: manipulation; user-select: none;
  -webkit-tap-highlight-color: transparent; cursor: pointer;
  font-family: inherit; transition: all 0.15s ease-out;
}
button:active { transform: scale(0.96); }
.text-center { text-align: center; }

/* === 頭部與主題按鈕 === */
.app-header {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  max-width: 900px; width: 100%; margin: 0 auto 20px auto;
}
.app-header h2 { margin: 0; font-weight: 800; font-size: 20px; letter-spacing: -0.5px; }

.theme-btn {
  position: absolute; right: 0;
  background: transparent; border: none; font-size: 24px;
  padding: 6px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-main); line-height: 1;
}
.theme-btn:hover { background: var(--bg-card); }

/* =========================================
   全域佈局
   ========================================= */
.app-container {
  display: flex; flex-wrap: nowrap; align-items: stretch; gap: var(--gap-unified);
  max-width: 900px; margin: 0 auto; width: 100%; flex: 1 0 auto;
}
.left-panel { flex: 4; min-width: 0; display: flex; flex-direction: column; gap: var(--gap-unified); }
.right-panel { flex: 5; min-width: 0; display: flex; flex-direction: column; gap: var(--gap-unified); }

.card {
  background: var(--bg-card); padding: var(--pad-card);
  border-radius: var(--radius-card); border: 1px solid var(--border-line);
  box-shadow: var(--shadow-card);
  transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.card-title { font-size: 14px; font-weight: 700; color: var(--text-main); margin-bottom: 12px; }

/* === 左側：盈虧與統計 Grid === */
.balance-container { text-align: center; }
.balance-amount { font-size: 2.5rem; font-weight: 800; letter-spacing: -1px; line-height: 1.1; margin: 4px 0 12px;}
.positive { color: var(--color-green); } 
.negative { color: var(--color-red); } 
.neutral { color: var(--text-main); }
.win-text { color: var(--color-green); }
.lose-text { color: var(--color-red); }

@keyframes pulseAmount {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
.pulse-anim { animation: pulseAmount 0.3s ease-out; display: inline-block; }

.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 8px;
  padding-top: 16px; border-top: 1px solid var(--border-line);
}
.stat-box { text-align: center; }
.stat-title { font-size: 11px; color: var(--text-sub); margin-bottom: 2px; font-weight: 500; } 
.stat-value { font-size: 14px; font-weight: 700; color: var(--text-main); }

/* === 左側：歷史紀錄 === */
.history-card { flex-grow: 1; display: flex; flex-direction: column; }
.history-container { flex-grow: 1; overflow-y: auto; max-height: 480px; padding-right: 4px; }
.history-container::-webkit-scrollbar { width: 4px; }
.history-container::-webkit-scrollbar-thumb { background-color: var(--border-line); border-radius: 10px; }
.empty-msg { color: var(--text-mut); text-align: center; padding: 30px; font-size: 13px; }

.history-item {
  border-bottom: 1px solid var(--border-line);
  transition: all 0.2s ease; overflow: hidden;
}
.history-item.removing { opacity: 0; transform: translateX(-20px); }

.history-summary {
  padding: 12px 4px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; user-select: none;
}
.history-summary:active { background-color: var(--bg-hover); border-radius: 8px;}
.hs-main { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-main); }
.hs-time { color: var(--text-sub); font-size: 12px;}
.hs-divider { color: var(--border-line); }
.hs-bet b { font-weight: 700; }

.hs-result { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 4px;}
.hs-chevron { font-size: 9px; color: var(--text-mut); transition: transform 0.3s; }
.history-item.expanded .hs-chevron { transform: rotate(180deg); color: var(--color-blue); }
.roll-badge { 
  font-size: 10px; background-color: var(--color-purple-bg); color: var(--color-purple);
  padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border-line); margin-left: 2px;
}

.history-details {
  display: none; padding: 12px; background-color: var(--bg-hover);
  border-radius: 8px; margin-bottom: 8px; align-items: center; justify-content: space-between;
  animation: fadeIn 0.2s ease-out;
}
.history-item.expanded .history-details { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.hd-info { font-size: 13px; color: var(--text-sub); }
.hd-info b { color: var(--text-main); }
.btn-delete-record {
  background: transparent; color: var(--color-red); border: 1px solid var(--color-red);
  padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600;
}
.btn-delete-record:active { background: var(--color-red); color: white; }

/* === 右側：投注選項 === */
.bet-options { display: flex; gap: var(--gap-unified); }
.bet-btn {
  flex: 1; padding: 12px 0; font-size: 15px; font-weight: 600; 
  background: var(--bg-page); border: 1px solid var(--border-line); color: var(--text-sub);
  border-radius: var(--radius-btn);
}
.bet-btn.active { 
  background: var(--color-blue-bg); border-color: var(--color-blue); color: var(--color-blue); font-weight: 700;
}
.roll-btn {
  width: 100%; margin-top: var(--gap-unified); font-size: 14px; padding: 10px 0; font-weight: 600;
  border: 1px solid var(--border-line); border-radius: var(--radius-btn); background: var(--bg-page);
  color: var(--text-sub);
}
.roll-btn.active { background: var(--color-purple-bg); border-color: #8b5cf6; color: #8b5cf6; }

/* === 右側：金額按鈕 === */
.amount-header { display: flex; justify-content: space-between; align-items: center; }
.current-bet-label { font-size: 11px; color: var(--text-sub); font-weight: 500; background: var(--bg-page); padding: 2px 8px; border-radius: 10px;}

.amount-display { 
  text-align: center; font-size: 2rem; font-weight: 800; color: var(--text-main); 
  margin-bottom: 16px; font-variant-numeric: tabular-nums;
}
.amount-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.amt-btn {
  padding: 10px 0; font-size: 14px; font-weight: 600; background: var(--bg-card); 
  border: 1px solid var(--border-line); border-radius: 8px; 
  color: var(--text-main); box-shadow: var(--shadow-btn);
}
.btn-outline { background: transparent; border-color: var(--border-line); color: var(--text-mut); box-shadow: none; font-weight: 500;}

/* === 右側：開彩與 SVG 骰子鍵盤 === */
.dice-display-area { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }

/* 顯示槽內的 SVG 尺寸設定 */
.dice-slot {
  width: 48px; height: 48px; border: 2px dashed var(--border-line); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-main); background: transparent; transition: all 0.2s;
}
.dice-slot.filled { 
  border: 2px solid var(--color-blue-border); background: var(--color-blue-bg); 
  color: var(--color-blue);
}
.dice-slot .dice-svg { width: 32px; height: 32px; }

.dice-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* 鍵盤按鈕置中 SVG */
.key-btn {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 0; font-size: 16px; font-weight: 600; background: var(--bg-card); 
  border: 1px solid var(--border-line); border-radius: 8px; 
  color: var(--text-main); box-shadow: var(--shadow-btn);
}
.key-btn .dice-svg { width: 26px; height: 26px; pointer-events: none; } /* 防點擊穿透 */

.btn-outline-red { background: transparent; border-color: var(--border-line); color: var(--color-red); box-shadow: none; font-size: 14px;}
.key-submit { 
  background: var(--color-blue); color: #ffffff; grid-column: span 2; 
  font-size: 15px; font-weight: 700; border: none; box-shadow: var(--shadow-card); 
}
.key-submit:disabled { background: var(--border-line); color: var(--text-mut); box-shadow: none; opacity: 0.8; }

/* === 署名區塊 (淡入效果設定) === */
.app-footer {
  text-align: center; font-size: 12px; color: var(--text-mut);
  margin-top: 80px; padding-bottom: 24px; letter-spacing: 0.5px;
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.app-footer.show {
  opacity: 1; transform: translateY(0);
}

/* =========================================
   📱 手機版專屬優化
   ========================================= */
@media (max-width: 768px) {
  body { padding: 6px; }
  
  .app-container {
    display: grid;
    grid-template-columns: minmax(0, 43%) minmax(0, 57%); 
    gap: 8px;
  }
  .left-panel, .right-panel { display: flex; width: 100%; gap: 8px; }
  
  .card { padding: 12px; border-radius: 12px; min-width: 0; }
  .card-title { font-size: 13px; margin-bottom: 8px; }
  
  /* 左側 */
  .balance-amount { font-size: 1.8rem; margin: 0 0 8px; }
  
  .stats-grid { gap: 8px 4px; margin-top: 8px; padding-top: 10px; }
  .stat-title { font-size: 10px; margin-bottom: 2px; }
  .stat-value { font-size: 12px; }
  
  .history-summary { padding: 8px 0; }
  .hs-main { font-size: 11px; gap: 4px;}
  .hs-time { font-size: 10px; }
  .hs-result { font-size: 12px; }
  .history-details { padding: 10px; flex-direction: column; align-items: stretch; gap: 8px;}
  .hd-info { font-size: 12px; text-align: center;}
  
  /* 右側 */
  .bet-options { gap: 6px; }
  .bet-btn { font-size: 13px; padding: 10px 0; border-radius: 8px;}
  .roll-btn { font-size: 12px; padding: 8px 0; margin-top: 8px; border-radius: 8px;}
  
  .amount-display { font-size: 1.5rem; margin-bottom: 12px; }
  .amount-btns { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .amt-btn { font-size: 12px; padding: 8px 0; }
  
  .dice-display-area { gap: 6px; margin-bottom: 8px; }
  .dice-slot { width: 36px; height: 36px; border-radius: 8px; }
  .dice-slot .dice-svg { width: 24px; height: 24px; }
  
  .dice-keypad { gap: 6px; }
  .key-btn { padding: 8px 0; }
  .key-btn .dice-svg { width: 22px; height: 22px; }
  .btn-outline-red { font-size: 12px; }
  .key-submit { font-size: 13px; }
}