/* 《積木創世紀》- 童話奇幻風格樣式 */

:root {
  --primary: #5C6BC0;
  --primary-hover: #3F51B5;
  --bg-main: #E8EEF5;
  --bg-card: #FFFFFF;
  --text-main: #2C3E50;
  --text-muted: #7F8C8D;
  --accent-gold: #FFA000;
  --border-radius: 12px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 僅允許文字輸入框進行文字選取與游標編輯 */
input, textarea {
  user-select: text !important;
  -webkit-user-select: text !important;
  -webkit-touch-callout: default !important;
}

#canvas-container, canvas {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* 頂部標題列 */
.app-header {
  height: 60px;
  background: #FFFFFF;
  border-bottom: 2px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}

.logo-icon {
  font-size: 26px;
  flex-shrink: 0;
}

.header-logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: #37474F;
  white-space: nowrap;
  margin: 0;
}

.logo-en {
  font-size: 14px;
  font-weight: 400;
  color: #78909C;
  margin-left: 6px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.btn-nav {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #CFD8DC;
  background: #FFFFFF;
  color: #455A64;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-nav:hover {
  background: #ECEFF1;
  border-color: #B0BEC5;
}

.btn-danger {
  color: #D32F2F;
  border-color: #FFCDD2;
}

.btn-danger:hover {
  background: #FFEBEE;
}

/* 主遊戲區佈局 */
.game-layout {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* 左側狀態面板 */
.status-panel {
  width: 280px;
  background: #F8FAFC;
  border-right: 2px solid #E2E8F0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  z-index: 5;
}

.panel-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #EDF2F7;
}

.turn-title {
  font-size: 15px;
  font-weight: 700;
  color: #37474F;
}

.badge-phase {
  background: #E8F5E9;
  color: #2E7D32;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 4px;
}

.badge-settle {
  background: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFE0B2;
}

.score-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.score-number {
  font-size: 32px;
  font-weight: 800;
  color: #2E7D32;
  margin-top: 4px;
}

.card-heading {
  font-size: 14px;
  font-weight: 700;
  color: #455A64;
}

.card-subheading {
  font-size: 11px;
  color: #90A4AE;
  margin-bottom: 8px;
}

.resource-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.resource-item {
  display: flex;
  align-items: center;
  background: #F8FAFC;
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 4px solid #B0BEC5;
  font-size: 13px;
  justify-content: space-between;
}

.elem-icon {
  font-size: 16px;
  margin-right: 4px;
}

.elem-name {
  font-weight: 600;
  color: #455A64;
  flex: 1;
}

.elem-value {
  font-size: 15px;
  font-weight: 800;
  color: #263238;
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: #CFD8DC;
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-block {
  width: 100%;
}

.btn-success {
  background: #43A047;
}

.btn-success:hover {
  background: #2E7D32;
}

.reroll-tip {
  font-size: 11px;
  color: #78909C;
  margin-top: 6px;
  text-align: center;
}

/* 中央 3D 視口 */
.viewport-section {
  flex: 1;
  position: relative;
  background: #F0F4F8;
  overflow: hidden;
  touch-action: none;
}

#canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* 懸浮偵測器 Tooltip */
.inspector-tooltip {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 250px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  border: 1px solid #CFD8DC;
  padding: 14px;
  font-size: 13px;
  pointer-events: none;
  z-index: 10;
}

.inspector-title {
  font-weight: 700;
  color: #37474F;
  border-bottom: 1px solid #ECEFF1;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.inspector-row {
  margin-bottom: 5px;
  color: #546E7A;
}

.inspector-dev {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed #CFD8DC;
  font-size: 12px;
  color: #455A64;
}

.inspector-alert {
  margin-top: 8px;
  padding: 6px;
  background: #FFF9C4;
  color: #F57F17;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
}

/* 放置確認浮動操作列 */
.placement-confirm-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border: 2px solid #4CAF50;
  border-radius: 40px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 50;
  animation: slideUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.confirm-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #2E7D32;
}

.confirm-icon {
  font-size: 18px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.btn-cancel {
  background: #ECEFF1;
  border: 1px solid #CFD8DC;
  color: #546E7A;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-cancel:hover {
  background: #CFD8DC;
}

.btn-confirm {
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  border: none;
  color: #FFFFFF;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
  transition: all 0.2s ease;
}

.btn-confirm:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(46, 125, 50, 0.4);
}

/* 下方積木池 */
.pool-footer {
  height: 220px;
  background: #FFFFFF;
  border-top: 2px solid #E2E8F0;
  padding: 10px 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  z-index: 10;
}

.pool-notice {
  font-size: 13px;
  font-weight: 600;
  color: #546E7A;
  margin-bottom: 8px;
}

.pool-list {
  flex: 1;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.pool-card {
  flex: 1;
  max-width: 230px;
  background: #F8FAFC;
  border: 2px solid #CFD8DC;
  border-radius: var(--border-radius);
  padding: 10px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.pool-card:hover:not(.is-locked) {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.pool-card.is-selected {
  border-color: #2E7D32;
  background: #E8F5E9;
  box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.25);
  transform: translateY(-4px);
}

.pool-card.is-locked {
  background: #ECEFF1;
  border-color: #B0BEC5;
  cursor: not-allowed;
  opacity: 0.7;
}

.lock-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(55, 71, 79, 0.65);
  border-radius: calc(var(--border-radius) - 2px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 14px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.card-tier {
  font-size: 10px;
  font-weight: 800;
  color: #FFFFFF;
  padding: 2px 6px;
  border-radius: 4px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: #263238;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-content-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.card-thumb {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #CFD8DC;
  background: #ECEFF1;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.card-body {
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(236, 239, 241, 0.8);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #78909C;
  font-size: 13px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.card-tier {
  font-size: 11px;
  font-weight: 800;
  color: #FFFFFF;
  padding: 2px 6px;
  border-radius: 4px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: #37474F;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-body {
  font-size: 12px;
  color: #546E7A;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-emits {
  font-weight: 600;
}

.card-req {
  color: #E65100;
  font-size: 11px;
}

.req-met {
  color: #2E7D32;
  font-weight: 700;
}

.req-unmet {
  color: #D32F2F;
  font-weight: 700;
}

.card-score {
  font-size: 11px;
  color: #78909C;
}

/* 終局確認結算操作區 */
.settle-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settle-card {
  width: 100%;
  max-width: 720px;
  background: linear-gradient(135deg, #FFFDE7 0%, #FFF8E1 100%);
  border: 2px solid #FFD54F;
  border-radius: var(--border-radius);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  box-shadow: 0 4px 18px rgba(255, 179, 0, 0.18);
  animation: slideUp 0.3s ease;
}

.settle-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settle-badge {
  font-size: 15px;
  font-weight: 800;
  color: #E65100;
}

.settle-hint {
  font-size: 12px;
  color: #6D4C41;
  line-height: 1.4;
}

.btn-settle {
  background: linear-gradient(135deg, #FFA000, #FF6F00);
  border: none;
  border-radius: 12px;
  color: #FFFFFF;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 18px rgba(255, 111, 0, 0.35);
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  white-space: nowrap;
  animation: settlePulse 2s infinite ease-in-out;
}

.btn-settle:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 24px rgba(255, 111, 0, 0.45);
}

.btn-settle:active {
  transform: translateY(1px) scale(0.98);
}

@keyframes settlePulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(255, 111, 0, 0.35); }
  50% { box-shadow: 0 8px 26px rgba(255, 160, 0, 0.65); }
}

.settle-btn-icon {
  font-size: 20px;
}

.settle-btn-text {
  letter-spacing: 0.5px;
}

/* 彈窗樣式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(38, 50, 56, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #FFFFFF;
  border-radius: 16px;
  width: 90%;
  max-width: 550px;
  max-height: 85vh;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.25s ease-out;
}

.modal-large {
  max-width: 850px;
}

@keyframes modalPop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #ECEFF1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #37474F;
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-text-danger {
  background: none;
  border: 1px dashed #EF9A9A;
  color: #E53935;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-text-danger:hover {
  background: #FFEBEE;
  border-color: #E53935;
}

/* 圖鑑屬性篩選標籤列 */
.comp-filter-bar {
  background: #F8FAFC;
  padding: 10px 20px;
  border-bottom: 1px solid #ECEFF1;
}

.comp-filter-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.filter-tab {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid #CFD8DC;
  background: #FFFFFF;
  color: #546E7A;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.filter-tab:hover {
  background: #ECEFF1;
  border-color: #B0BEC5;
}

.filter-tab.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(92, 107, 192, 0.3);
}

.sub-progress {
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
  margin-left: 10px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 26px;
  color: #90A4AE;
  cursor: pointer;
}

.modal-content {
  padding: 20px;
  overflow-y: auto;
}

/* 進階選項卡片 */
.evo-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.evo-card {
  border: 2px solid #E0E0E0;
  border-radius: var(--border-radius);
  padding: 14px;
  background: #FAFAFA;
}

.evo-card-content {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.evo-thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #CFD8DC;
  background: #ECEFF1;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.evo-card-info {
  flex: 1;
}

.evo-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.evo-name {
  font-size: 16px;
  color: #263238;
}

.evo-desc {
  font-size: 13px;
  color: #546E7A;
  margin-bottom: 6px;
}

.evo-hint {
  font-size: 12px;
  color: #E65100;
  font-weight: 600;
  margin-bottom: 6px;
}

.evo-score {
  font-size: 12px;
  color: #78909C;
}

/* 圖鑑清單 */
.comp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.comp-card {
  border: 1px solid #CFD8DC;
  border-radius: 12px;
  padding: 12px;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
}

.comp-card.unlocked:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--primary);
}

.comp-card.locked {
  background: #ECEFF1;
  opacity: 0.6;
}

.comp-thumb-box {
  width: 100%;
  height: 120px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #CFD8DC;
  background: #F8FAFC;
  margin-bottom: 8px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}

.comp-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.comp-desc {
  font-size: 12px;
  color: #546E7A;
  margin-bottom: 6px;
}

.comp-emits, .comp-score {
  font-size: 11px;
  color: #78909C;
  margin-bottom: 3px;
}

/* 圖鑑內的進階目標分支清單 */
.comp-evo-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #ECEFF1;
}

