/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: #d0d0d0;
  min-height: 100%;
}

body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  color: #222;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0 40px;
  gap: 16px;
}

/* === 控制區（搜尋 + 切換）=== */
#controls {
  width: 390px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}

/* === 搜尋區 === */
#search-section {
  background: #c0392b;
  padding: 16px 16px 20px;
  color: white;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  opacity: 0.85;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.search-bar {
  display: flex;
  gap: 8px;
}

#symbol-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  font-size: 18px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.95);
  color: #222;
  outline: none;
  -webkit-appearance: none;
}

#symbol-input::placeholder {
  color: #aaa;
  font-size: 14px;
  font-weight: 400;
}

#search-btn {
  padding: 12px 18px;
  background: white;
  color: #c0392b;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  min-width: 60px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

#search-btn:active {
  opacity: 0.7;
}

/* === 漲跌停切換 === */
#mode-toggle {
  display: flex;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.mode-btn {
  flex: 1;
  padding: 13px 0;
  font-size: 15px;
  font-weight: 700;
  border: none;
  background: #f7f7f7;
  color: #aaa;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 1px;
}

#btn-up.active {
  background: #fff0f0;
  color: #c0392b;
  border-bottom: 3px solid #c0392b;
}

#btn-down.active {
  background: #f0fff4;
  color: #27ae60;
  border-bottom: 3px solid #27ae60;
}

/* === 手機畫面容器 === */
#app {
  width: 390px;
  min-height: 200px;
  background: #f0f0f0;
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
  border-radius: 28px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* === 載入中 === */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 16px;
  gap: 16px;
  color: #888;
  font-size: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #ddd;
  border-top-color: #c0392b;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === 錯誤訊息 === */
#error-msg {
  margin: 16px;
  padding: 14px 16px;
  background: #fff0f0;
  border: 1px solid #f5c6cb;
  border-radius: 10px;
  color: #c0392b;
  font-size: 14px;
  line-height: 1.5;
}

/* === 月曆 Header === */
#calendar-header {
  background: #c0392b;
  color: white;
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: background 0.25s;
}

#calendar-header.mode-down {
  background: #27ae60;
}

#stock-info-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

#stock-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

#header-label {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.85;
  white-space: nowrap;
  flex-shrink: 0;
}

#stock-symbol {
  font-size: 20px;
  font-weight: 700;
}

#stock-name {
  font-size: 14px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 230px;
}

#month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#month-nav button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 30px;
  line-height: 1;
  padding: 2px 16px 4px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

#month-nav button:active {
  background: rgba(255, 255, 255, 0.35);
}

#month-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* === 月曆本體 === */
#calendar {
  background: white;
}

.weekday-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f7f7f7;
  border-bottom: 1px solid #e0e0e0;
}

.weekday-header span {
  text-align: center;
  padding: 8px 0;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  letter-spacing: 0.5px;
}

/* 週日第1欄，週六第7欄 */
.weekday-header span:nth-child(1) { color: #c0392b; }
.weekday-header span:nth-child(7) { color: #27ae60; }

#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 76px;
  gap: 1px;
  background: #e0e0e0;
}

/* === 月曆格子 === */
.calendar-cell {
  background: white;
  height: 76px;
  padding: 5px 4px 4px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.calendar-cell.weekend {
  background: #fafafa;
}

.calendar-cell.empty {
  background: #f5f5f5;
}

.calendar-cell.today {
  background: #fffbe6;
}

/* 今日外框 */
.calendar-cell.today::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid #e6a800;
  pointer-events: none;
}

.cell-date {
  position: absolute;
  top: 5px;
  left: 5px;
  font-size: 11px;
  color: #bbb;
  font-weight: 500;
  line-height: 1;
}

.calendar-cell.today .cell-date {
  color: #e6a800;
  font-weight: 700;
}

/* 今日日期圓圈 */
.calendar-cell.today .cell-date-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #e6a800;
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}

.cell-price {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #c0392b;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
}

.cell-price.down {
  color: #27ae60;
}

/* === 基準資訊 === */
#base-info {
  padding: 12px 16px;
  font-size: 13px;
  color: #888;
  background: white;
  border-top: 1px solid #eee;
  text-align: center;
}

#base-info strong {
  color: #c0392b;
  font-weight: 700;
}

/* === 圖片操作按鈕 === */
#action-buttons {
  width: 390px;
  display: flex;
  gap: 10px;
}

#action-buttons button {
  flex: 1;
  padding: 14px 0;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  transition: opacity 0.15s, transform 0.1s;
}

#action-buttons button:active {
  opacity: 0.8;
  transform: scale(0.97);
}

#btn-download {
  background: #2c3e50;
  color: white;
}

#btn-copy {
  background: white;
  color: #2c3e50;
  border: 2px solid #2c3e50;
}

.btn-icon {
  font-size: 18px;
  line-height: 1;
}

/* === 工具類 === */
.hidden {
  display: none !important;
}
