:root {
  --bg-sky-top: #1b262c;
  --bg-sky-bot: #2c3e50;
  --bg-soil-top: #3e2723;
  --bg-soil-bot: #1a0f0d;
  --panel-bg: rgba(22, 28, 36, 0.88);
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent-green: #66bb6a;
  --accent-gold: #ffca28;
  --accent-blue: #4fc3f7;
  --text-main: #f5f5f5;
  --text-dim: #9e9e9e;
  --card-bg: #212b36;
  --card-border: #37474f;
  --card-hover: #2e3c4a;
}

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

html, body {
  font-family: 'Noto Serif TC', serif;
  background: #0f141a;
  color: var(--text-main);
  height: 100%;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: fixed;
  touch-action: manipulation;
}

#game-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* 頂部狀態列 */
#status-bar {
  height: 60px;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  touch-action: manipulation;
  flex-shrink: 0;
}

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

.time-badge {
  font-size: 15px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
}

.btn-preview-tag {
  background: rgba(255, 202, 40, 0.15);
  border: 1px solid rgba(255, 202, 40, 0.35);
  color: #ffca28;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 10px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  touch-action: manipulation;
  transition: all 0.2s ease;
}

.btn-preview-tag:hover, .btn-preview-tag:active {
  background: rgba(255, 202, 40, 0.3);
  border-color: #ffca28;
  transform: scale(1.03);
}

.year-label {
  color: var(--accent-gold);
}

.turn-counter {
  font-size: 12px;
  color: var(--text-dim);
  font-family: sans-serif;
}

.resources {
  gap: 20px;
}

.res-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.25);
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.res-icon {
  font-size: 16px;
}

.res-name {
  font-size: 12px;
  color: var(--text-dim);
}

.res-val {
  font-weight: 700;
  font-family: sans-serif;
  color: #fff;
}

.res-val.highlight {
  color: var(--accent-gold);
}

.weather-badge {
  background: rgba(79, 195, 247, 0.1);
  border: 1px solid rgba(79, 195, 247, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  color: var(--accent-blue);
}

/* 中央主畫布區域 */
#stage-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(to bottom, #101924, #1e2c38 65%, #2a1c17 65%, #150d0a 100%);
}

#plant-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#log-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 24, 32, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 24px;
  border-radius: 24px;
  font-size: 14px;
  color: #eceff1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transition: all 0.3s ease;
}

#plant-quick-stats {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(22, 28, 36, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.8;
  color: #cfd8dc;
  backdrop-filter: blur(8px);
}

#plant-quick-stats span {
  font-weight: 700;
  color: var(--accent-green);
}

/* 下方卡牌操作面板 */
#control-deck {
  height: 250px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 10px 20px;
  z-index: 10;
}

.deck-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.deck-title-area {
  display: flex;
  align-items: center;
  gap: 16px;
}

.deck-main-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
}

.toggle-unavailable-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.toggle-unavailable-label:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #eceff1;
}

.toggle-unavailable-label input[type="checkbox"] {
  accent-color: var(--accent-green);
  cursor: pointer;
}

.btn-primary-action {
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  border: 1px solid #43a047;
  color: #fff;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(27, 94, 32, 0.4);
}

.btn-primary-action:hover {
  background: linear-gradient(135deg, #388e3c, #2e7d32);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(46, 125, 50, 0.6);
}

#cards-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.cards-list {
  display: flex;
  gap: 14px;
  height: 100%;
  align-items: center;
}

/* 環境威脅卡列表容器（支援多張危機卡並存） */
.crisis-deck {
  position: absolute;
  top: 14px;
  left: 18px;
  width: 320px;
  max-height: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  pointer-events: auto;
}

.crisis-deck-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ff8a80;
  background: rgba(30, 16, 14, 0.9);
  border: 1px solid rgba(239, 83, 80, 0.4);
  padding: 4px 10px;
  border-radius: 6px;
  width: fit-content;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.crisis-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 380px;
  padding-right: 4px;
}

.crisis-list::-webkit-scrollbar {
  width: 4px;
}

.crisis-list::-webkit-scrollbar-thumb {
  background: rgba(239, 83, 80, 0.4);
  border-radius: 2px;
}

