/* =========================================
   1. 🎨 風格系統 (CSS Variables)
   ========================================= */
:root {
  /* 預設 (夜間模式 Dark) */
  --bg: #000000;
  --card: #121212;
  --panel: #1c1c1e;
  --border: #333333;
  --text: #eeeeee;
  --text-sub: #aaaaaa;
  --btn-bg: #2c2c2e;
  --btn-text: #ffffff;
  --input-bg: #222222;

  --accent: #ffd700; /* 夜間：亮金黃 */
  --blue: #0a84ff;
  --green: #30d158;
  --red: #ff453a;
  --split-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

/* 日間模式 (Light) */
[data-theme="light"] {
  --bg: #f2f2f7;
  --card: #ffffff;
  --panel: #ffffff;
  --border: #d1d1d6;
  --text: #000000;
  --text-sub: #666666;
  --btn-bg: #e5e5ea;
  --btn-text: #000000;
  --input-bg: #ffffff;

  --accent: #b45309; /* 日間：深琥珀色 */
  --split-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, sans-serif;
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* Header & Nav */
header {
  padding: 12px 15px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  transition: background 0.3s;
}
.app-name {
  font-size: 18px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.theme-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

.nav-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  padding: 5px 0;
  flex-shrink: 0;
  transition: background 0.3s;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 14px;
  padding: 10px 0;
  font-weight: bold;
  cursor: pointer;
}
.nav-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.page {
  flex: 1;
  overflow-y: auto;
  display: none;
  padding: 15px;
  padding-bottom: 60px;
  position: relative;
}
.page.active {
  display: block;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

/* 工廠 */
.camera-box {
  background: var(--input-bg);
  border: 2px dashed var(--border);
  border-radius: 12px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
  overflow: hidden;
  position: relative;
}
.camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.grade-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 15px;
}
.grade-btn {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 20px 0;
  border-radius: 12px;
  font-weight: bold;
  font-size: 16px;
  transition: all 0.2s;
}
.grade-btn.active {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
  border-color: var(--accent);
}

.input-group {
  position: relative;
  width: 100%;
  margin-bottom: 10px;
}
.input-dark {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 15px;
  border-radius: 10px;
  box-sizing: border-box;
  font-size: 16px;
}
.suggestion-box {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 100;
  max-height: 150px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
.suggestion-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.suggestion-item:active {
  background: var(--blue);
  color: white;
}

.save-btn {
  width: 100%;
  background: var(--blue);
  color: #fff;
  padding: 18px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
  margin-top: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1.2;
}

/* 倉庫 */
.warehouse-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.export-btn {
  background: var(--btn-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
}
.daily-stats {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 10px;
  text-align: center;
  background: var(--card);
  padding: 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.inventory-item {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.inventory-item.sold {
  opacity: 0.6;
  filter: grayscale(0.5);
}
.thumb-box {
  position: relative;
  width: 70px;
  height: 70px;
  flex-shrink: 0;
}
.item-thumb {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
  background: #222;
}
.sold-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  color: #ff453a;
  border: 2px solid #ff453a;
  transform: rotate(-15deg);
  display: none;
}
.inventory-item.sold .sold-overlay {
  display: flex;
}

.item-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 70px;
}
.cost-wrapper {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  width: 80px;
  margin-top: 5px;
}
.currency-symbol {
  color: var(--text-sub);
  font-size: 14px;
  margin-right: 4px;
}
.cost-input {
  background: none;
  border: none;
  color: var(--green);
  font-weight: bold;
  width: 100%;
  padding: 6px 0;
  font-size: 14px;
  outline: none;
}

.item-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
}
.btn-tag {
  background: var(--btn-bg);
  color: var(--text-sub);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-explain {
  background: var(--blue);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 13px;
  white-space: nowrap;
}
.btn-undo {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 13px;
  white-space: nowrap;
}
.btn-del {
  background: none;
  border: none;
  color: var(--red);
  font-size: 16px;
  padding: 5px;
  cursor: pointer;
}
.profit-display {
  font-size: 13px;
  margin-top: 5px;
  font-weight: bold;
}
.grade-select {
  background: var(--input-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
  font-weight: bold;
  font-size: 14px;
  width: 100%;
  margin-bottom: 4px;
}
.item-tags-display {
  color: var(--text-sub);
  font-size: 12px;
  line-height: 1.4;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-top: 2px;
}

/* 直播頁 */
.live-split-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.live-top-half {
  flex: 6;
  position: relative;
  background: #000;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.live-bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.5;
}
.prompter-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.2));
  padding: 15px;
}
.top-info-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.5);
  padding: 10px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.info-grade {
  color: var(--accent);
  font-weight: 900;
  font-size: 16px;
  margin-bottom: 4px;
}
.info-tags {
  font-size: 13px;
  color: #ddd;
  line-height: 1.4;
  text-align: left;
}
.prompter-scroll-area {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 60px;
  padding: 0 10px;
}
.prompter-text {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 1);
  line-height: 1.5;
  text-align: left;
  width: 100%;
}
.prompter-text.spinning {
  filter: blur(3px);
  opacity: 0.7;
}
.spin-container {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 20;
}
.spin-btn {
  background: rgba(255, 215, 0, 0.95);
  color: #000;
  border: 3px solid #fff;
  padding: 12px 40px;
  border-radius: 40px;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  transition: all 0.1s;
  display: inline-block;
}
.spin-btn:active {
  transform: scale(0.95);
}
.spin-btn.stop-mode {
  background: var(--red);
  color: #fff;
  border-color: #ffcccc;
  box-shadow: 0 0 20px rgba(255, 69, 58, 0.6);
}

