* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  color-scheme: light;
  --ink: #382a21;
  --muted: #796654;
  --paper: #f7edcf;
  --paper-deep: #e8d4a5;
  --cinnabar: #9e3829;
  --gold: #c99332;
  --jade: #396c5b;
}

html,
body {
  width: 100%;
  height: 100%;
  display: grid;
  margin: 0;
  overflow: hidden;
  place-items: center;
  background: #1d1916;
  color: var(--ink);
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", "Songti SC", serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #2c7c88;
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.75);
  opacity: 0.52;
}

#game-shell {
  position: relative;
  width: min(100vw, 56.22dvh, 750px);
  height: min(100dvh, 177.87vw, 1334px);
  margin: 0 auto;
  overflow: hidden;
  container-type: inline-size;
  background: #e9ddbd;
  box-shadow: 0 0 60px #000b;
  font-size: 16px;
  font-size: 2.15cqw;
}

#app,
.screen {
  position: absolute;
  inset: 0;
}

.screen {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #e9ddbd center / cover no-repeat;
}

.loading-screen {
  display: grid;
  height: 100%;
  place-content: center;
  justify-items: center;
  background: #eee3c7;
}

.loading-screen img {
  width: 42%;
}

.loading-screen p {
  margin-top: 8cqw;
  letter-spacing: 0.2em;
}

.scroll-area {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #8c6d45 transparent;
}

.scroll-area::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 5px;
}

.scroll-area::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: #8c6d45;
  border-radius: 8px;
}

.title-screen {
  align-items: center;
  background-image: url("assets/textures/base/bj01.jpg");
  text-align: center;
}

.title-screen::after,
.setup-screen::after,
.home-screen::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  height: 17%;
  background: url("assets/textures/base/404aa.png") center bottom / 100% auto no-repeat;
  content: "";
  pointer-events: none;
}

.title-logo {
  z-index: 1;
  width: 47%;
  max-height: 51%;
  margin-top: 9%;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 #f7edcf);
}

.title-subtitle {
  z-index: 1;
  margin: 1cqw 0 5cqw;
  padding: 1cqw 4cqw;
  border-top: 1px solid #6a4d38;
  border-bottom: 1px solid #6a4d38;
  color: #513c2e;
  font-size: 2.8cqw;
  letter-spacing: 0.55cqw;
}

.title-actions {
  z-index: 1;
  display: grid;
  width: 58%;
  gap: 2.2cqw;
}

.title-footer {
  position: absolute;
  bottom: 2.2cqw;
  z-index: 1;
  color: #594b3d;
  font-size: 1.85cqw;
  letter-spacing: 0.15em;
}

.ink-button,
.paper-button,
.text-button,
.icon-button,
.feature-button,
.nav-button,
.choice-button {
  border: 0;
  cursor: pointer;
  user-select: none;
}

.ink-button {
  min-height: 8.4cqw;
  padding: 1.4cqw 5cqw 1.8cqw;
  background: url("assets/textures/ui/zqn06.png") center / 100% 100% no-repeat;
  color: #4b2f18;
  font-size: 3.1cqw;
  font-weight: 700;
  letter-spacing: 0.35cqw;
  text-shadow: 0 1px #fff5c9;
}

.ink-button:hover,
.ink-button:active {
  filter: brightness(1.07) saturate(1.1);
  transform: translateY(-1px);
}

.ink-button.secondary {
  background-image: url("assets/textures/ui/zqn03.png");
}

.ink-button.danger {
  background-image: url("assets/textures/ui/zqn06-1.png");
  color: #6e211b;
}

.ink-button.small {
  min-height: 6.6cqw;
  padding: 0.8cqw 3.2cqw 1.2cqw;
  font-size: 2.5cqw;
}