/* 單張環境危機卡樣式 */
.crisis-card {
  position: relative;
  background: rgba(28, 16, 15, 0.94);
  border: 1.5px solid #ef5350;
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  transition: all 0.25s ease;
}

.crisis-card.resolved {
  background: rgba(16, 30, 18, 0.92);
  border-color: #66bb6a;
  box-shadow: 0 4px 12px rgba(102, 187, 106, 0.2);
}

.crisis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 3px;
}

.crisis-tag {
  font-size: 10px;
  font-weight: 700;
  color: #ff8a80;
  letter-spacing: 0.5px;
}

.crisis-card.resolved .crisis-tag {
  color: #a5d6a7;
}

.crisis-timer {
  font-size: 10px;
  color: #9e9e9e;
}

.crisis-body {
  display: flex;
  gap: 10px;
  align-items: center;
}

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

.crisis-info {
  flex: 1;
}

.crisis-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 2px;
}

.crisis-desc {
  font-size: 11px;
  color: #ef9a9a;
  line-height: 1.35;
  margin-bottom: 4px;
}

.crisis-card.resolved .crisis-desc {
  color: #c8e6c9;
}

.crisis-counter {
  font-size: 10.5px;
  color: #ffca28;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
}

.crisis-status-badge {
  position: absolute;
  top: 7px;
  right: 8px;
  font-size: 9.5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  background: #c62828;
  color: #fff;
}

.crisis-card.resolved .crisis-status-badge {
  background: #2e7d32;
}

/* 精簡卡牌樣式 */
.card-item {
  width: 155px;
  height: 160px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  padding: 12px 10px 10px 10px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .card-item:hover:not(.disabled) {
    transform: translateY(-8px) scale(1.03);
    background: var(--card-hover);
    border-color: var(--accent-green);
    box-shadow: 0 12px 24px rgba(102, 187, 106, 0.25);
  }
}

.card-item:active:not(.disabled) {
  transform: scale(0.96);
  background: var(--card-hover);
  border-color: var(--accent-green);
}

.card-item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.card-cost-badge {
  position: absolute;
  top: 8px;
  right: 36px;
  background: rgba(0, 0, 0, 0.65);
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  border: 1px solid rgba(255, 202, 40, 0.4);
}

.btn-card-info {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #cfd8dc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.2s ease;
  touch-action: manipulation;
  z-index: 5;
}

/* 擴大平板手指點擊熱區 */
.btn-card-info::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

.btn-card-info:hover, .btn-card-info:active {
  background: var(--accent-blue);
  color: #fff;
  transform: scale(1.1);
}

.card-type-tag {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
  line-height: 1.2;
}

.card-brief {
  font-size: 12px;
  color: #81c784;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
}