.live-bottom-half {
  flex: 4;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: 10px 15px;
  position: relative;
  box-shadow: var(--split-shadow);
  z-index: 10;
  transition: background 0.3s;
}
.price-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  padding-bottom: 5px;
  border-bottom: 1px dashed var(--border);
}
.price-display-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}
.price-huge {
  font-size: 50px;
  font-weight: 900;
  color: var(--green);
  line-height: 1;
}
.edit-icon {
  font-size: 24px;
  margin-top: 5px;
  display: inline-block;
  transform: scaleX(-1);
  filter: grayscale(0.2);
}
.live-settings-icon {
  font-size: 24px;
  color: var(--text-sub);
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
}
.safe-line {
  font-size: 14px;
  color: var(--red);
  font-weight: 900;
  margin-top: -5px;
  margin-bottom: 5px;
  text-align: right;
}
.control-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: 1;
}
.btn-act {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 900;
  font-size: 22px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  transition: all 0.2s;
}
.btn-act:active {
  transform: scale(0.96);
  opacity: 0.8;
}
.btn-sold {
  grid-column: span 2;
  background: var(--green);
  color: #000;
  border: none;
  font-size: 22px;
}

footer {
  text-align: center;
  font-size: 10px;
  color: var(--text-sub);
  padding: 10px;
  border-top: 1px dashed var(--border);
  margin-top: 10px;
  flex-shrink: 0;
  background: transparent;
  transition: background 0.3s;
}
footer a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

/* 彈窗 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  width: 85%;
  border: 1px solid var(--border);
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal-header {
  padding: 15px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
  background: var(--card);
  z-index: 2;
}
.modal-thumb {
  width: 70px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid var(--border);
  display: block;
  margin: 0 auto 10px auto;
}
.modal-title {
  margin: 0;
  font-size: 16px;
  color: var(--text);
}
.modal-content {
  padding: 15px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 15px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--card);
  z-index: 2;
}
.modal-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  align-items: center;
  color: var(--text-sub);
}
.modal-input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  width: 80px;
  padding: 8px;
  text-align: center;
  border-radius: 6px;
  font-size: 16px;
}
.price-input-lg {
  width: 100%;
  font-size: 30px;
  text-align: center;
  background: var(--input-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 15px;
}

.cascade-section {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 5px;
}
.cascade-section.visible {
  max-height: 600px;
  opacity: 1;
  margin-bottom: 15px;
}
.tag-group-label {
  font-size: 14px;
  color: var(--blue);
  margin: 10px 0 8px 0;
  font-weight: bold;
  border-left: 3px solid var(--blue);
  padding-left: 8px;
  display: flex;
  align-items: center;
}
.tag-panel-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 5px;
}

/* 🌟 黃底黑字高對比修正 */
.quick-tag {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text-sub);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  transition: all 0.2s;
}
.quick-tag:active {
  transform: scale(0.95);
}
.quick-tag.selected {
  background: var(--accent);
  color: #000000;
  border-color: var(--accent);
  font-weight: bold;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