.paper-button,
.choice-button {
  min-height: 6.8cqw;
  padding: 1.1cqw 2.8cqw;
  border: 1px solid #9b7a4d;
  border-radius: 1.2cqw;
  background: linear-gradient(#fff8df, #e7cd96);
  box-shadow: 0 0.7cqw 1.5cqw #4b32142e;
  color: #513822;
  font-size: 2.35cqw;
  font-weight: 700;
}

.paper-button:hover,
.choice-button:hover {
  background: linear-gradient(#fffdf0, #f0d9a6);
}

.paper-button.danger {
  border-color: #a64b3c;
  color: #8d2d24;
}

.paper-button.jade {
  border-color: #4f7969;
  color: #2f5f50;
}

.text-button {
  padding: 0.8cqw 1.2cqw;
  background: transparent;
  color: #744432;
  font-size: 2.2cqw;
  text-decoration: underline;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.8cqw;
  align-items: center;
  justify-content: center;
  margin-top: 2.4cqw;
}

.button-row > * {
  flex: 1 1 28%;
}

.setup-screen {
  background-image: url("assets/textures/base/bj02.png");
}

.setup-header,
.home-header {
  z-index: 2;
  flex: none;
  padding: 2.4cqw 3.2cqw 1.2cqw;
  text-align: center;
}

.setup-header h1,
.panel-title,
.home-header h1 {
  margin: 0;
  color: #3c2c22;
  font-size: 4.4cqw;
  letter-spacing: 0.45cqw;
}

.setup-header p,
.home-header p {
  margin: 0.8cqw 0 0;
  color: #725a45;
  font-size: 2.15cqw;
}

.setup-content {
  z-index: 1;
  padding: 1cqw 4.5cqw 5cqw;
}

.paper-panel,
.stat-card,
.member-card,
.info-card,
.offer-card,
.log-card {
  border: 1px solid #b89a68;
  border-radius: 1.4cqw;
  background: #fff8e3d9;
  box-shadow: 0 0.8cqw 2.2cqw #4c35152b;
}

.paper-panel {
  margin-bottom: 2.4cqw;
  padding: 3cqw;
}

.paper-panel h2,
.info-card h3 {
  margin: 0 0 2cqw;
  color: #6d3528;
  font-size: 3cqw;
  text-align: center;
}

.world-buff {
  margin: 1.8cqw 0 0;
  padding: 1.8cqw;
  border-left: 0.8cqw solid var(--cinnabar);
  background: #f3dfb5;
  color: #664331;
  line-height: 1.5;
}

.form-grid {
  display: grid;
  grid-template-columns: 5em 1fr auto;
  gap: 1.5cqw;
  align-items: center;
  margin: 1.5cqw 0;
}

.form-grid label {
  color: #6d5540;
  font-weight: 700;
}

.text-input,
.select-input {
  width: 100%;
  min-width: 0;
  padding: 1.2cqw 1.6cqw;
  border: 1px solid #a7895f;
  border-radius: 0.8cqw;
  background: #fffdf4;
  color: #3b2c22;
}

.attribute-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5cqw;
}

.attribute {
  padding: 1.4cqw 0.8cqw;
  border-radius: 1cqw;
  background: #efe0bb;
  text-align: center;
}

.attribute strong {
  display: block;
  color: #8d392c;
  font-size: 3.1cqw;
}

.attribute span {
  color: #6f5a46;
  font-size: 1.9cqw;
}

.member-preview {
  display: flex;
  gap: 2cqw;
  align-items: center;
}

.avatar {
  width: 12cqw;
  height: 12cqw;
  flex: none;
  border: 1px solid #b28b54;
  border-radius: 50%;
  background: #e6d1a5;
  object-fit: cover;
  object-position: top;
}

.home-screen {
  background-image: url("assets/textures/base/zqd04.png");
}

.home-header {
  padding-bottom: 0.6cqw;
  background: linear-gradient(#f7efd8f2, #f7efd800);
}

.home-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.home-title-row h1 {
  font-size: 3.7cqw;
}

.home-title-row p {
  margin: 0.3cqw 0 0;
}

.header-actions {
  display: flex;
  gap: 1cqw;
}

.icon-button {
  display: grid;
  width: 7.2cqw;
  height: 7.2cqw;
  place-items: center;
  border: 1px solid #a17b4b;
  border-radius: 50%;
  background: #f7e7bb;
  color: #653c29;
  font-family: sans-serif;
  font-size: 3.2cqw;
  font-weight: 700;
}

.resource-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1cqw;
  margin-top: 1.2cqw;
}

.resource-item {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 0.6cqw;
  padding: 0.8cqw 0.4cqw;
  border-radius: 4cqw;
  background: #fff6d9dc;
  color: #513923;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 2.05cqw;
  font-weight: 700;
}

.resource-item img {
  width: 3.8cqw;
  height: 3.8cqw;
  object-fit: contain;
}

.home-content {
  z-index: 1;
  padding: 1.2cqw 3.2cqw 3cqw;
}

.notice-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1cqw;
  margin-bottom: 1.8cqw;
  padding: 1.2cqw 2cqw;
  border-top: 1px solid #9b7a52;
  border-bottom: 1px solid #9b7a52;
  background: #f4e5bde8;
  color: #6a4933;
  font-size: 2cqw;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2cqw 1.5cqw;
}

