:root {
  --bg: #f5f3ee;
  --surface: #fffefa;
  --ink: #1d1d1b;
  --muted: #74736d;
  --line: #dedbd2;
  --primary: #6d51e7;
  --primary-dark: #5840c7;
  --danger: #b63d3d;
  --sidebar: #171716;
  --radius: 18px;
  --shadow: 0 14px 40px rgba(30, 27, 18, 0.07);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
}
button, input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-family: "Unbounded", sans-serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}
h2 { margin-bottom: 6px; }
.muted { color: var(--muted); }
.eyebrow {
  margin-bottom: 10px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  width: 220px;
  flex-direction: column;
  padding: 28px 18px;
  background: var(--sidebar);
  color: #fff;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: "Unbounded", sans-serif;
  font-size: 1rem;
  font-weight: 700;
}
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--primary);
}
.sidebar nav { display: grid; gap: 7px; margin-top: 52px; }
.sidebar nav a, .nav-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #aaa9a4;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
}
.sidebar nav a:hover, .sidebar nav a.active, .nav-button:hover {
  background: #292927;
  color: #fff;
}
.nav-icon { width: 18px; text-align: center; }
.logout-form { margin-top: auto; }
.app-shell { min-height: 100vh; margin-left: 220px; padding: 52px clamp(24px, 4vw, 64px) 80px; }
.auth-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(109, 81, 231, 0.18), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(255, 115, 92, 0.15), transparent 32%),
    var(--bg);
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 34px;
}
.page-header.compact { align-items: center; }
.dashboard-header { align-items: center; }
.header-actions, .form-actions, .row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-ghost { border-color: var(--line); background: var(--surface); }
.button-ghost:hover { border-color: #b9b5aa; }
.button-danger { border-color: #ecc8c8; background: #fff2f2; color: var(--danger); }
.button-small { min-height: 36px; padding: 7px 12px; }
.button-wide { width: 100%; }
.text-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
}
.back-link {
  display: block;
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 600;
}

.attribute-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.level-card, .entity-card, .form-card, .calendar-card, .list-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.level-card { padding: 20px; border-radius: 14px; }
.level-card-top, .xp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.attribute-gem {
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border-radius: 2px;
  background: var(--accent);
}
.level-label, .xp-row { color: var(--muted); font-size: 0.78rem; }
.level-card h2 { margin: 22px 0 12px; font-size: 1rem; }
.progress-track {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 10px;
  background: #e9e6df;
}
.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent, var(--primary));
  transition: width 0.25s ease;
}

