/* ================================================================
   WOG SPA 佈局 — 手機優先，暗黑 RPG
   ================================================================ */

/* ── 重置 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── 根容器：全螢幕，防止頁面捲動 ── */
#spa-root {
  display: flex;
  flex-direction: column;
  height: 100dvh;        /* dvh 處理手機瀏覽器底部欄 */
  height: 100vh;         /* fallback */
  overflow: hidden;
  position: relative;
}

/* ── 頂部欄 ── */
#spa-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gap-md);
  position: relative;
  z-index: 10;
}

#spa-header .hdr-title {
  font-size: 0.85em;
  color: var(--c-gold);
  font-weight: bold;
  letter-spacing: 1px;
}

/* HP/EXP 底部狀態列 */
#hdr-vitals {
  flex-shrink: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--c-border);
  padding: 4px var(--gap-md) 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.vital-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vital-label {
  font-size: 0.55em;
  font-weight: bold;
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}

.vital-label--hp  { color: #c83030; }
.vital-label--exp { color: #5a60c8; }

.vital-pct {
  font-size: 0.58em;
  color: var(--c-text-dim);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

.hdr-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  overflow: hidden;
}

.hdr-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--t-normal);
}

.hdr-bar--hp .hdr-bar-fill  { background: linear-gradient(90deg, var(--c-hp-from), var(--c-hp-to)); }
.hdr-bar--exp .hdr-bar-fill { background: linear-gradient(90deg, var(--c-exp-from), var(--c-exp-to)); }

/* ── 主內容區 ── */
#spa-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* 各頁面 panel */
.spa-panel {
  display: none;
  min-height: 100%;
  padding: var(--gap-sm);
  animation: panel-in var(--t-normal) ease;
}

.spa-panel.active {
  display: block;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── 底部 Tab 導航 ── */
#spa-nav {
  flex-shrink: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--nav-bg);
  border-top: 1px solid var(--nav-border);
  display: flex;
  align-items: stretch;
  position: relative;
  z-index: 10;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--nav-inactive);
  cursor: pointer;
  padding: 4px 0;
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.nav-tab:active {
  opacity: 0.7;
}

.nav-tab.active {
  color: var(--nav-active);
}

/* 活動 Tab 頂部指示線 */
.nav-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  width: 60%;
  height: 2px;
  background: var(--nav-active);
  border-radius: 0 0 2px 2px;
}

.nav-tab svg,
.nav-tab .tab-icon {
  width: 22px;
  height: 22px;
  font-size: 20px;
  line-height: 1;
}

.nav-tab .tab-label {
  font-size: 0.62em;
  letter-spacing: 0.3px;
}

/* Tab 徽章（未讀消息） */
.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #d55;
  color: #fff;
  font-size: 0.6em;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.nav-badge:empty,
.nav-badge[data-count="0"] {
  display: none;
}

/* ── Toast 通知 ── */
#spa-toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-sm);
  pointer-events: none;
  width: 90%;
  max-width: 360px;
}

.spa-toast {
  background: var(--c-surface3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 8px 14px;
  font-size: 0.82em;
  color: var(--c-text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  animation: toast-in 0.2s ease;
  width: 100%;
  text-align: center;
}

.spa-toast.toast-error {
  border-color: rgba(200,50,50,0.6);
  color: #ff8888;
}

.spa-toast.toast-success {
  border-color: rgba(50,160,80,0.6);
  color: #80d880;
}

.spa-toast.toast-out {
  animation: toast-out 0.25s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ── Modal ── */
#spa-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: var(--gap-sm);
  animation: overlay-in var(--t-fast) ease;
}

#spa-modal-overlay.open {
  display: flex;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.spa-modal {
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--gap-lg);
  animation: modal-up var(--t-normal) ease;
  display: flex;
  flex-direction: column;
}

/* modal body 預設可滾動但讓子組件能用 flex 佈局 */
#modal-body {
  flex: 1;
  min-height: 0;
}

@keyframes modal-up {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.spa-modal-title {
  font-size: 0.9em;
  color: var(--c-gold);
  font-weight: bold;
  margin-bottom: var(--gap-md);
  padding-bottom: var(--gap-sm);
  border-bottom: 1px solid var(--c-border);
}

.spa-modal-title:empty {
  display: none;
}

/* ── 載入骨架 ── */
.skeleton {
  background: linear-gradient(90deg,
    var(--c-surface2) 25%,
    var(--c-surface3) 50%,
    var(--c-surface2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── 登入頁 ── */
#panel-login {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: var(--gap-lg);
}

#panel-login[style*="display: none"] {
  display: none !important;
}

.login-box {
  width: 100%;
  max-width: 320px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--gap-lg) var(--gap-lg) 20px;
}

.login-logo {
  text-align: center;
  margin-bottom: var(--gap-lg);
}

.login-logo h1 {
  font-size: 1.3em;
  color: var(--c-gold);
  text-shadow: 0 0 16px rgba(200,160,60,0.4);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.login-logo p {
  font-size: 0.72em;
  color: var(--c-text-dim);
}

.form-group {
  margin-bottom: var(--gap-md);
}

.form-label {
  display: block;
  font-size: 0.72em;
  color: var(--c-gold-dim);
  margin-bottom: 5px;
  letter-spacing: 0.4px;
}

.form-input {
  width: 100%;
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 9px 12px;
  color: var(--c-text);
  font-size: 0.9em;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--t-fast);
}

.form-input:focus {
  border-color: var(--c-gold-dim);
}

.form-input::placeholder {
  color: var(--c-text-faint);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #7a5010, #c9a84c);
  border: none;
  border-radius: var(--r-md);
  padding: 11px;
  color: #fff;
  font-size: 0.92em;
  font-weight: bold;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: 1px;
  transition: opacity var(--t-fast), transform var(--t-fast);
  margin-top: var(--gap-sm);
}

.btn-primary:active {
  opacity: 0.8;
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── 註冊表單 ── */
.reg-radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.reg-radio {
  color: var(--c-text);
  font-size: 0.82em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

.reg-img-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 4px;
}

.reg-img-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color var(--t-fast);
}

.reg-img-cell img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.reg-img-cell span {
  font-size: 0.55em;
  color: var(--c-text-faint);
}

.reg-img-cell:active,
.reg-img-cell.selected {
  border-color: var(--c-gold);
  background: rgba(200,160,60,0.1);
}

.reg-img-cell.selected span {
  color: var(--c-gold);
}

/* ── 通用卡片 ── */
.wog-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  margin-bottom: var(--gap-sm);
  overflow: hidden;
}