/* 卡牌詳細資訊彈窗樣式 */
.card-info-box {
  width: 380px;
  max-width: 92vw;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  background: #1e2630;
  border: 1.5px solid #455a64;
  border-radius: 12px;
  padding: 20px;
  color: #eceff1;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8);
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.btn-close-sm {
  background: transparent;
  border: none;
  color: #90a4ae;
  font-size: 20px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
}

.btn-close-sm:hover, .btn-close-sm:active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.info-badges {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.info-section {
  margin-bottom: 14px;
}

.info-section h4 {
  font-size: 13px;
  color: #81c784;
  margin-bottom: 4px;
}

.info-section p {
  font-size: 13px;
  line-height: 1.6;
  color: #cfd8dc;
}

.info-flavor-text {
  font-style: italic;
  color: #90a4ae !important;
}

/* 結局植物標本典藏卡樣式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.botanical-card {
  width: 900px;
  max-width: 95vw;
  max-height: 92vh;
  background: #fbf7ee;
  color: #2c251e;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  padding: 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.botanical-frame {
  border: 2px solid #8d6e63;
  outline: 1px dashed #bcaaa4;
  outline-offset: -5px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-sizing: border-box;
  max-height: 100%;
}

.specimen-header {
  text-align: center;
  border-bottom: 1px solid #d7ccc8;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.botanical-tag {
  font-size: 11px;
  letter-spacing: 2px;
  color: #8d6e63;
  font-weight: 700;
}

.specimen-title {
  font-family: 'Cinzel', serif;
  font-size: 28px;
  color: #3e2723;
  margin-top: 4px;
}

.specimen-latin {
  font-style: italic;
  font-size: 13px;
  color: #6d4c41;
}

.specimen-body {
  flex: 1;
  display: flex;
  gap: 24px;
  align-items: center;
}

.specimen-visual {
  flex: 1;
  height: 100%;
  background: #f5eedc;
  border: 1px solid #e0d5be;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#endgame-canvas {
  width: 100%;
  height: 100%;
}

.specimen-analysis {
  width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.specimen-analysis h3 {
  font-size: 15px;
  color: #4e342e;
  margin-bottom: 10px;
}

.score-breakdown {
  width: 100%;
  background: #f2e9d2;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid #d7ccc8;
  margin-top: 8px;
  font-size: 12px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  color: #5d4037;
}

.score-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #bcaaa4;
  font-size: 14px;
  font-weight: 700;
  color: #274e13;
}

.big-score {
  font-size: 20px;
  color: #1b5e20;
}

.specimen-text {
  font-size: 12px;
  line-height: 1.6;
  color: #4e342e;
  margin-top: 10px;
  font-style: italic;
  text-align: center;
}

.btn-close-specimen {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #c7bca9;
  background: rgba(255, 255, 255, 0.85);
  color: #5d4037;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn-close-specimen:hover {
  background: #efebe9;
  color: #271d18;
  border-color: #8d6e63;
  transform: scale(1.08);
}

.btn-secondary-outline {
  background: rgba(141, 110, 99, 0.1);
  border: 1px solid #8d6e63;
  color: #4e342e;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-secondary-outline:hover {
  background: rgba(141, 110, 99, 0.22);
  color: #271d18;
  border-color: #5d4037;
  transform: translateY(-2px);
}

.specimen-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding-top: 10px;
}

/* --- 觸控平板與響應式螢幕優化 (Tablet & Touch Responsiveness) --- */
button, input, label, .card-item, .res-item, .weather-badge, .time-badge, .btn-primary-action, .btn-secondary-outline {
  touch-action: manipulation;
}

@media (max-width: 900px) {
  #status-bar {
    padding: 0 12px;
    height: 56px;
  }

  .status-group {
    gap: 8px;
  }

  .time-badge {
    padding: 4px 8px;
    font-size: 13px;
  }

  .btn-preview-tag {
    padding: 4px 8px;
    font-size: 11.5px;
    margin-left: 6px;
  }

  .res-item {
    padding: 4px 8px;
    font-size: 12px;
    gap: 4px;
  }

  .weather-badge {
    padding: 4px 10px;
    font-size: 12px;
  }

  .crisis-deck {
    width: 260px;
    left: 10px;
    top: 10px;
  }

  #plant-quick-stats {
    right: 10px;
    top: 10px;
    padding: 8px 12px;
    font-size: 11.5px;
    line-height: 1.6;
  }

  #log-overlay {
    top: 10px;
    font-size: 12px;
    padding: 5px 14px;
    max-width: 75%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #control-deck {
    height: 240px;
    padding: 8px 12px;
  }

  .deck-main-title {
    font-size: 13.5px;
  }

  .toggle-unavailable-label {
    font-size: 11px;
    padding: 3px 8px;
  }

  /* 標本彈窗在直式平板時的彈性適配 */
  .botanical-card {
    width: 95vw;
    max-height: 94dvh;
    padding: 10px;
  }

  .botanical-frame {
    padding: 10px 14px;
  }

  .specimen-header {
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .specimen-title {
    font-size: 22px;
  }

  .specimen-body {
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
  }

  .specimen-visual {
    width: 100%;
    height: 250px;
    min-height: 250px;
  }

  .specimen-analysis {
    width: 100%;
  }

  #radar-canvas {
    width: 220px;
    height: 220px;
  }

  .specimen-footer {
    gap: 10px;
    padding-top: 8px;
  }
}

@media (max-height: 700px) {
  #control-deck {
    height: 220px;
  }
  .card-item {
    height: 148px;
    width: 145px;
  }
}