.calendar-card { overflow: hidden; border-radius: var(--radius); }
.calendar-grid {
  display: grid;
  min-width: 990px;
  grid-template-columns: 58px repeat(7, minmax(130px, 1fr));
  grid-template-rows: 82px repeat(4, minmax(180px, auto));
}
.timeline-corner {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f0eee8;
}
.day-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 15px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}
.decay-summary {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.7rem;
}
.decay-summary span { display: flex; justify-content: space-between; gap: 12px; }
.decay-summary b { color: var(--muted); font-weight: 500; }
.decay-summary strong { color: var(--danger); white-space: nowrap; }
.day-heading > div { display: flex; width: 100%; align-items: center; justify-content: space-between; }
.manual-add-button {
  width: 100%;
  padding: 4px 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: left;
}
.manual-add-button:hover { background: #f0ecff; }
.day-heading:nth-child(8) { border-right: 0; }
.day-heading strong {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  font-size: 0.9rem;
}
.day-heading.today strong { background: var(--primary); color: #fff; }
.time-marker {
  position: relative;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f0eee8;
  color: #8c8980;
  font-size: 0.65rem;
}
.time-marker span { position: absolute; top: 8px; right: 8px; }
.day-period {
  min-width: 0;
  overflow: visible;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.day-period:nth-child(8n) { border-right: 0; }
.period-night { background: #f3f2f6; }
.period-morning { background: #fffdf7; }
.period-afternoon { background: #faf8f1; }
.period-evening { background: #f7f3f0; }
.today-period { box-shadow: inset 0 0 0 1px rgba(109, 81, 231, 0.18); }
.quest-list { display: grid; align-content: start; gap: 9px; padding: 10px; }
.quest {
  position: relative;
  display: flex;
  min-width: 0;
  gap: 8px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: 0.2s ease;
}
.quest:hover { transform: translateY(-1px); border-color: #bdb8ad; }
.quest input { position: absolute; opacity: 0; }
.checkmark {
  display: grid;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #c9c5bb;
  border-radius: 6px;
  color: transparent;
  font-size: 0.7rem;
}
.quest.is-complete { background: #f3f1eb; opacity: 0.72; }
.quest.is-complete .checkmark { border-color: var(--primary); background: var(--primary); color: #fff; }
.quest.is-complete strong { text-decoration: line-through; }
.quest-content { display: grid; min-width: 0; gap: 4px; }
.quest-content strong { overflow: hidden; font-size: 0.82rem; text-overflow: ellipsis; }
.quest-time { color: var(--muted); font-size: 0.68rem; }
.quest-rewards, .reward-list { display: flex; flex-wrap: wrap; gap: 5px; }
.quest-rewards span, .reward-list span {
  color: var(--reward);
  font-size: 0.65rem;
  font-weight: 700;
}
.quest-rewards .negative-reward, .reward-list .negative-reward { color: var(--danger); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 18px; }
.entity-card { position: relative; overflow: hidden; padding: 24px; border-radius: var(--radius); }
.entity-accent { position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--accent); }
.entity-card-header { display: flex; align-items: flex-start; justify-content: space-between; }
.entity-card h2 { margin-top: 10px; }
.pill {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent, var(--primary)) 12%, white);
  color: var(--accent, var(--primary));
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}
.muted-pill { background: #e8e6df; color: var(--muted); }
.icon-link { color: var(--primary); font-size: 0.82rem; font-weight: 700; }
.card-description { min-height: 44px; margin: 12px 0 20px; font-size: 0.88rem; }
.entity-card .xp-row { margin-top: 7px; }
.trait-list { display: grid; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.trait { display: flex; justify-content: space-between; gap: 16px; font-size: 0.78rem; }
.trait span { color: var(--muted); text-align: right; }

.editor-form { max-width: 880px; }
.form-card { margin-bottom: 16px; padding: 28px; border-radius: var(--radius); }
.section-heading { display: flex; gap: 15px; margin-bottom: 24px; }
.section-heading h2 { font-size: 1.05rem; }
.section-heading p { margin: 0; color: var(--muted); font-size: 0.86rem; }
.section-number { color: var(--primary); font-family: "Unbounded", sans-serif; font-size: 0.72rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
label { color: #45443f; font-size: 0.82rem; font-weight: 700; }
input, textarea, select {
  width: 100%;
  margin-top: 7px;
  padding: 11px 12px;
  border: 1px solid #cbc7bc;
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109,81,231,0.1); }
input[type="color"] { height: 44px; padding: 5px; }
label small { display: block; margin-top: 5px; color: var(--muted); font-weight: 400; }
.characteristic-toggle { display: flex; align-items: flex-start; gap: 13px; }
.characteristic-toggle input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); }
.characteristic-toggle label { display: grid; gap: 5px; cursor: pointer; }
.characteristic-toggle strong { font-size: 1rem; }
.characteristic-toggle span { color: var(--muted); font-weight: 400; }
.toggle-fields { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.hidden { display: none !important; }
.metric-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 30px; gap: 8px; margin-bottom: 8px; }
.remove-row { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.4rem; }
.form-actions { margin-top: 24px; }
.action-spacer { flex: 1; }
.sync-card { border-color: #cfc7f6; background: #fbfaff; }
.sync-summary {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-top: 18px;
  border-top: 1px solid #ded8f7;
  color: var(--muted);
  font-size: 0.82rem;
}
.sync-summary strong { margin-left: 5px; color: var(--ink); }
.sync-summary .button { margin-left: auto; }

.segmented { display: inline-flex; margin-bottom: 22px; padding: 4px; border-radius: 10px; background: #ebe8e1; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 8px 16px; border-radius: 7px; }
.segmented input:checked + span { background: #fff; box-shadow: 0 2px 8px rgba(30,27,18,0.08); color: var(--primary); }
.creation-mode { margin-bottom: 18px; }
.schedule-fields > label { display: block; max-width: 350px; }
.weekday-picker { display: flex; gap: 7px; margin: 9px 0 20px; }
.weekday-picker label { cursor: pointer; }
.weekday-picker input { position: absolute; opacity: 0; }
.weekday-picker span { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 50%; }
.weekday-picker input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
.reward-editor { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.reward-row { display: grid; grid-template-columns: 14px 1fr 130px; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); }
.reward-row:last-child { border-bottom: 0; }
.attribute-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot); }
.reward-row > span:nth-child(2) { display: grid; gap: 2px; }
.reward-row small { margin: 0; }
.xp-input { position: relative; }
.xp-input input { margin: 0; padding-right: 36px; text-align: right; }
.xp-input b { position: absolute; top: 12px; right: 10px; color: var(--muted); font-size: 0.7rem; }

.list-card { overflow: hidden; border-radius: var(--radius); }
.activity-section { display: block; margin-bottom: 42px; }
.subsection-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
  list-style: none;
}
.subsection-heading::-webkit-details-marker { display: none; }
.subsection-heading .eyebrow { margin-bottom: 7px; }
.subsection-heading h2 { margin: 0; font-size: 1.25rem; }
.count-badge {
  display: grid;
  min-width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 20px;
  background: #e9e6df;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}
.one-time-section > summary { cursor: pointer; }
.one-time-section > summary::after {
  content: "+";
  color: var(--muted);
  font-size: 1.4rem;
}
.one-time-section[open] > summary::after { content: "−"; }
.one-time-section .count-badge { margin-left: auto; }
.compact-list .activity-row { padding-top: 15px; padding-bottom: 15px; }
.inline-empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.instance-pill { background: #e8e3ff; color: var(--primary); }
.activity-row { display: grid; grid-template-columns: 16px 1fr auto; gap: 15px; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.activity-row.inactive { opacity: 0.55; }
.activity-status span { display: block; width: 9px; height: 9px; border-radius: 50%; background: #50a777; }
.inactive .activity-status span { background: var(--muted); }
.activity-title { display: flex; align-items: center; gap: 10px; }
.activity-title h2 { margin: 0; font-size: 1rem; }
.activity-main > p { margin: 4px 0 8px; color: var(--muted); font-size: 0.8rem; }
.empty-state { max-width: 580px; margin: 70px auto; text-align: center; }
.empty-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 18px; place-items: center; border-radius: 16px; background: #e8e3ff; color: var(--primary); }
.empty-state p { color: var(--muted); }
.flash-stack { position: fixed; z-index: 50; top: 18px; right: 18px; display: grid; gap: 8px; }
.flash { padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); font-size: 0.85rem; }
.flash-success { border-color: #b9dfc9; }
.flash-error { border-color: #ecc0c0; color: var(--danger); }
.login-card { width: min(100%, 430px); padding: 38px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.brand-login { margin-bottom: 50px; }
.login-card h1 { font-size: 2rem; }
.stack-form { display: grid; gap: 18px; margin-top: 30px; }
.manual-adjustment-modal {
  width: min(92vw, 520px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(20, 18, 15, 0.25);
}
.manual-adjustment-modal::backdrop { background: rgba(23, 23, 22, 0.55); }
.manual-adjustment-modal form { padding: 26px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.modal-heading h2 { margin: 0; }
.modal-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.6rem; }
.manual-adjustment-fields { display: grid; gap: 10px; margin-top: 22px; }
.manual-adjustment-fields label { display: grid; grid-template-columns: 14px 1fr 120px; align-items: center; gap: 10px; }
.manual-adjustment-fields input { margin: 0; text-align: right; }
.insight-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.insight-summary article, .insight-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.insight-summary article { display: grid; gap: 5px; padding: 20px; border-radius: 14px; }
.insight-summary span, .insight-summary small { color: var(--muted); font-size: 0.72rem; }
.insight-summary strong { font-family: "Unbounded", sans-serif; font-size: 1.45rem; }
.positive-value { color: #32835a !important; }
.negative-value { color: var(--danger) !important; }
.insight-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, 0.8fr); gap: 18px; }
.insight-panel { min-width: 0; padding: 24px; border-radius: var(--radius); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-heading .eyebrow { margin-bottom: 6px; }
.panel-heading h2 { margin: 0; font-size: 1.05rem; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 14px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.7rem; }
.chart-legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--legend-color); }
.growth-chart-wrap { position: relative; height: 390px; }
.growth-chart-wrap canvas { width: 100%; height: 100%; }
.event-list { display: grid; }
.event-row { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.event-row:last-child { border-bottom: 0; }
.event-row div { display: grid; gap: 3px; min-width: 0; }
.event-row strong { overflow: hidden; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.event-row small { color: var(--muted); font-size: 0.66rem; }
.event-row b { font-size: 0.76rem; }
.event-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.event-decay { background: var(--danger); }
.event-manual { background: #d08b2c; }

@media (max-width: 1100px) {
  .calendar-card { overflow-x: auto; }
  .insight-summary { grid-template-columns: 1fr 1fr; }
  .insight-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar {
    inset: auto 0 0;
    width: auto;
    height: 66px;
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
  }
  .sidebar .brand, .logout-form { display: none; }
  .sidebar nav { display: flex; width: 100%; justify-content: space-around; margin: 0; }
  .sidebar nav a { width: auto; flex-direction: column; gap: 3px; padding: 7px 12px; font-size: 0.65rem; }
  .nav-icon { font-size: 1rem; }
  .app-shell { margin-left: 0; padding: 30px 16px 100px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; overflow-x: auto; }
  .dashboard-header .header-actions .button-primary { margin-left: auto; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .metric-row { grid-template-columns: 1fr 1fr; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .activity-row { grid-template-columns: 12px 1fr; }
  .row-actions { grid-column: 2; justify-content: flex-end; }
  .form-card { padding: 20px; }
  .sync-summary { align-items: stretch; flex-direction: column; gap: 10px; }
  .sync-summary .button { margin: 8px 0 0; }
  .form-actions { position: sticky; bottom: 76px; z-index: 5; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,254,250,0.95); }
  .insight-summary { grid-template-columns: 1fr 1fr; }
  .insight-summary article { padding: 15px; }
  .panel-heading { flex-direction: column; }
  .chart-legend { justify-content: flex-start; }
  .growth-chart-wrap { height: 300px; }
}