.feature-button {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 20cqw;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.2cqw 0.8cqw 1.5cqw;
  background: url("assets/textures/ui/zqk01.png") center / 100% 100% no-repeat;
  color: #fff0c4;
  text-shadow: 0 1px 2px #25160e;
}

.feature-button:hover {
  filter: brightness(1.12);
  transform: translateY(-0.4cqw);
}

.feature-button img {
  width: 9.2cqw;
  height: 9.2cqw;
  margin-bottom: 1.2cqw;
  object-fit: contain;
  filter: drop-shadow(0 0.5cqw 0.5cqw #0005);
}

.feature-button span {
  overflow: hidden;
  max-width: 100%;
  font-size: 2.55cqw;
  font-weight: 700;
  letter-spacing: 0.12cqw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav {
  z-index: 3;
  display: grid;
  flex: none;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  padding: 1.2cqw 2cqw 2.2cqw;
  background: linear-gradient(#e7d3a800, #e7d3a8 22%, #dbc18a);
  border-top: 1px solid #9a764b;
}

.nav-button {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 0.4cqw;
  padding: 0.8cqw 0.2cqw;
  background: transparent;
  color: #4f3828;
  font-size: 2cqw;
  font-weight: 700;
}

.nav-button img {
  width: 6.5cqw;
  height: 6.5cqw;
  object-fit: contain;
}

.nav-button.next-year {
  margin: 0 0.5cqw;
  padding: 1.4cqw 0.5cqw;
  border: 1px solid #8c562c;
  border-radius: 50%;
  background: radial-gradient(#f9d77b, #b95832);
  box-shadow: 0 0 2cqw #f2bf54;
  color: #fff4c9;
  text-shadow: 0 1px 2px #6e231c;
}

.nav-button.next-year img {
  width: 8.5cqw;
  height: 8.5cqw;
}

#modal-root:empty {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4cqw;
  background: #160f0bbd;
  animation: fade-in 160ms ease-out;
}

.modal-panel {
  display: flex;
  width: 100%;
  max-height: 94%;
  flex-direction: column;
  padding: 8cqw 6.5cqw 6cqw;
  background: url("assets/textures/ui/zqk10.png") center / 100% 100% no-repeat;
  animation: scroll-open 180ms ease-out;
}

.modal-panel.wide {
  width: 108%;
  margin: 0 -4%;
}

.modal-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 2cqw;
  margin-bottom: 2.2cqw;
  border-bottom: 1px solid #a7885c;
  padding-bottom: 1.4cqw;
}

.modal-header h2 {
  margin: 0;
  color: #673528;
  font-size: 3.8cqw;
  letter-spacing: 0.25cqw;
}

.modal-close {
  display: grid;
  width: 6.4cqw;
  height: 6.4cqw;
  flex: none;
  place-items: center;
  border: 0;
  background: url("assets/textures/ui/zqk11.png") center / 100% 100% no-repeat;
  color: #6a3c29;
  cursor: pointer;
  font-family: sans-serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.modal-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  line-height: 1.45;
}

.modal-footer {
  flex: none;
  padding-top: 1cqw;
}

.centered {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.danger-text {
  color: #9b3329;
}

.good-text {
  color: #2f6b52;
}

.gold-text {
  color: #8c5a17;
}

.small-text {
  font-size: 1.9cqw;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 1cqw;
  margin: 2.4cqw 0 1.4cqw;
  color: #6a382b;
  font-size: 2.8cqw;
}

.section-title::after {
  height: 1px;
  flex: 1;
  background: #b29262;
  content: "";
}

.card-list {
  display: grid;
  gap: 1.6cqw;
}

.member-card,
.info-card,
.offer-card,
.log-card,
.stat-card {
  padding: 2cqw;
}

.member-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.5cqw;
  align-items: center;
}

.member-card.dead {
  filter: grayscale(0.75);
  opacity: 0.72;
}

.member-card.current {
  border: 2px solid #a43e2e;
  background: #fff2c9;
}

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

.member-main h3 {
  overflow: hidden;
  margin: 0 0 0.5cqw;
  font-size: 2.7cqw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-main p {
  margin: 0.35cqw 0;
  color: #705947;
  font-size: 1.9cqw;
}

.member-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6cqw 1.4cqw;
  margin-top: 0.8cqw;
  color: #664736;
  font-size: 1.8cqw;
}

.badge {
  display: inline-block;
  margin: 0.2cqw;
  padding: 0.25cqw 1cqw;
  border: 1px solid #ac8757;
  border-radius: 3cqw;
  background: #f3dfae;
  color: #714330;
  font-size: 1.75cqw;
}

.badge.red {
  border-color: #a33e31;
  background: #f2c8ac;
  color: #852c24;
}

.badge.green {
  border-color: #4b7964;
  background: #cee1c8;
  color: #2f5c4a;
}

.tabs {
  display: flex;
  gap: 0.8cqw;
  margin-bottom: 1.8cqw;
  overflow-x: auto;
  padding-bottom: 0.6cqw;
}

.tab-button {
  flex: none;
  padding: 0.8cqw 2.2cqw;
  border: 1px solid #9f7c51;
  border-radius: 4cqw;
  background: #ead4a4;
  color: #624634;
  cursor: pointer;
}

.tab-button.active {
  background: #8f4030;
  color: #fff0c9;
}

.stat-grid,
.offer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.4cqw;
}

.stat-card {
  text-align: center;
}

.stat-card strong {
  display: block;
  color: #853c2e;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 3.4cqw;
}

.stat-card span {
  color: #715d49;
  font-size: 1.9cqw;
}

.offer-card {
  display: flex;
  flex-direction: column;
  gap: 1cqw;
}

.offer-card h3 {
  margin: 0;
  color: #6d382c;
}

.offer-card p {
  margin: 0;
  color: #6b5542;
  font-size: 1.9cqw;
}

.offer-card .button-row {
  margin-top: auto;
}

.report-lines {
  display: grid;
  gap: 0.8cqw;
}

.report-line {
  display: flex;
  justify-content: space-between;
  gap: 2cqw;
  padding: 0.7cqw 0;
  border-bottom: 1px dashed #b99c71;
}

.report-line strong {
  color: #743c2d;
}

.log-card {
  margin-bottom: 1.2cqw;
  color: #5f4939;
  font-size: 2cqw;
}

.log-card.good {
  border-left: 0.8cqw solid #4d7c5d;
}

.log-card.bad {
  border-left: 0.8cqw solid #a14234;
}

.quiz-options {
  display: grid;
  gap: 1.2cqw;
  margin-top: 2cqw;
}

.choice-button {
  text-align: left;
}

.progress-track {
  height: 2cqw;
  overflow: hidden;
  border-radius: 2cqw;
  background: #cdb68a;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #8f3f31, #daa743);
}

.empty-state {
  padding: 6cqw 2cqw;
  color: #796653;
  text-align: center;
}

#toast {
  position: absolute;
  bottom: 14cqw;
  left: 50%;
  z-index: 50;
  max-width: 84%;
  padding: 1.5cqw 3cqw;
  border: 1px solid #e3c583;
  border-radius: 4cqw;
  background: #35261eea;
  color: #fff0c5;
  font-size: 2.2cqw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 2cqw);
  transition: 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes scroll-open {
  from { opacity: 0; transform: translateY(2cqw) scale(0.98); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