.comp-evo-title {
  font-size: 11px;
  font-weight: 700;
  color: #2E7D32;
  margin-bottom: 5px;
}

.comp-evo-none {
  margin-top: 6px;
  font-size: 11px;
  color: #90A4AE;
  font-style: italic;
}

.comp-evo-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.comp-evo-item {
  display: flex;
  flex-direction: column;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
}

.comp-evo-item.is-discovered {
  border-left: 3px solid #4CAF50;
  background: #F1F8E9;
}

.comp-evo-item.is-hidden {
  border-left: 3px solid #B0BEC5;
  background: #ECEFF1;
}

.evo-target-tier {
  font-size: 10px;
  font-weight: 800;
  color: #FFFFFF;
  padding: 1px 4px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 4px;
  width: fit-content;
}

.evo-target-name {
  font-weight: 700;
  color: #37474F;
  margin-top: 2px;
}

.evo-hint-text {
  font-size: 10px;
  color: #E65100;
  margin-top: 2px;
}

/* 名人堂 */
.hall-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hall-item {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  padding: 10px;
}

.hall-rank {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-gold);
  width: 40px;
  text-align: center;
}

.hall-img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #CFD8DC;
}

.hall-info {
  flex: 1;
  font-size: 13px;
}

.hall-score {
  font-size: 15px;
  font-weight: 700;
  color: #2E7D32;
}

