:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #121826;
  --muted: #6b7280;
  --primary: #5b6cff;
  --primary-dark: #4855e6;
  --accent: #00c2a8;
  --danger: #ff5c6d;
  --border: #e6e8ef;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  --input-bg: #f8fafc;
  --tab-bg: #eef1ff;
  --tab-hover: #e1e6ff;
  --ghost-bg: #f1f5f9;
  --ghost-color: #334155;
  --ghost-hover: #e2e8f0;
}

/* 다크 테마 */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1219;
  --card: #1a1f2e;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6b7cff;
  --primary-dark: #5b6cff;
  --accent: #00d4b8;
  --danger: #ff6b7a;
  --border: #2d3548;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  --input-bg: #232938;
  --tab-bg: #232938;
  --tab-hover: #2d3548;
  --ghost-bg: #232938;
  --ghost-color: #cbd5e1;
  --ghost-hover: #2d3548;
}

* {
  box-sizing: border-box;
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  gap: 24px;
  align-items: center;
  padding: 18px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo {
  font-weight: 700;
  font-size: 20px;
}

.tag {
  color: var(--muted);
  font-size: 13px;
}

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

.tab {
  border: 1px solid transparent;
  background: var(--tab-bg);
  color: var(--ghost-color);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: 0.2s ease;
}

.tab:hover {
  background: var(--tab-hover);
}

.tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 8px 16px rgba(91, 108, 255, 0.3);
}

