:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --bg-2: #fffaf2;
  --panel: #ffffff;
  --panel-2: #fbf7ef;
  --line: #e5dccd;
  --line-strong: #cdbca3;
  --text: #22201d;
  --muted: #6e665c;
  --soft: #9c9183;
  --gold: #c9933d;
  --gold-2: #a66d1f;
  --teal: #3f8f8a;
  --red: #bd6d5d;
  --green: #5d9258;
  --blue: #597fa8;
  --shadow: 0 20px 52px rgba(76, 62, 43, 0.12);
  font-family:
    Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(201, 147, 61, 0.11), transparent 38%),
    linear-gradient(160deg, rgba(63, 143, 138, 0.1), transparent 44%),
    var(--bg);
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-view {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 28px;
}

.auth-copy {
  margin-bottom: 22px;
}

.auth-copy h2 {
  margin: 0 0 10px;
  font-size: 2rem;
  line-height: 1.05;
}

.auth-copy p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.auth-error {
  min-height: 20px;
  margin: 0;
  color: #a33c2f;
  font-weight: 700;
}

.auth-switch {
  width: 100%;
  margin-top: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(201, 147, 61, 0.12), transparent 26%),
    repeating-linear-gradient(
      0deg,
      rgba(166, 109, 31, 0.04) 0,
      rgba(166, 109, 31, 0.04) 1px,
      transparent 1px,
      transparent 7px
    ),
    #fffaf2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(215, 166, 75, 0.55);
  border-radius: 8px;
  color: #24180c;
  background:
    linear-gradient(135deg, #f4d289, #b97832 54%, #8f422f),
    var(--gold);
  font-weight: 900;
}

.brand p,
.overline {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.brand h1,
.topbar h2,
.section-heading h3,
.goal-form h3 {
  margin: 0;
  line-height: 1.05;
}

.brand h1 {
  font-size: 1.34rem;
}

.profile-block {
  position: relative;
  min-height: 280px;
  margin-bottom: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
}

#trailCanvas {
  display: block;
  width: 100%;
  height: 206px;
}

.reward-panel {
  padding: 15px;
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.92);
}

.reward-panel > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.reward-panel strong {
  color: var(--gold-2);
  font-size: 1.35rem;
}

.reward-meter {
  height: 9px;
  margin-top: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #efe3d1;
}

.reward-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--teal));
  transition: width 220ms ease;
}

.reward-panel p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.side-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.side-section.compact {
  display: grid;
  gap: 10px;
}

.storage-status {
  min-height: 34px;
  padding: 9px 11px;
  border: 1px solid rgba(166, 109, 31, 0.22);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.82rem;
  line-height: 1.25;
}

.storage-status.file {
  color: #2e6c37;
  border-color: rgba(111, 158, 103, 0.46);
  background: rgba(111, 158, 103, 0.12);
}

.category-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.category-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.category-pill:hover,
.category-pill.active {
  border-color: var(--line-strong);
  background: rgba(201, 147, 61, 0.1);
}

.category-pill span:last-child {
  color: var(--gold-2);
}

.workspace {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
}