.hall-date, .hall-village {
  font-size: 11px;
  color: #78909C;
  margin-top: 2px;
}

/* 遊戲結束結算彈窗 */
.modal-gameover {
  max-width: 520px;
  width: 92%;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: center;
}

.gameover-banner {
  background: linear-gradient(135deg, #66BB6A, #43A047);
  color: #FFFFFF;
  padding: 14px 18px;
  font-size: 19px;
  font-weight: 800;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.gameover-body {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
}

.gameover-scores {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.shot-preview {
  width: 100%;
  display: flex;
  justify-content: center;
}

.shot-preview img {
  max-width: 100%;
  max-height: 150px;
  border-radius: 10px;
  border: 2px solid #CFD8DC;
  box-shadow: var(--shadow-sm);
  object-fit: cover;
}

.go-score-big {
  font-size: 28px;
  font-weight: 900;
  color: #2E7D32;
}

.go-score-detail {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: #546E7A;
  margin: 4px 0;
}

/* 固定底部重來／下載操作列 */
.gameover-footer {
  padding: 12px 18px;
  background: #F8FAFC;
  border-top: 1px solid #E2E8F0;
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

.gameover-footer button {
  flex: 1;
  max-width: 220px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

#btn-gameover-restart {
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.35);
  transition: all 0.2s ease;
}

#btn-gameover-restart:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.45);
}

@keyframes pulseGlow {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7); }
  50% { transform: scale(1.03); box-shadow: 0 0 0 8px rgba(76, 175, 80, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

.pulse-highlight {
  animation: pulseGlow 1.4s infinite ease-in-out;
}

/* 🔊 音效按鈕與 🎵 背景音樂按鈕 */
.btn-sound,
.btn-bgm {
  font-size: 14px;
  padding: 6px 10px;
  min-width: 42px;
}

.btn-bgm.active {
  background: #E8F5E9;
  border-color: #81C784;
  color: #2E7D32;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.25);
}

/* 🏆 名人堂分頁標籤 */
.hall-tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: #ECEFF1;
  border: 1px solid #CFD8DC;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #546E7A;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--primary, #2E7D32);
  color: #FFFFFF;
  border-color: var(--primary, #2E7D32);
  box-shadow: 0 2px 6px rgba(46, 125, 50, 0.3);
}

/* 🏅 文明稱號徽章 */
.civ-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #FFF9C4, #FFF176);
  color: #F57F17;
  font-weight: 800;
  font-size: 16px;
  border: 2px solid #FBC02D;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(251, 192, 45, 0.25);
  animation: pulseBadge 2s infinite ease-in-out;
}

@keyframes pulseBadge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* 👑 本局 MVP 建築卡片 */
.go-mvp-card {
  background: #F8F9FA;
  border: 2px dashed #B0BEC5;
  border-radius: 12px;
  padding: 10px 14px;
  margin: 10px 0;
  text-align: left;
}

.mvp-tag {
  font-size: 11px;
  font-weight: 800;
  color: #D84315;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mvp-content {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.mvp-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: contain;
  background: #FFFFFF;
  border: 1px solid #CFD8DC;
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

.mvp-name {
  font-size: 15px;
  font-weight: 800;
  color: #263238;
}

.mvp-tier {
  font-size: 11px;
  font-weight: 700;
  color: #78909C;
  margin-top: 2px;
}

/* 🚀 Cloudflare 全球登錄區 */
.go-upload-section {
  background: #E8F5E9;
  border: 1px solid #A5D6A7;
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
}

.upload-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.input-player-name {
  flex: 1;
  max-width: 200px;
  padding: 8px 12px;
  border: 2px solid #81C784;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  outline: none;
  background: #FFFFFF;
  color: #2E7D32;
}

.input-player-name:focus {
  border-color: #2E7D32;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.btn-upload {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 800;
  background: linear-gradient(135deg, #2E7D32, #1B5E20);
  border: none;
  border-radius: 8px;
  color: #FFFFFF;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-upload:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(46, 125, 50, 0.3);
}

.btn-upload:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.upload-status-text {
  font-size: 12px;
  font-weight: 700;
  color: #2E7D32;
  margin-top: 6px;
  min-height: 16px;
}

/* 全球榜單項目樣式 */
.global-rank-badge {
  font-size: 16px;
  font-weight: 900;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #ECEFF1;
  color: #455A64;
}

.rank-1 .global-rank-badge { background: #FFD54F; color: #E65100; }
.rank-2 .global-rank-badge { background: #CFD8DC; color: #37474F; }
.rank-3 .global-rank-badge { background: #FFAB91; color: #BF360C; }

/* =========================================================================
   📱 手機直式版面 (Portrait Mobile Layout)
   由上而下：精簡標題列 ➔ 狀態列(回合/分數/重刷/資源) ➔ 正方形地圖 ➔ 橫向滑動積木池
   ========================================================================= */
@media (max-width: 820px) {
  html, body {
    height: 100dvh;
    overscroll-behavior: none;
  }

  body, #app {
    height: 100dvh;
  }

  /* 精簡標題列 */
  .app-header {
    height: 46px;
    padding: 0 8px;
    gap: 8px;
  }
  .logo-icon { font-size: 18px; flex-shrink: 0; }
  .header-logo {
    gap: 4px;
    flex-shrink: 0;
  }
  .header-logo h1 {
    font-size: 14px;
    white-space: nowrap;
  }
  .logo-en { display: none; }
  .header-actions {
    gap: 4px;
    overflow-x: auto;
    flex-shrink: 1;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .header-actions::-webkit-scrollbar {
    display: none;
  }
  .btn-nav {
    padding: 5px 7px;
    font-size: 11px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* 版面改為縱向堆疊 */
  .game-layout {
    flex-direction: column;
  }

  /* 狀態面板：橫向精簡列 */
  .status-panel {
    width: 100%;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 2px solid #E2E8F0;
    padding: 6px 8px;
    gap: 6px;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr 1fr;
    overflow: visible;
  }
  .panel-card {
    padding: 6px 8px;
    border-radius: 8px;
  }
  .turn-title { font-size: 12px; line-height: 1.3; }
  .badge-phase { font-size: 10px; padding: 1px 4px; }
  .score-card { display: flex; flex-direction: column; justify-content: center; }
  .score-title { font-size: 10px; }
  .score-number { font-size: 20px; margin-top: 0; line-height: 1.1; }

  .resources-card {
    grid-column: 1 / -1;
    order: 4;
    padding: 5px 6px;
  }
  .resources-card .card-heading,
  .resources-card .card-subheading { display: none; }
  .resource-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }
  .resource-item {
    flex-direction: column;
    padding: 3px 2px;
    gap: 0;
    border-left-width: 0;
    border-top: 3px solid #B0BEC5;
    font-size: 11px;
    text-align: center;
  }
  .elem-icon { margin-right: 0; font-size: 14px; }
  .elem-name { display: none; }
  .elem-value { font-size: 13px; line-height: 1.2; }
  .elem-value small { display: block; font-size: 9px; margin-left: 0 !important; }

  .action-card { display: flex; align-items: center; }
  .action-card .btn-primary {
    padding: 6px 4px;
    font-size: 11px;
    line-height: 1.2;
  }
  .reroll-tip { display: none; }

  /* 地圖視口：吃滿剩餘空間 */
  .viewport-section {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    touch-action: none;
  }

  /* 單格資訊：縮小並貼左上，避免遮住地圖中央 */
  .inspector-tooltip {
    top: 6px;
    left: 6px;
    right: auto;
    width: auto;
    max-width: 62%;
    padding: 6px 8px;
    font-size: 11px;
    border-radius: 8px;
  }
  .inspector-title { padding-bottom: 3px; margin-bottom: 4px; }
  .inspector-row { margin-bottom: 2px; }
  .inspector-dev { margin-top: 4px; padding-top: 3px; font-size: 11px; }
  .inspector-alert { margin-top: 4px; padding: 3px; font-size: 11px; }

  /* 確認放置列：貼底、全寬、大按鈕易點 */
  .placement-confirm-bar {
    bottom: 8px;
    width: calc(100% - 16px);
    border-radius: 16px;
    padding: 8px 10px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .confirm-info { font-size: 12px; gap: 6px; flex-wrap: wrap; }
  .confirm-actions { gap: 8px; }
  .confirm-actions button {
    flex: 1;
    min-height: 40px;
    font-size: 14px;
  }

  /* 積木池：固定高度、橫向滑動 */
  .pool-footer {
    height: auto;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .pool-notice {
    font-size: 11px;
    margin-bottom: 4px;
    line-height: 1.3;
  }
  .pool-list {
    flex: none;
    justify-content: flex-start;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 2px 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .pool-card {
    flex: 0 0 158px;
    max-width: none;
    padding: 6px 8px;
    scroll-snap-align: start;
  }
  .pool-card:hover:not(.is-locked) { transform: none; }
  .pool-card.is-selected { transform: translateY(-3px); }
  .card-thumb { width: 44px; height: 44px; }
  .card-title { font-size: 12px; }
  .card-body { font-size: 10px; gap: 2px; }
  .card-score { display: none; }

  /* 結算操作區手機適配 */
  .settle-container {
    width: 100%;
    padding: 2px 0;
  }
  .settle-card {
    flex-direction: column;
    padding: 8px 12px;
    gap: 8px;
    text-align: center;
  }
  .settle-info {
    align-items: center;
  }
  .settle-badge {
    font-size: 13px;
  }
  .settle-hint {
    font-size: 11px;
    line-height: 1.3;
  }
  .btn-settle {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* 彈窗 */
  .modal-box {
    width: 96%;
    max-height: 90dvh;
    border-radius: 12px;
  }
  .modal-header { padding: 10px 12px; }
  .modal-header h2 { font-size: 15px; }
  .modal-title-group { gap: 8px; flex-wrap: wrap; }
  .modal-content { padding: 10px; }
  .comp-filter-bar { padding: 8px 10px; }
  .comp-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .comp-card { padding: 8px; }
  .comp-thumb-box { height: 90px; }
  .btn-text-danger { font-size: 10px; padding: 3px 6px; }
  .evo-thumb { width: 56px; height: 56px; }
  .modal-gameover {
    width: 96%;
    max-height: 94dvh;
    border-radius: 12px;
  }
  .gameover-banner {
    padding: 10px 14px;
    font-size: 16px;
  }
  .gameover-body {
    padding: 10px 12px;
    gap: 8px;
  }
  .shot-preview img {
    max-height: 110px;
  }
  .go-score-big {
    font-size: 22px;
  }
  .go-score-detail {
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
  }
  .go-upload-section {
    padding: 8px 10px;
    margin: 4px 0;
  }
  .upload-row {
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }
  .input-player-name {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    font-size: 13px;
    padding: 8px;
  }
  .btn-upload {
    width: 100%;
    padding: 9px;
    font-size: 13px;
  }
  .gameover-footer {
    padding: 8px 12px;
    gap: 8px;
  }
  .gameover-footer button {
    max-width: 100%;
    padding: 9px 10px;
    font-size: 13px;
  }
}
