/* =========================================
   1. Base & Reset (基礎設定)
   ========================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden; /* 防止整個頁面捲動 */
  font-family: "Noto Sans TC", sans-serif;
  background: #0f1218;
  color: #fff;
}

/* =========================================
   2. Layout Structure (佈局結構)
   ========================================= */
.container {
  height: 100%;
  width: 100%;
}

.main-app {
  display: none;
  height: 100%;
  width: 100%;
}

.main-app.show {
  display: block;
}

.app-container {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* =========================================
   3. Sidebar (左側導覽列)
   ========================================= */
.sidebar {
  width: 260px;
  background: #1a1a2e;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  flex-shrink: 0;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  height: 70px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  /* 關鍵修改：因為標題移除了，所以將關閉按鈕推到右側 */
  justify-content: flex-end;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.nav-menu {
  flex: 1;
  padding: 20px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  margin-bottom: 5px;
  border-radius: 8px;
  cursor: pointer;
  color: #8899ac;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}

.nav-item:hover:not(.disabled) {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.nav-item.active {
  background: linear-gradient(
    90deg,
    rgba(0, 210, 255, 0.1),
    rgba(58, 123, 213, 0.05)
  );
  color: #00d2ff;
  border-left-color: #00d2ff;
}

.nav-icon {
  margin-right: 12px;
  font-size: 1.2rem;
  min-width: 24px;
  text-align: center;
}

.nav-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(100%);
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: #151525;
  flex-shrink: 0;
}

.user-info-box {
  margin-bottom: 15px;
}

.user-email-display {
  font-size: 0.85rem;
  color: #ccc;
  word-break: break-all;
  margin-bottom: 8px;
}

/* =========================================
   4. Content Area (右側內容區)
   ========================================= */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #13151a 0%, #16213e 100%);
  position: relative;
  overflow: hidden;
  height: 100%;
  min-width: 0;
}

/* --- App Header (原 Mobile Header，現在全平台顯示) --- */
.app-header {
  height: 60px;
  background: #1a1a2e;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  z-index: 900;

  display: flex;
  align-items: center;
  justify-content: center; /* 標題置中 */
  position: relative;
  padding: 0 10px;
}

.btn-toggle-sidebar {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
}

.btn-toggle-sidebar svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
  stroke-width: 2px;
}

.app-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  text-align: center;
  z-index: 900;
}

/* 電腦版時隱藏選單切換按鈕，只顯示標題 */
@media (min-width: 769px) {
  .btn-toggle-sidebar {
    display: none;
  }
}

.btn-close-sidebar {
  display: none;
  background: transparent;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 5px;
}

/* --- Page Content --- */
.page-content {
  flex: 1;
  padding: 30px;
  padding-bottom: 150px;
  overflow-y: auto;
  scroll-behavior: smooth;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* 卡片區塊 */
.section.page-section {
  display: none;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 30px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  width: 100%;
  animation: fadeIn 0.4s ease;
}

.section.page-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #00d2ff;
  line-height: 1.4;
}

/* =========================================
   5. Form Elements
   ========================================= */
.input-group {
  margin-bottom: 25px;
  width: 100%;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #ccc;
  font-weight: 500;
  font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
textarea {
  width: 100%;
  padding: 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  transition: border-color 0.3s;
  font-family: inherit;
  max-width: 100%;
  resize: vertical;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #00d2ff;
  background: rgba(0, 0, 0, 0.35);
}

.file-upload {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  width: 100%;
}

.file-upload:hover {
  border-color: #00d2ff;
  background: rgba(0, 210, 255, 0.05);
}

.file-upload-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
  opacity: 0.8;
}

.file-upload input {
  display: none;
}

/* =========================================
   6. Buttons
   ========================================= */
