/* ========================================================= */
/* 通用基礎樣式 (General Base Styles)                       */
/* ========================================================= */
body {
  font-family: 'Arial', sans-serif;
  margin: 0;
  padding: 20px;
  background-color: #f4f4f4;
  color: #333;
  line-height: 1.6;
  box-sizing: border-box;
  min-height: 100vh;
  display: flex;
  flex-direction: column; /* 確保子元素垂直排列 */
  align-items: center; /* 讓內容在水平方向上置中 */
}




.main-container {
  width: 100%;
  max-width: 600px;
  background: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s, color 0.3s, box-shadow 0.3s;
  text-align: center;
 margin-top: 20px;
}

/* ========================================================= */
/* 標題與文字 (Headings and Text)                           */
/* ========================================================= */

h1, h2 {
  text-align: center;
  margin-bottom: 20px;
}

h1 {
  font-size: 2em;
  color: #4CAF50; /* 應用中心標題的特定綠色 */
}

h2 {
  color: #0056b3;
}

/* ========================================================= */
/* 頁首與資訊區塊 (Header & Info Sections)                  */
/* ========================================================= */

.top-bar {
  background-color: #f0f0f0;
  color: #333;
  padding: 15px 20px;
  border-bottom: 2px solid #ccc;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: center; /* 使 flex 容器中的項目在主軸上置中 */
  align-items: center;
  position: relative; /* 設置相對定位，以便絕對定位子元素 */
  width: 100%; /* 確保 top-bar 佔滿寬度 */
}

.top-bar .left-section {
    position: absolute; /* 絕對定位 */
    left: 20px; /* 距離左側 20px */
}

.top-bar .center-section {
    display: flex; /* 使用 flexbox 讓 h1 在 center-section 中置中 */
    justify-content: center;
    align-items: center;
}

.top-bar h1 {
  font-size: 24px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


.top-bar .home-link {
    font-size: 1.1em;
    font-weight: bold;
    color: #0088cc;
    text-decoration: none;
    transition: color 0.3s ease;
}

.top-bar .home-link:hover {
    color: #007bb5;
}

.user-info, .catcoin-info {
  margin-bottom: 20px;
  font-size: 1.1em;
  padding: 10px;
  border-radius: 5px;
  color: #555;
}

.user-info {
  background-color: #e3f2fd;
}

.catcoin-info {
  background-color: #e8f5e9;
}

.catcoin-details {
  text-align: left;
  margin-top: 15px;
  margin-bottom: 20px;
  padding: 10px;
  border: 1px solid #eee;
  border-radius: 5px;
  background-color: #fcfcfc;
  transition: background-color 0.3s, border-color 0.3s;
}

.catcoin-details p {
  margin: 5px 0;
}

.catcoin-details strong {
  color: #007bff;
}

/* ========================================================= */
/* 按鈕與訊息 (Buttons & Messages)                          */
/* ========================================================= */

button {
  margin-top: 15px;
  padding: 12px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1em;
  transition: background-color 0.3s ease;
  white-space: nowrap;
}

button:hover {
  background-color: #0056b3;
}

button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
  color: #666;
}

.message {
  margin-bottom: 20px;
  padding: 10px;
  border-radius: 5px;
  word-wrap: break-word;
  min-height: 30px;
  text-align: center;
  font-size: 1em;
}

.message.info {
  background-color: #e0f7fa;
  color: #007bff;
  border: 1px solid #b2ebf2;
}

.message.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.message.error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.hidden {
  display: none;
}

.back-button {
  display: block;
  width: fit-content;
  margin: 20px auto 0;
  padding: 10px 20px;
  background-color: #6c757d;
  color: white;
  text-decoration: none;
  border-radius: 5px;
  transition: background-color 0.3s ease;
}

.back-button:hover {
  background-color: #5a6268;
}

/* ========================================================= */
/* 功能區塊與導覽 (Section Specific Styles)                 */
/* ========================================================= */

/* Section Selector */
.section-selector {
  margin-bottom: 10px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap; /* 讓按鈕在小螢幕時自動換行 */
}

.section-selector button {
  padding: 15px 15px;
  font-size: 1.1em;
  border-radius: 8px;
  transition: background-color 0.3s ease, transform 0.2s ease;
  flex-grow: 1;
  max-width: 180px;
}

