:root {
  --ink: #171513;
  --muted: #6c665c;
  --paper: #f3ead8;
  --ivory: #fffaf0;
  --line: rgba(23, 21, 19, 0.14);
  --black: #090908;
  --green: #285844;
  --moss: #6f8f55;
  --river: #5ca7a5;
  --wine: #6b2633;
  --gold: #b38a48;
  --stone: #81776b;
  --shadow: 0 18px 48px rgba(20, 17, 13, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(179, 138, 72, 0.12), transparent 32%),
    linear-gradient(180deg, #f5eddf 0%, #eee2cf 100%);
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 12px clamp(16px, 4vw, 48px);
  color: var(--ivory);
  background: rgba(9, 9, 8, 0.9);
  border-bottom: 1px solid rgba(255, 250, 240, 0.14);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--black);
  background: var(--gold);
  font-family: SimSun, "Songti SC", serif;
  font-weight: 900;
}

.nav {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.nav a {
  min-width: 58px;
  padding: 8px 10px;
  color: rgba(255, 250, 240, 0.82);
  text-align: center;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.nav a:hover {
  color: var(--ivory);
  border-color: var(--gold);
}

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

.icon-button,
.admin-button,
.compact-button {
  min-height: 38px;
  border: 1px solid rgba(255, 250, 240, 0.2);
  background: rgba(255, 250, 240, 0.08);
  color: var(--ivory);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.import-label input {
  display: none;
}

.admin-button,
.compact-button {
  padding: 0 16px;
  font-weight: 800;
}

.admin-button.is-active {
  color: var(--black);
  background: var(--ivory);
}

.kingdom-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 22px;
  padding: clamp(30px, 5vw, 70px) clamp(18px, 4vw, 54px) 24px;
  align-items: end;
}

.kingdom-copy h1,
.panel h2,
.modal h3 {
  margin: 0;
  font-family: SimSun, "Songti SC", serif;
}

.kingdom-copy h1 {
  font-size: clamp(2.5rem, 6vw, 5.6rem);
  line-height: 1;
  letter-spacing: 0;
}

.hero-line {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.8;
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.hero-meta span {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.66);
  color: var(--muted);
  font-weight: 700;
}

.royal-card {
  display: grid;
  gap: 8px;
  padding: 22px;
  color: var(--ivory);
  background: var(--black);
  box-shadow: var(--shadow);
}

.royal-card strong {
  color: var(--gold);
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

.royal-label {
  color: rgba(255, 250, 240, 0.72);
  font-weight: 800;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 clamp(18px, 4vw, 54px);
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.74);
}

.metric {
  min-height: 96px;
  padding: 20px clamp(16px, 3vw, 32px);
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric-value,
.metric-label {
  display: block;
}

.metric-value {
  color: var(--green);
  font-size: clamp(1.8rem, 3.4vw, 3rem);
  font-weight: 900;
  line-height: 1;
}

.metric-label {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 800;
}

.realm-panel,
.court-panel,
.panel {
  min-width: 0;
  background: rgba(255, 250, 240, 0.76);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.realm-panel {
  margin: 18px clamp(18px, 4vw, 54px);
}

.court-panel {
  margin: 18px clamp(18px, 4vw, 54px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.panel h2,
.realm-panel h2 {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

.compact-button {
  border-color: rgba(23, 21, 19, 0.18);
  color: var(--ivory);
  background: var(--black);
}

.compact-button.secondary {
  color: var(--ink);
  background: transparent;
}

.admin-only {
  display: none;
}

body.admin .admin-only {
  display: inline-flex;
  align-items: center;
}

.realm-layout,
.court-layout {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.realm-layout {
  grid-template-columns: minmax(0, 1fr) 270px;
}

.court-layout {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  align-items: start;
}

.map-wrap {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid rgba(23, 21, 19, 0.18);
  background:
    linear-gradient(135deg, rgba(79, 91, 64, 0.18) 25%, transparent 25%) 0 0 / 28px 28px,
    linear-gradient(225deg, rgba(79, 91, 64, 0.12) 25%, transparent 25%) 0 0 / 28px 28px,
    #d2c1a6;
}

.river {
  position: absolute;
  inset: -80px 40% -80px auto;
  width: 150px;
  transform: rotate(18deg);
  background: repeating-linear-gradient(
    180deg,
    rgba(92, 167, 165, 0.3) 0,
    rgba(92, 167, 165, 0.58) 18px,
    rgba(255, 250, 240, 0.25) 28px,
    rgba(92, 167, 165, 0.48) 42px
  );
  filter: blur(0.5px);
  animation: riverFlow 7s linear infinite;
}

@keyframes riverFlow {
  from {
    background-position-y: 0;
  }
  to {
    background-position-y: 84px;
  }
}

.realm-map {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(7, minmax(66px, 1fr));
  gap: 12px;
  padding: 24px;
}

.map-tile {
  position: relative;
  min-height: 92px;
  padding: 10px;
  border: 1px solid rgba(23, 21, 19, 0.18);
  background: #9b8d78;
  color: var(--ivory);
  text-align: left;
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.map-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(20, 17, 13, 0.18);
}

.map-tile::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(255, 250, 240, 0.24);
}

.map-tile::after {
  content: attr(data-icon);
  position: absolute;
  right: 8px;
  bottom: 4px;
  font-size: 2rem;
}

.map-tile.ruin {
  background:
    radial-gradient(circle at 28% 36%, #61584d 0 9px, transparent 10px),
    radial-gradient(circle at 72% 62%, #756b61 0 11px, transparent 12px),
    linear-gradient(145deg, #8a7e70, #6f665d);
}

.map-tile.level-1 {
  background: linear-gradient(145deg, #87955f, #5d7550);
}

.map-tile.level-2 {
  background: linear-gradient(145deg, #6f935e, #2f6c54);
}

.map-tile.level-3 {
  background: linear-gradient(145deg, #446f65, #223d3b);
}

.tile-day {
  position: relative;
  z-index: 1;
  display: block;
  font-weight: 900;
}

.tile-title {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 8px;
  color: rgba(255, 250, 240, 0.82);
  font-size: 0.76rem;
  line-height: 1.35;
}

.tile-note {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 1;
  width: calc(100% - 48px);
  height: 3px;
  background: rgba(255, 250, 240, 0.44);
}

.advisor-card,
.court-registry {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.72);
}

.advisor-card {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 260px;
  background:
    linear-gradient(135deg, rgba(107, 38, 51, 0.08), transparent 38%),
    rgba(255, 250, 240, 0.78);
}

.advisor-role {
  margin: 0;
  color: var(--gold);
  font-weight: 900;
}

.advisor-card h3,
.court-registry h3 {
  margin: 0;
  font-family: SimSun, "Songti SC", serif;
}

.advisor-comment {
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.8;
}

.advisor-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.advisor-skills .pill {
  background: rgba(179, 138, 72, 0.12);
  color: var(--wine);
}

.registry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.guestbook-form {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.guestbook-form .compact-button {
  min-width: 72px;
}

.court-item {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.66);
}

.court-name,
.court-title,
.court-message,
.court-time {
  display: block;
}

.court-name {
  color: var(--muted);
  font-weight: 800;
}

.court-title {
  margin-top: 4px;
  color: var(--green);
  font-weight: 900;
}

.court-message {
  margin-top: 8px;
  color: var(--ink);
  line-height: 1.65;
}

.court-time {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.legend {
  display: grid;
  gap: 12px;
  align-content: start;
}

.legend > div {
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.62);
}

.legend strong {
  display: block;
}

.legend p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.legend-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 1px solid rgba(23, 21, 19, 0.18);
}

.legend-dot.ruin {
  background: #756b61;
}

.legend-dot.level-1 {
  background: #87955f;
}

.legend-dot.level-2 {
  background: #2f6c54;
}

.legend-dot.level-3 {
  background: #223d3b;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 18px;
  padding: 0 clamp(18px, 4vw, 54px) 64px;
}

.task-list,
.focus-list,
.idea-stream,
.paper-grid {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.task-item,
.focus-item,
.idea-item,
.paper-item {
  position: relative;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.78);
}

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
  padding: 16px;
}

.task-check {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid rgba(23, 21, 19, 0.24);
  color: transparent;
  background: transparent;
}

.task-item.done {
  opacity: 0.58;
}

.task-item.done .task-check {
  color: var(--ivory);
  background: var(--green);
}

.task-title,
.idea-title,
.paper-title {
  margin: 0;
  font-weight: 900;
}

.task-note,
.idea-body,
.paper-reflection {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: rgba(40, 88, 68, 0.08);
  color: var(--green);
  font-weight: 800;
}

.danger {
  color: var(--wine);
}

.delete-button {
  display: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  color: var(--wine);
  background: transparent;
  font-size: 20px;
  line-height: 1;
}

body.admin .delete-button {
  display: block;
}

.focus-item,
.idea-item,
.paper-item {
  padding: 16px;
}

.focus-item {
  border-left: 4px solid var(--gold);
}

.idea-stream {
  max-height: 620px;
  overflow: auto;
}

.idea-item::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 20px;
  width: 8px;
  height: 8px;
  background: var(--gold);
}

.idea-item {
  padding-left: 34px;
}

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

.paper-file {
  margin-top: 12px;
  color: var(--stone);
  font-size: 0.9rem;
  font-weight: 800;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  border: 1px dashed rgba(23, 21, 19, 0.22);
  background: rgba(255, 250, 240, 0.56);
}

.modal {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(9, 9, 8, 0.66);
  backdrop-filter: blur(6px);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--ivory);
  border: 1px solid rgba(255, 250, 240, 0.55);
  box-shadow: var(--shadow);
}

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

.ghost-icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 22px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid rgba(23, 21, 19, 0.2);
  background: #fffdf7;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--wine);
  font-weight: 800;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .nav {
    display: none;
  }

  .kingdom-hero,
  .summary-band,
  .realm-layout,
  .court-layout,
  .workspace-grid,
  .paper-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .map-wrap {
    min-height: 460px;
  }

  .realm-map {
    grid-template-columns: repeat(4, minmax(64px, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 10px 12px;
  }

  .brand span:last-child {
    display: none;
  }

  .kingdom-hero {
    padding: 26px 14px 14px;
  }

  .summary-band,
  .court-panel,
  .realm-panel {
    margin-left: 12px;
    margin-right: 12px;
  }

  .workspace-grid {
    padding: 0 12px 42px;
  }

  .realm-layout,
  .task-list,
  .focus-list,
  .idea-stream,
  .paper-grid {
    padding: 14px;
  }

  .realm-map {
    grid-template-columns: repeat(3, minmax(72px, 1fr));
    gap: 10px;
    padding: 14px;
  }

  .map-tile {
    min-height: 86px;
  }

  .task-item {
    grid-template-columns: 1fr auto;
  }

  .task-check {
    grid-row: 1;
  }

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