:root {
  --ink: #17211f;
  --muted: #65716d;
  --paper: #f7f4ec;
  --surface: #ffffff;
  --line: #ddd7c8;
  --moss: #2e6f5a;
  --gold: #d79b36;
  --coral: #d85b4a;
  --night: #25304a;
  --blue: #4272b8;
  --shadow: 0 18px 50px rgba(37, 48, 74, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: "Inter", "Noto Sans KR", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  color: #f8f2e6;
  background: var(--night);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: var(--gold);
  color: #1f263a;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.library-rank p,
.library-rank small {
  color: rgba(248, 242, 230, 0.72);
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  width: 100%;
  padding: 13px 12px;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(248, 242, 230, 0.76);
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.library-rank {
  margin-top: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
}

.library-rank p,
.library-rank h2 {
  margin: 0 0 8px;
}

.xp-track {
  height: 9px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.16);
}

.xp-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gold);
  transition: width 0.35s ease;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--moss);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
}

h2 {
  margin-bottom: 14px;
  font-size: 1.15rem;
}

.primary-action {
  border: 0;
  padding: 12px 16px;
  background: var(--moss);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(46, 111, 90, 0.22);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.alert-banner {
  display: none;
  margin-bottom: 16px;
  padding: 16px 18px;
  border-left: 5px solid var(--coral);
  background: #fff0eb;
  color: #823023;
  font-weight: 800;
}

.alert-banner.active {
  display: block;
}

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

.metric-card,
.panel,
.wanted-hero {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin: 10px 0 2px;
  font-size: 2.2rem;
  line-height: 1;
}

.metric-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.metric-card.danger strong {
  color: var(--coral);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.panel-head span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.bar-chart {
  min-height: 220px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  align-items: end;
  padding-top: 20px;
}

.bar {
  min-height: 46px;
  background: linear-gradient(180deg, var(--blue), var(--moss));
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 8px 4px;
}

.bar small {
  color: rgba(255, 255, 255, 0.78);
}

.ranking-list,
.return-list,
.wanted-list,
.book-table,
.popular-books,
#questList {
  display: grid;
  gap: 10px;
}

.rank-row,
.book-row,
.return-row,
.wanted-card,
.quest-card,
.popular-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fcfaf5;
}

.rank-row {
  grid-template-columns: 38px 1fr auto;
  align-items: center;
}

.rank-no {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #1d2435;
  font-weight: 900;
}

.tier {
  color: var(--moss);
  font-size: 0.82rem;
  font-weight: 800;
}

.split-layout,
.guild-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.stacked-forms {
  display: grid;
  gap: 18px;
  align-self: start;
}

.form-panel {
  align-self: start;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

.inline-controls {
  display: flex;
  min-width: min(520px, 100%);
  gap: 10px;
}

.book-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  padding: 7px 9px;
  background: #e8f3ee;
  color: var(--moss);
  font-weight: 900;
}

.status-pill.borrowed {
  background: #fce7de;
  color: #9a3d2e;
}

.small-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font-weight: 800;
}

.calendar-panel {
  margin-top: 18px;
}

.lower-guild-grid {
  margin-top: 18px;
}

.management-list {
  display: grid;
  gap: 10px;
}

.template-note {
  margin: -2px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fcfaf5;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.bulk-preview {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.bulk-preview-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fcfaf5;
}

.bulk-preview-row.invalid {
  border-color: #efb5a8;
  background: #fff0eb;
}

.manage-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fcfaf5;
}

.button-pair {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.day-name,
.calendar-day {
  min-height: 84px;
  padding: 8px;
  border: 1px solid var(--line);
  background: #fcfaf5;
}

.day-name {
  min-height: auto;
  background: var(--night);
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.calendar-day.muted {
  opacity: 0.38;
}

.due-chip {
  display: block;
  margin-top: 6px;
  padding: 5px;
  background: #e8f3ee;
  color: var(--moss);
  font-size: 0.72rem;
  font-weight: 800;
}

.due-chip.late {
  background: #ffe4de;
  color: #9a3d2e;
}

.wanted-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  margin-bottom: 18px;
  background: #2f2430;
  color: #fff;
}

.wanted-hero p {
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.76);
}

.wanted-hero strong {
  font-size: 3rem;
  color: var(--gold);
}

.wanted-card {
  grid-template-columns: 54px 1fr auto;
  align-items: center;
}

.wanted-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #ffe4de;
  font-size: 1.4rem;
}

.avatar-jailed {
  color: var(--coral);
  font-weight: 900;
}

.toast-area {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 10px;
  z-index: 10;
}

.toast {
  width: min(360px, calc(100vw - 44px));
  padding: 14px 16px;
  background: var(--night);
  color: #fff;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
}

.toast strong {
  display: block;
  color: var(--gold);
}

@keyframes toastIn {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .app-shell,
  .split-layout,
  .guild-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

@media (max-width: 640px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .panel-head,
  .inline-controls,
  .wanted-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .calendar-grid {
    gap: 4px;
  }

  .calendar-day {
    min-height: 72px;
    font-size: 0.78rem;
  }
}