.topbar h2 {
  font-size: 2.1rem;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button,
.mini-button {
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 17px;
  color: #ffffff;
  background: linear-gradient(180deg, #bf8634, #99621c);
  border-color: #ad7429;
  font-weight: 800;
}

.primary-button:hover {
  filter: brightness(1.06);
}

.ghost-button {
  min-height: 38px;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.ghost-button.danger {
  color: #a33c2f;
  border-color: rgba(183, 85, 69, 0.42);
}

.text-button {
  min-height: 34px;
  padding: 0 11px;
  color: var(--gold-2);
  background: transparent;
}

.text-button.active,
.text-button:hover {
  background: rgba(201, 147, 61, 0.12);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
  font-size: 1.35rem;
  line-height: 1;
}

.mini-button {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
}

.mini-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

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

.user-chip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.88rem;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-tile {
  min-height: 138px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(201, 147, 61, 0.11), transparent),
    var(--panel);
}

.stat-tile.teal {
  background:
    linear-gradient(180deg, rgba(63, 143, 138, 0.13), transparent),
    var(--panel);
}

.stat-tile.red {
  background:
    linear-gradient(180deg, rgba(189, 109, 93, 0.13), transparent),
    var(--panel);
}

.stat-tile.gold {
  background:
    linear-gradient(180deg, rgba(240, 199, 110, 0.2), transparent),
    var(--panel);
}

.stat-tile span,
.stat-tile small {
  color: var(--muted);
}

.stat-tile strong {
  display: block;
  margin: 16px 0 8px;
  font-size: 2.15rem;
  line-height: 1;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto 180px;
  gap: 12px;
  align-items: center;
  margin-bottom: 25px;
}

.search-box,
.select-field,
.goal-form label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.search-box input::placeholder {
  color: var(--soft);
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.segmented button {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: #ffffff;
  background: var(--gold-2);
  font-weight: 800;
}

.select-field {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

select,
input,
textarea {
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

select {
  min-width: 0;
  border: 0;
  background: transparent;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 24px;
  align-items: start;
  margin-bottom: 28px;
}

.board-section,
.library-section {
  min-width: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.section-heading h3 {
  font-size: 1.25rem;
}

.result-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.active-list,
.timeline {
  display: grid;
  gap: 11px;
}

.quest-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  color: #24170c;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.badge::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 1px solid rgba(36, 23, 12, 0.34);
  transform: rotate(45deg);
}

.badge.bronze {
  background: linear-gradient(135deg, #b7764a, #7f4b32);
}

.badge.silver {
  background: linear-gradient(135deg, #d8ded8, #899397);
}

.badge.gold {
  background: linear-gradient(135deg, #f4d681, #bb7e2f);
}

.badge.platinum {
  background: linear-gradient(135deg, #a9efe1, #7f8fd6 58%, #e1d2ff);
}

.badge.locked {
  color: #928579;
  background: linear-gradient(135deg, #f0e9de, #d7cbbb);
}

.quest-main {
  min-width: 0;
}

.quest-title-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.quest-title-line strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.76rem;
  font-weight: 800;
}

.tag.done {
  color: #2e6c37;
  border-color: rgba(111, 158, 103, 0.45);
  background: rgba(111, 158, 103, 0.14);
}

.tag.pin {
  color: var(--gold-2);
  border-color: rgba(215, 166, 75, 0.45);
}

.quest-row p,
.achievement-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.progress-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #efe4d2;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--teal));
  transition: width 220ms ease;
}

.progress-line small {
  color: var(--muted);
  white-space: nowrap;
}

.quest-actions,
.card-actions {
  display: flex;
  gap: 7px;
  align-items: center;
}

.timeline-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.timeline-item::before {
  content: "";
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--gold-2);
  box-shadow: 0 0 0 5px rgba(215, 166, 75, 0.12);
}

.timeline-item strong {
  display: block;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.timeline-item span,
.empty-state {
  color: var(--muted);
}

.timeline-content {
  display: grid;
  gap: 8px;
}

.timeline-reward {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.achievement-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.achievement-card {
  display: grid;
  gap: 13px;
  min-height: 244px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(201, 147, 61, 0.06), transparent 48%),
    var(--panel);
}

.achievement-card.completed {
  border-color: rgba(215, 166, 75, 0.5);
  background:
    linear-gradient(180deg, rgba(201, 147, 61, 0.12), transparent 46%),
    var(--panel);
}

.achievement-card.locked {
  opacity: 0.76;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card-title {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.card-title strong {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: auto;
}

.reward-state {
  color: var(--gold-2);
  font-weight: 900;
  text-align: right;
}

.reward-note {
  color: var(--gold-2);
}

.reward-button {
  min-height: 32px;
  padding: 0 10px;
  color: #ffffff;
  background: var(--gold-2);
  border-color: rgba(240, 199, 110, 0.84);
  font-weight: 900;
}

.reward-button.claimed {
  color: #2e6c37;
  background: rgba(111, 158, 103, 0.14);
  border-color: rgba(111, 158, 103, 0.45);
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  text-align: center;
}

.goal-dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.goal-dialog::backdrop {
  background: rgba(50, 42, 32, 0.34);
}

.goal-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.goal-form label {
  display: grid;
  gap: 8px;
}

.goal-form input,
.goal-form textarea,
.goal-form select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.goal-form textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.check-field {
  align-content: end;
  grid-template-columns: 20px 1fr;
  gap: 9px;
  min-height: 68px;
}

.check-field input {
  width: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--gold);
}

.dialog-actions > div {
  display: flex;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 15px;
  border: 1px solid rgba(215, 166, 75, 0.5);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

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

  .split-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    order: 2;
    position: relative;
    height: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    order: 1;
    padding: 22px 16px 28px;
  }

  .topbar,
  .dialog-head,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .control-strip {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .quest-row {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .quest-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

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

  .form-grid,
  .achievement-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding: 22px 16px;
  }

  .topbar h2 {
    font-size: 1.7rem;
  }

  .stat-tile {
    min-height: 118px;
  }

  .achievement-card {
    min-height: 228px;
  }

  .card-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .card-actions {
    justify-content: flex-end;
  }
}