.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 15px;
  width: 100%;
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(90deg, #00d2ff, #3a7bd5);
  color: #fff;
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-danger {
  background: rgba(255, 71, 87, 0.1);
  color: #ff4757;
  border: 1px solid rgba(255, 71, 87, 0.3);
}
.btn-copy {
  background: linear-gradient(90deg, #11998e, #38ef7d);
  color: #fff;
}

.next-step-hint {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: flex-end;
}
.btn-next {
  background: transparent;
  color: #00d2ff;
  border: 1px solid #00d2ff;
  padding: 10px 20px;
}

.btn-admin-mini {
  width: 100%;
  padding: 6px;
  font-size: 0.8rem;
  background: rgba(240, 147, 251, 0.1);
  border: 1px solid rgba(240, 147, 251, 0.3);
  color: #f093fb;
  border-radius: 4px;
  margin-top: 8px;
}
.btn-test-mode {
  width: 100%;
  padding: 6px;
  font-size: 0.8rem;
  background: rgba(255, 193, 7, 0.08);
  border: 1px solid rgba(255, 193, 7, 0.25);
  color: #999;
  border-radius: 4px;
  margin-top: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-test-mode:hover {
  background: rgba(255, 193, 7, 0.15);
  border-color: rgba(255, 193, 7, 0.5);
  color: #ffc107;
}
.btn-test-mode.active {
  background: rgba(255, 193, 7, 0.2);
  border-color: #ffc107;
  color: #ffc107;
  font-weight: bold;
}
.test-mode-badge {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
  background: #ffc107;
  color: #000;
  margin-left: 10px;
  vertical-align: middle;
}
.btn-logout-sidebar {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #bbb;
  margin-top: 10px;
}

/* =========================================
   7. Specific Components
   ========================================= */
.reference-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-items: flex-start;
  padding: 15px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.reference-item .input-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 200px;
}
.btn-add-ref {
  width: 100%;
  background: rgba(0, 210, 255, 0.05);
  border: 1px dashed rgba(0, 210, 255, 0.3);
  color: #00d2ff;
}

.loading {
  display: none;
  text-align: center;
  padding: 40px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  margin: 20px 0;
}
.loading.show {
  display: block;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: #00d2ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 15px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.title-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.title-option {
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.title-option.selected {
  border-color: #00d2ff;
  background: rgba(0, 210, 255, 0.15);
}
.char-count {
  font-size: 0.85rem;
  color: #888;
  margin-top: 5px;
  text-align: right;
}

/* =========================================
   New Color Palette Styles
   ========================================= */
.color-palette-container {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.palette-label {
  color: #aaa;
  font-size: 0.9rem;
  white-space: nowrap;
}

.palette-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

input[type="color"].custom-picker,
input[type="color"].palette-item {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

input[type="color"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

input[type="color"].active {
  transform: scale(1.1);
  box-shadow:
    0 0 0 2px #fff,
    0 0 10px rgba(0, 210, 255, 0.5);
  z-index: 1;
}

/* Canvas & Design */
.canvas-container {
  margin: 20px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  background: #000;
  width: 100%;
}
canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
  max-width: 100%;
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  min-height: 60px;
  align-items: center;
}
.word-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 15px;
  cursor: pointer;
}
.toggle {
  width: 50px;
  height: 26px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 13px;
  position: relative;
  transition: all 0.3s;
}
.toggle.active {
  background: #00d2ff;
}
.toggle-knob {
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: all 0.3s;
}
.toggle.active .toggle-knob {
  left: 27px;
}

.logo-preview {
  max-width: 120px;
  max-height: 120px;
  margin-top: 15px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* =========================================
   8. Utilities
   ========================================= */
.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 16px 24px;
  background: #2ed573;
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translateX(200%);
  transition: transform 0.4s;
  z-index: 9999;
  font-weight: 500;
  max-width: 90%;
}
.toast.show {
  transform: translateX(0);
}
.toast.error {
  background: #ff4757;
}

/* Login */
.login-page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  text-align: center;
}
.btn-google {
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  padding: 12px 30px;
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 1rem;
  margin-top: 30px;
  border-radius: 8px;
  width: 100%;
  max-width: 300px;
  justify-content: center;
}
.btn-google svg {
  width: 24px;
  height: 24px;
}

/* Admin */
.admin-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #13151a;
  z-index: 3000;
  overflow-y: auto;
  padding: 20px;
  display: none;
}
.admin-panel.show {
  display: block;
}
.admin-header {
  max-width: 1000px;
  margin: 0 auto 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* =========================================
   9. Responsive Design (Mobile)
   ========================================= */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: -260px;
    top: 0;
    bottom: 0;
    height: 100%;
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open {
    transform: translateX(260px);
  }

  .btn-close-sidebar {
    display: block;
  }

  .page-content {
    padding: 20px;
    padding-bottom: 120px; /* 避開底部 */
  }

  .section.page-section {
    padding: 20px;
    margin-bottom: 15px;
  }

  .btn-group {
    flex-direction: column;
    width: 100%;
  }
  button {
    width: 100%;
  }

  .next-step-hint {
    margin-top: 30px;
    text-align: center;
  }

  .toast {
    bottom: 20px;
    right: 5%;
    left: 5%;
    width: 90%;
    transform: translateY(150%);
    justify-content: center;
  }
  .toast.show {
    transform: translateY(0);
  }
}

/* 電腦版 Canvas 編輯區縮小 */
@media (min-width: 769px) {
  #section-design .canvas-container {
    max-width: 60%;
    margin: 20px auto;
  }
  #section-export .canvas-container {
    max-width: 60%;
    margin: 20px auto;
  }
}
