/* frontend/style.css */
:root {
  --primary-color: #3a7e5c;
  --secondary-color: #82c091;
  --background-color: #f5f8f6;
  --card-bg: #ffffff;
  --text-color: #333333;
  --border-radius: 8px;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --tile-hover: #e0f2e9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Noto Sans TC', sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--background-color);
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  /* Add padding-top to prevent content from hiding behind fixed menu button */
  padding-top: 80px;
}

.container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  /* Remove left padding if menu is fixed on the left */
  /* padding-left: 40px; */
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 16px;
}

.header h1 {
  color: var(--primary-color);
  margin-bottom: 8px;
  font-size: 2rem;
}

.header p {
  color: #666;
  max-width: 600px;
  margin: 0 auto;
}

.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  width: 100%;
}

.card-header h2 {
  font-size: 1.25rem;
  color: var(--primary-color);
}

/* 結果區域共用樣式 */
#result {
  min-height: 100px;
  width: 100%;
}

.result-header {
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  width: 100%;
}

/* 共用加載器樣式 */
.loader {
  display: none;
  text-align: center;
  padding: 20px;
  width: 100%;
}

.loader:after {
  content: " ";
  display: inline-block;
  width: 20px;
  height: 20px;
  margin: 8px;
  border-radius: 50%;
  border: 3px solid var(--primary-color);
  border-color: var(--primary-color) transparent;
  animation: spin 1.2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 文字置中樣式 */
.text-center {
  text-align: center;
  width: 100%;
  display: block;
  color: #666;
}

/* 按鈕樣式 */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
  font-size: 16px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: #306b4d;
}

.btn-secondary {
  background-color: #e2e8f0;
  color: #4a5568;
}

.btn-secondary:hover {
  background-color: #cbd5e0;
}

.btn-danger {
  background-color: #e53e3e;
  color: white;
}

.btn-danger:hover {
  background-color: #c53030;
}

.btn-warning {
  background-color: #ed8936;
  color: white;
}

.btn-warning:hover {
  background-color: #dd6b20;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 18px;
}

/* 通用彈出視窗和模態框樣式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1001;
}

.modal-content {
  background-color: white;
  padding: 25px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  max-width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

/* 通用動畫效果 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* --- Common Tile Selector & Hand Styles --- */
.tile-selector {
  margin-bottom: 24px;
  width: 100%;
}

.tabs, .modal-tabs {
  display: flex;
  margin-bottom: 15px;
  border-bottom: 1px solid #ddd;
  width: 100%;
}

.tab, .modal-tab {
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.3s ease;
}

.tab.active, .modal-tab.active {
  border-bottom: 2px solid var(--primary-color);
  font-weight: 500;
  color: var(--primary-color);
}

.tile-group, .modal-tile-group {
  display: none; /* Hidden by default */
  width: 100%;
}

.tile-group.active {
  display: flex; /* Use flexbox */
  justify-content: center; /* Center tiles horizontally */
  align-items: center; /* Align items vertically */
  flex-wrap: nowrap; /* Prevent wrapping to the next line */
  gap: 5px; /* Adjust spacing between tiles */
  width: 100%;
  overflow: hidden; /* Hide potential overflow */
}

.modal-tile-group.active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 8px;
}

.tile, .modal-tile {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 5px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
  touch-action: manipulation; /* Disable double-tap zoom */
}

.tile {
  flex: 0 1 auto; /* Allow shrinking, don't grow, base size on content */
}

.tile:hover, .modal-tile:hover {
  background-color: var(--tile-hover);
  transform: translateY(-2px);
}

.tile img, .modal-tile img, .problem-tile img, .waiting-tile-preview img {
  max-width: 100%; /* Ensure image scales down */
  height: auto; /* Maintain aspect ratio */
  display: block; /* Remove extra space below image */
}

.tile.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.tile.disabled:hover {
  background-color: #fff;
  transform: none;
}

.hand-area {
  min-height: 110px; /* Ensure minimum height */
  width: 100%;
  margin-top: 15px;
}

#hand, #drawn-tile-display, .tile-display { /* Apply to all tile display areas */
  display: flex;
  flex-wrap: wrap;
  gap: 8px; /* Spacing between tiles */
  min-height: 60px; /* Ensure area has height even when empty */
  padding: 10px;
  background-color: var(--hand-bg, #f0f0f0); /* Use variable or default */
  border-radius: var(--border-radius);
  margin-bottom: 15px; /* Space before controls */
  justify-content: center; /* Center tiles if they don't fill the row */
}

.hand-tile, .drawn-tile-item, .problem-tile, .waiting-tile-preview { /* Common styles for tile displays */
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative; /* For potential future additions like tooltips */
}

.hand-tile img, .drawn-tile-item img {
  width: 40px; /* Reduced tile size from 50px */
  height: auto;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 3px;
  background: white;
  transition: transform 0.2s ease;
}

.hand-tile:hover img, .drawn-tile-item:hover img {
  transform: translateY(-3px); /* Slight lift effect on hover */
}

.drawn-tile-item span { /* Specific style for the "已選摸牌" text */
   font-size: 0.8em;
   color: #666;
   margin-top: 3px;
}

#hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  min-height: 60px; /* Minimum height for the hand display */
  width: 100%;
  padding: 5px; /* Add some padding */
  border: 1px dashed #eee; /* Optional: subtle border */
  border-radius: 4px;
}