.profile-area {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.profile-area .name {
  font-weight: 600;
  color: var(--text);
}

.auth-btn {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: 0.2s ease;
}

.login-btn {
  background: var(--primary);
  color: white;
}

.login-btn:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.logout-btn {
  background: var(--ghost-bg);
  color: var(--muted);
}

.logout-btn:hover {
  background: var(--ghost-hover);
  text-decoration: none;
}

.profile {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  border: none;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.profile-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.profile-text .name {
  font-weight: 600;
}

.profile-text .status {
  color: var(--muted);
  font-size: 12px;
}

.content {
  padding: 32px;
  flex: 1;
}

.page {
  display: none;
  flex-direction: column;
  gap: 24px;
}

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

.page.active {
  display: flex;
  animation: fadeInUp 0.4s ease-out forwards;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
}

.date,
.tier {
  color: var(--muted);
  font-weight: 500;
}

.actions {
  display: flex;
  gap: 10px;
}

.grid {
  display: grid;
  gap: 20px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card.hero {
  background: linear-gradient(135deg, #5b6cff 0%, #7c54ff 50%, #8c6cff 100%);
  color: white;
}

.hero .muted {
  color: rgba(255, 255, 255, 0.7);
}

.hero-metrics {
  display: flex;
  gap: 20px;
}

.metric {
  font-size: 36px;
  font-weight: 700;
}

.metric-label {
  font-size: 13px;
  opacity: 0.8;
  margin-left: 6px;
}

.primary,
.ghost,
.danger {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary {
  background: var(--primary);
  color: white;
}

.primary:hover {
  background: var(--primary-dark);
}

.ghost {
  background: var(--ghost-bg);
  color: var(--ghost-color);
}

.ghost:hover {
  background: var(--ghost-hover);
}

.danger {
  background: rgba(255, 92, 109, 0.1);
  color: var(--danger);
}

.danger:hover {
  background: rgba(255, 92, 109, 0.2);
}

.primary:hover, .ghost:hover, .danger:hover {
  transform: translateY(-2px);
}

.pill-list,
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  border: 1px solid var(--border);
  background: var(--ghost-bg);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.pill.small {
  background: var(--tab-bg);
  border-color: var(--border);
}

.card-note {
  color: var(--muted);
  font-size: 13px;
}

.quest {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quest-title {
  font-weight: 600;
}

.quest-progress {
  color: var(--muted);
  font-size: 13px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.routine-list,
.quest-list,
.exercise-list,
.requirement-list,
.detail-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quest-list {
  list-style: none;
  padding: 0;
}

.quest-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.quest-list li:last-child {
  border-bottom: none;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.chip {
  background: var(--tab-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
}

.stat-list {
  display: grid;
  gap: 12px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--input-bg);
  border-radius: 12px;
  padding: 12px 14px;
}

.stat strong {
  font-size: 16px;
}

.chart-placeholder {
  height: 180px;
  border-radius: 14px;
  background: repeating-linear-gradient(
    135deg,
    var(--ghost-bg),
    var(--ghost-bg) 10px,
    var(--ghost-hover) 10px,
    var(--ghost-hover) 20px
  );
  display: grid;
  place-items: center;
  color: var(--muted);
}

.badge {
  background: #0f172a;
  color: white;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}

.streak-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16px, 1fr));
  gap: 6px;
}

.streak {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--border);
}

.streak.on {
  background: #10b981;
}

.exercise-list {
  list-style: none;
  padding: 0;
}

.exercise-list li {
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
}

.exercise-list li.selected {
  background: var(--tab-bg);
  border-color: var(--primary);
}

.requirement-list {
  list-style: none;
  padding: 0;
}

.requirement-list li {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--input-bg);
  border: 1px dashed var(--border);
}

.requirement-list li.done {
  border-color: #22c55e;
  color: #16a34a;
}

.status-badges {
  display: flex;
  gap: 8px;
}

.status {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status.running {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}

.status.paused {
  background: rgba(248, 113, 113, 0.15);
  color: #ef4444;
}

.status.rest {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
}

.camera {
  gap: 12px;
}

.camera-frame {
  height: 320px;
  border-radius: 16px;
  border: 1px dashed #cbd5f5;
  background: #eef2ff;
  display: grid;
  place-items: center;
}

.camera-overlay {
  color: #64748b;
  font-weight: 500;
}

.camera-actions {
  display: flex;
  gap: 10px;
}

.progress-card {
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px;
}

.alert {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 12px;
  padding: 12px;
  color: #be123c;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-row {
  display: flex;
  gap: 10px;
}

.score {
  font-size: 46px;
  font-weight: 700;
}

.summary-lines p {
  margin: 0;
}

.detail-list {
  list-style: none;
  padding: 0;
}

.detail-list li {
  display: flex;
  justify-content: space-between;
  background: var(--input-bg);
  border-radius: 12px;
  padding: 10px 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  width: min(520px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
}

.modal-body {
  display: grid;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.full {
  width: 100%;
}

.auth-shell {
  min-height: calc(100vh - 160px);
  display: grid;
  place-items: center;
  padding: 12px 16px 28px;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-header .logo {
  font-size: 22px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inline-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-input-row input {
  flex: 1;
}

.check-button {
  white-space: nowrap;
  padding-inline: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-weight: 600;
  font-size: 14px;
}

.input-group input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 108, 255, 0.16);
}

.field-message {
  min-height: 18px;
  font-size: 12px;
  margin-top: 2px;
}

.field-message .error {
  color: var(--danger);
}

.field-message .success {
  color: #16a34a;
}

.form-error {
  background: rgba(255, 92, 109, 0.1);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

.helper-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.link-button {
  width: 100%;
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--ghost-color);
  text-align: center;
  transition: 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.link-button:hover {
  background: var(--ghost-hover);
  text-decoration: none;
}

@media (max-width: 1200px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .profile {
    justify-content: flex-start;
  }

  .grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }

  .brand .tag {
    display: none;
  }

  .profile-area {
    gap: 8px;
  }

  .profile-area .auth-btn {
    padding: 7px 12px;
    font-size: 12px;
  }

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    padding: 10px max(12px, env(safe-area-inset-left))
      calc(10px + env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.92);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .tab {
    min-height: 42px;
    border-radius: 12px;
    padding: 8px 6px;
    font-size: 12px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.25;
  }

  .tab.active {
    box-shadow: none;
  }

  .content {
    padding: 20px 16px calc(98px + env(safe-area-inset-bottom));
  }

  [data-theme="dark"] .tabs {
    background: rgba(26, 31, 46, 0.95);
  }
}

/* ========== 다크 테마 추가 스타일 ========== */
[data-theme="dark"] .chip {
  background: var(--tab-bg);
  border-color: var(--border);
}

[data-theme="dark"] .form-group input {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

[data-theme="dark"] .modal-content {
  background: var(--card);
}

[data-theme="dark"] .form-success {
  background: rgba(0, 212, 184, 0.15);
  color: var(--accent);
}

/* ========== 설정 페이지 스타일 ========== */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-text {
  font-weight: 500;
  color: var(--text);
}

.label-value {
  color: var(--muted);
  font-size: 14px;
}

.label-value.link {
  color: var(--primary);
}

/* 테마 선택 옵션 */
.theme-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.theme-option input[type="radio"] {
  display: none;
}

.theme-preview {
  width: 100%;
  aspect-ratio: 16/10;
  border-radius: 12px;
  border: 2px solid var(--border);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.theme-option input[type="radio"]:checked + .theme-preview {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 108, 255, 0.2);
}

.light-preview {
  background: #f6f7fb;
}

.light-preview .preview-header {
  height: 20%;
  background: #ffffff;
  border-bottom: 1px solid #e6e8ef;
}

.light-preview .preview-content {
  padding: 8px;
  display: flex;
  gap: 6px;
}

.light-preview .preview-card {
  flex: 1;
  height: 24px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #e6e8ef;
}

.dark-preview {
  background: #0f1219;
}

.dark-preview .preview-header {
  height: 20%;
  background: #1a1f2e;
  border-bottom: 1px solid #2d3548;
}

.dark-preview .preview-content {
  padding: 8px;
  display: flex;
  gap: 6px;
}

.dark-preview .preview-card {
  flex: 1;
  height: 24px;
  background: #1a1f2e;
  border-radius: 6px;
  border: 1px solid #2d3548;
}

.system-preview {
  display: flex;
  overflow: hidden;
}

.preview-split {
  display: flex;
  width: 100%;
  height: 100%;
}

.split-light {
  flex: 1;
  background: #f6f7fb;
}

.split-light .preview-header {
  height: 100%;
  background: #ffffff;
  border-right: 1px solid #e6e8ef;
}

.split-dark {
  flex: 1;
  background: #0f1219;
}

.split-dark .preview-header {
  height: 100%;
  background: #1a1f2e;
}

.theme-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.theme-option input[type="radio"]:checked ~ .theme-name {
  color: var(--primary);
}

/* 성공 메시지 스타일 */
.form-success {
  background: rgba(0, 194, 168, 0.1);
  color: #00a88e;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

.field-message .success {
  color: #16a34a;
}

[data-theme="dark"] .field-message .success {
  color: #4ade80;
}

/* ========== 다크 테마: 히스토리 & 퀘스트 페이지 ========== */

/* 공통 요소 */
[data-theme="dark"] .stat {
  background: var(--card);
}

[data-theme="dark"] .empty-state {
  background: var(--card);
}

[data-theme="dark"] .chip {
  background: var(--card);
  border-color: var(--border);
}

/* 히스토리 페이지 */
[data-theme="dark"] .filter-group select {
  background: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}

[data-theme="dark"] .filter-group select option {
  background: var(--card);
  color: var(--text);
}

[data-theme="dark"] .history-actions .ghost:hover {
  background: var(--ghost-hover);
}

[data-theme="dark"] .detail-item {
  background: var(--input-bg);
}

[data-theme="dark"] .metric-item {
  background: var(--input-bg);
}

[data-theme="dark"] .score-circle {
  background: var(--input-bg);
}

[data-theme="dark"] .detail-list li {
  background: var(--input-bg);
}

/* 퀘스트 페이지 */
[data-theme="dark"] .quest-card.completed {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, rgba(22, 163, 74, 0.15) 100%);
  border-color: rgba(134, 239, 172, 0.4);
}

[data-theme="dark"] .quest-type.do {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

[data-theme="dark"] .quest-type.quality {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

[data-theme="dark"] .quest-type.habit {
  background: rgba(139, 92, 246, 0.2);
  color: #a78bfa;
}

[data-theme="dark"] .point-record {
  background: var(--input-bg);
}

[data-theme="dark"] .tier-item {
  background: var(--input-bg);
}

[data-theme="dark"] .tier-item.current {
  background: linear-gradient(135deg, rgba(91, 108, 255, 0.15) 0%, rgba(91, 108, 255, 0.25) 100%);
}

[data-theme="dark"] .quick-action-btn {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

[data-theme="dark"] .quick-action-btn:hover {
  background: var(--ghost-hover);
}

[data-theme="dark"] .history-mode.free {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

[data-theme="dark"] .history-mode.routine {
  background: rgba(139, 92, 246, 0.2);
  color: #a78bfa;
}

@media (max-width: 600px) {
  .theme-options {
    grid-template-columns: 1fr;
  }
}