.wog-card-header {
  padding: var(--gap-sm) var(--gap-md);
  background: var(--c-surface2);
  border-bottom: 1px solid var(--c-border);
  font-size: 0.78em;
  color: var(--c-gold);
  font-weight: bold;
  letter-spacing: 0.4px;
}

.wog-card-body {
  padding: var(--gap-md);
}

/* ── 平板/桌面：側欄佈局 ── */
@media (min-width: 769px) {
  #spa-root {
    flex-direction: row;
    height: 100vh;
  }

  /* 側邊導航取代底部 Tab */
  #spa-nav {
    width: 72px;
    height: 100%;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--nav-border);
    padding-bottom: 0;
    padding-top: var(--gap-md);
    order: -1;
  }

  .nav-tab.active::before {
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    border-radius: 0 2px 2px 0;
  }

  #spa-header {
    display: none;  /* 桌面不需要頂部欄 */
  }

  #spa-content {
    flex: 1;
    height: 100%;
  }

  #spa-toast-container {
    bottom: var(--gap-lg);
  }
}

/* ════════════════════════════════════════════
   Attribute badges (五行屬性, v3.12)
   1=地 2=水 3=火 4=木 5=風 6=毒 7=無
   ════════════════════════════════════════════ */
.sv-badge--attr {
  font-weight: bold;
  letter-spacing: 1px;
}
.sv-attr-1 { background: rgba(120,90,40,0.4);  color: #d8a060; border: 1px solid rgba(180,130,60,0.6); }  /* 地 */
.sv-attr-2 { background: rgba(30,80,140,0.4);  color: #6ab0e8; border: 1px solid rgba(60,130,200,0.6); }  /* 水 */
.sv-attr-3 { background: rgba(150,40,30,0.4);  color: #f08060; border: 1px solid rgba(200,80,60,0.6); }   /* 火 */
.sv-attr-4 { background: rgba(30,100,40,0.4);  color: #70d080; border: 1px solid rgba(60,160,80,0.6); }   /* 木 */
.sv-attr-5 { background: rgba(80,120,140,0.4); color: #a0d0e0; border: 1px solid rgba(120,180,200,0.6); } /* 風 */
.sv-attr-6 { background: rgba(80,30,120,0.4);  color: #c080ff; border: 1px solid rgba(140,80,200,0.6); }  /* 毒 */
.sv-attr-7 { background: rgba(80,80,80,0.4);   color: #c0c0c0; border: 1px solid rgba(140,140,140,0.6); } /* 無 */
.sv-attr-x { background: var(--c-surface3);    color: var(--c-text-dim); border: 1px solid var(--c-border); }

/* ════════════════════════════════════════════
   通用 form 商店 modal (v3.19)
   ════════════════════════════════════════════ */
.form-shop {
  padding: 4px 0;
}
.form-shop .form-group {
  margin-bottom: 10px;
}
.form-shop .form-label {
  display: block;
  font-size: 0.75em;
  color: var(--c-text-dim);
  margin-bottom: 4px;
}
.form-shop .form-input {
  width: 100%;
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-family: var(--font);
  padding: 8px 10px;
  font-size: 0.85em;
}
.form-shop .form-input:focus {
  outline: none;
  border-color: var(--c-gold-dim);
}

/* 印花屋（PHP 原版表格輕度美化） */
.stamp-shop .stamp-content table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}
.stamp-shop .stamp-content td {
  padding: 6px 8px;
  border: 1px solid var(--c-border);
  font-size: 0.78em;
  color: var(--c-text);
  background: var(--c-surface);
}
.stamp-shop .stamp-content tr:first-child td {
  background: var(--c-surface2);
  color: var(--c-gold-dim);
}
.stamp-shop .stamp-btn {
  background: linear-gradient(135deg, #7a5010, #c9a84c);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.78em;
  font-family: var(--font);
  cursor: pointer;
  font-weight: bold;
}
.stamp-shop .stamp-btn:active { opacity: 0.85; }