.section-selector button:hover {
  background-color: #0056b3;
  transform: translateY(-2px);
}

.section-content {
  border-top: 1px solid #eee;
  padding-top: 20px;
  margin-top: 10px;
}

.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

/* Coupon Section */
#coupon-section h2 {
  color: #ff9800;
}

.coupon-item {
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 15px;
  margin-bottom: 15px;
  background-color: #f9f9f9;
  transition: background-color 0.3s, border-color 0.3s;
  text-align: left;
}

.coupon-item.redeemed {
  background-color: #e9ecef;
  border-color: #ced4da;
  color: #6c757d;
}

.coupon-item h3 {
  color: #007bff;
  margin-top: 0;
  margin-bottom: 10px;
}

.coupon-item p {
  margin: 5px 0;
  font-size: 0.95em;
  color: #555;
}

.coupon-item button {
  background-color: #28a745;
  color: white;
  padding: 8px 15px;
  border-radius: 4px;
  font-size: 1em;
  float: right;
  margin-top: 0;
}

.coupon-item button:hover {
  background-color: #218838;
}

.coupon-message {
  margin-top: 10px;
  padding: 8px;
  border-radius: 4px;
  font-size: 0.9em;
  font-weight: bold;
  word-wrap: break-word;
}

/* Game Area */
.game-area {
  text-align: center;
  margin-top: 30px;
  padding: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background-color: #fcfcfc;
  transition: background-color 0.3s, border-color 0.3s;
}

.game-area button {
  padding: 12px 25px;
  font-size: 1.1em;
  margin-bottom: 15px;
  width: auto;
  max-width: 100%;
}

#start-game-btn {
  background-color: #007bff;
  padding: 15px 30px;
  font-size: 1.2em;
  margin-bottom: 20px;
}

#game-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

#guess-input {
  padding: 12px;
  font-size: 1.1em;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 100%;
  max-width: 250px;
  text-align: center;
  box-sizing: border-box;
}

#submit-guess-btn {
  background-color: #28a745;
  width: 100%;
  max-width: 250px;
}

#guesses-history {
  list-style: none;
  padding: 10px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 5px;
  text-align: left;
  background-color: #fdfdfd;
  transition: background-color 0.3s, border-color 0.3s;
  margin-top: 20px;
}

#guesses-history li {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

#guesses-history li:last-child {
  border-bottom: none;
}

#guesses-history li strong {
  color: #007bff;
}

/* Query Section */
#query-section h2 {
  color: #1a73e8;
}

#query-iframe {
  width: 100%;
  height: 500px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #fdfdfd;
}