.hand-controls {
  display: flex;
  justify-content: space-between; /* Distribute buttons */
  align-items: center;
  margin-top: 15px; /* Space above buttons */
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
  gap: 10px; /* Add gap between buttons when wrapping */
}

/* Responsive adjustments for controls if needed */
@media (max-width: 480px) {
  .hand-controls {
    justify-content: center; /* Center buttons on very small screens */
  }
}

/* --- End Common Tile Selector & Hand Styles --- */


/* 多功能菜單樣式 */
.menu-button {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  z-index: 1000;
  transition: all 0.3s ease;
}

.menu-button:hover {
  background-color: #2a6e4c;
  transform: scale(1.1);
}

.menu-icon {
  width: 24px;
  height: 24px;
}

.menu-panel {
  position: fixed;
  top: 80px;
  left: 20px;
  background-color: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  width: 220px;
  z-index: 999;
  overflow: hidden;
  transform: translateX(-110%);
  transition: transform 0.3s ease;
}

.menu-panel.open {
  transform: translateX(0);
}

.menu-header {
  background-color: var(--primary-color);
  color: white;
  padding: 15px;
  font-weight: bold;
}

.menu-items {
  padding: 10px 0;
}

.menu-item {
  padding: 12px 15px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none; /* Ensure links look like menu items */
  color: var(--text-color); /* Ensure links look like menu items */
}

.menu-item:hover {
  background-color: #f0f0f0;
}

.menu-item.active {
  background-color: var(--tile-hover);
  border-left: 4px solid var(--primary-color);
  font-weight: bold; /* Highlight active item */
}

.menu-item-icon {
  margin-right: 10px;
  width: 20px;
  height: 20px;
}

.menu-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.menu-item.disabled:hover {
  background-color: transparent;
}

.coming-soon-badge {
  background-color: #f59e0b;
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 10px;
  margin-left: 8px;
}

/* 頁腳樣式 */
.footer {
  margin-top: 40px;
  padding: 20px;
  background-color: var(--primary-color);
  color: white;
  border-radius: var(--border-radius);
}

.footer-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
}

.footer-section {
  flex: 1;
  min-width: 200px;
  margin-bottom: 20px;
  padding: 0 15px;
}

.footer-section h3 {
  color: var(--secondary-color);
  margin-bottom: 15px;
  font-size: 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 8px;
}

.footer-section ul {
  list-style: none;
  padding: 0;
}

.footer-section ul li {
  margin-bottom: 8px;
}

.footer-section a {
  color: white;
  text-decoration: none;
  transition: all 0.2s;
}

.footer-section a:hover {
  color: var(--secondary-color);
  text-decoration: underline;
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.9rem;
  width: 100%;
}

/* 響應式設計 */
@media (max-width: 768px) {
  body {
    padding-top: 70px; /* Adjust padding for smaller screens */
  }
  .menu-button {
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
  }

  .menu-panel {
    top: 60px;
    left: 10px;
    width: 200px;
  }
  .footer-section {
    flex: 0 0 50%;
  }
  /* Adjust tile sizes for tablets */
  .tile img, .waiting-tile-preview img, .problem-tile img {
    width: 35px;
  }
}

@media (max-width: 480px) {
  .footer-section {
    flex: 0 0 100%;
  }
   /* Further adjust tile sizes for mobile */
   .tile img {
     width: 30px;
   }
   .hand-controls {
       flex-direction: column; /* Stack buttons vertically */
       align-items: stretch; /* Make buttons full width */
   }
   .hand-controls .btn {
       width: 100%; /* Make buttons full width */
       margin-bottom: 5px; /* Add space between stacked buttons */
   }
   .hand-controls .btn:last-child {
       margin-bottom: 0;
   }
}

/* 響應式設計加強（手機優化） */
@media (max-width: 600px) {
  body {
    padding: 8px;
    padding-top: 60px;
    font-size: 16px;
  }
  .container {
    gap: 12px;
    padding: 0;
  }
  .header h1 {
    font-size: 1.2rem;
  }
  .card {
    padding: 10px;
    margin-bottom: 12px;
  }
  .card-header h2 {
    font-size: 1rem;
  }
  .menu-button {
    top: 8px;
    left: 8px;
    width: 38px;
    height: 38px;
  }
  .menu-panel {
    top: 50px;
    left: 8px;
    width: 90vw;
    min-width: 0;
    max-width: 320px;
  }
  .footer {
    padding: 10px;
    font-size: 0.95em;
  }
  .footer-section {
    min-width: 120px;
    padding: 0 5px;
  }
  .footer-section h3 {
    font-size: 1em;
    margin-bottom: 8px;
  }
  .footer-bottom {
    font-size: 0.8em;
    padding-top: 10px;
  }
  .btn, .btn-lg {
    font-size: 15px;
    padding: 8px 12px;
  }
  /* Mobile tile sizes */
  .tile img {
    width: 28px;
  }
  .waiting-tile img {
    width: 32px;
  }
  .discard-tile img {
    width: 36px;
  }
  .hand-area, #hand, .tile-display {
    min-height: 40px;
    gap: 4px;
    padding: 4px;
  }
  .modal-content {
    width: 98vw;
    padding: 8px;
  }
  .modal-tile img, .problem-tile img, .waiting-tile-preview img {
    width: 24px;
  }
}