.container { /* For query_usertable.php */
  max-width: 600px;
  margin: auto;
  background: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

form {
  margin-bottom: 30px;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 5px;
  background-color: #f9f9f9;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

label {
  margin-bottom: 10px;
  font-weight: bold;
  display: flex;
  align-items: center;
}

input[type="radio"] {
  margin-right: 8px;
}

select {
  padding: 10px 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 10px;
  width: 100%;
  max-width: 250px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

th, td {
  border: 1px solid #ddd;
  padding: 10px;
  text-align: left;
}

th {
  background-color: #e9e9e9;
  font-weight: bold;
}

tr:nth-child(even) {
  background-color: #f2f2f2;
}

.no-results {
  text-align: center;
  color: #666;
  margin-top: 30px;
  font-size: 1.1em;
}

/* ========================================================= */
/* 深色模式 (Dark Mode)                                     */
/* ========================================================= */

@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a1a1a;
    color: #e0e0e0;
  }

  .main-container {
    background: #2a2a2a;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  }

  .top-bar {
    background-color: #1e1e1e;
    color: #f0f0f0;
    border-bottom: 2px solid #555;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  }

  .top-bar h1 {
    color: #f0f0f0;
  }

  h1, h2 {
    color: #8bb9ed;
  }

  h1 {
    color: #6cbf6f;
  }

  .user-info {
    background-color: #003366;
    color: #99ccff;
  }

  .catcoin-info {
    background-color: #1a4d1f;
    color: #88cc88;
  }

  .catcoin-details {
    background-color: #333;
    border-color: #444;
  }

  .catcoin-details strong {
    color: #a7d9ff;
  }

  button {
    background-color: #0056b3;
    color: #fff;
  }

  button:hover {
    background-color: #004080;
  }

  button:disabled {
    background-color: #444;
    color: #999;
  }

  .message.info {
    background-color: #004c6f;
    color: #8bb9ed;
    border-color: #007bff;
  }

  .message.success {
    background-color: #0f5132;
    color: #9adea4;
    border-color: #218838;
  }

  .message.error {
    background-color: #8c1e2d;
    color: #f8d7da;
    border-color: #dc3545;
  }

  .back-button {
    background-color: #4a4a4a;
  }

  .back-button:hover {
    background-color: #5a5a5a;
  }

  .section-selector button {
    background-color: #0056b3;
  }

  .section-selector button:hover {
    background-color: #004080;
  }

  .section-selector button:disabled {
    background-color: #444;
  }

  .section-content {
    border-top-color: #444;
  }

  #coupon-section h2 {
    color: #ffc107;
  }

  .coupon-item {
    background-color: #333;
    border-color: #444;
  }

  .coupon-item.redeemed {
    background-color: #444;
    border-color: #555;
    color: #a0a0a0;
  }

  .coupon-item.redeemed h3 {
    color: #bbbbbb;
  }

  .coupon-item h3 {
    color: #a7d9ff;
  }

  .coupon-item p {
    color: #e0e0e0;
  }

  .coupon-item button {
    background-color: #1e7e34;
  }

  .coupon-item button:hover {
    background-color: #155d22;
  }

  .coupon-item button:disabled {
    background-color: #444;
    color: #999;
  }

  .game-area {
    background-color: #333;
    border-color: #444;
  }

  #start-game-btn {
    background-color: #0056b3;
  }

  #start-game-btn:hover {
    background-color: #004080;
  }

  #guess-input {
    background-color: #444;
    border-color: #666;
    color: #eee;
  }

  #guess-input::placeholder {
    color: #aaa;
  }

  #submit-guess-btn {
    background-color: #1e7e34;
  }

  #submit-guess-btn:hover {
    background-color: #155d22;
  }

  #guesses-history {
    background-color: #333;
    border-color: #444;
  }

  #guesses-history li {
    border-bottom-color: #4a4a4a;
  }

  #guesses-history li strong {
    color: #a7d9ff;
  }

  #query-section h2 {
    color: #99ccff;
  }

  #query-iframe {
    border-color: #444;
    background-color: #333;
  }

  .container {
    background: #2a2a2a;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  }

  form {
    background-color: #333;
    border-color: #444;
  }

  label {
    color: #e0e0e0;
  }

  select {
    background-color: #444;
    border-color: #666;
    color: #eee;
  }

  select option {
    background-color: #444;
    color: #eee;
  }

  table {
    border-color: #555;
  }

  th, td {
    border-color: #555;
  }

  th {
    background-color: #444;
    color: #e0e0e0;
  }

  tr:nth-child(even) {
    background-color: #3a3a3a;
  }

  .no-results {
    color: #aaa;
  }
}

/* ========================================================= */
/* 響應式設計 (Responsive Design)                           */
/* ========================================================= */

@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .main-container {
    margin: 10px auto;
    padding: 20px 15px;
  }

  h1 {
    font-size: 1.8em;
  }

  .user-info, .catcoin-info {
    font-size: 1em;
  }

  .section-selector {
    flex-direction: column;
  }

  .section-selector button {
    max-width: 100%;
  }

  .coupon-item {
    padding: 10px;
  }

  .coupon-item h3 {
    font-size: 1.1em;
  }

  .coupon-item p {
    font-size: 0.9em;
  }

  .coupon-item button {
    width: 100%;
    margin-top: 10px;
    float: none;
  }

  .game-area button {
    font-size: 1em;
    padding: 10px 20px;
  }

  #start-game-btn {
    font-size: 1.1em;
    padding: 12px 25px;
  }

  #game-controls {
    flex-direction: column;
    gap: 10px;
  }

  #guess-input, #submit-guess-btn {
    width: 100%;
    max-width: none;
  }

  select {
    width: 100%;
    max-width: none;
  }
  
  form button {
      align-self: center;
  }

  #query-iframe {
    height: 400px;
  }

  th, td {
    padding: 8px;
    font-size: 0.9em;
  }
}