:root {
  color-scheme: light;
  --bg: #f4f1e8;
  --panel: #fffdf6;
  --ink: #22201c;
  --muted: #726c60;
  --line: #d8d0bf;
  --cell: #fbfaf4;
  --cell-hover: #ece4d4;
  --glyph-land: #f6efd8;
  --building-land: #bcd6a1;
  --wild-land: #b9a176;
  --accent: #2f6d67;
  --accent-weak: #d8ebe6;
  --warn: #a45338;
  --shadow: 0 12px 32px rgba(43, 38, 28, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-family:
    "Noto Serif SC", "Songti SC", "SimSun", "Microsoft YaHei", serif;
}

button {
  font: inherit;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(430px, 100vw);
  height: min(932px, 100vh);
  height: min(932px, 100dvh);
  margin: 0 auto;
  padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.game-hud,
.board-panel,
.bottom-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-hud {
  flex: 0 0 auto;
  padding: 6px;
}

.board-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding: 6px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.text-button,
.icon-button {
  min-width: 68px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.text-button:hover,
.icon-button:hover {
  border-color: var(--accent);
}

.text-button:disabled,
.icon-button:disabled,
.info-action:disabled {
  cursor: default;
  opacity: 0.48;
}

.action-row {
  display: flex;
  gap: 6px;
}

.board-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #8c7d62;
  border-radius: 6px;
  background: #8c7d62;
  touch-action: none;
}

.board {
  --cell-size: 58px;
  display: grid;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: 0 0;
  background: #8c7d62;
  gap: 2px;
  width: max-content;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  background: var(--cell);
  color: var(--ink);
  cursor: pointer;
  font-size: 34px;
  line-height: 1;
  touch-action: none;
  user-select: none;
  transition:
    background 120ms ease,
    color 120ms ease;
}

.cell:hover {
  background: var(--cell-hover);
}

.cell-spacer {
  visibility: hidden;
  pointer-events: none;
}

.cell.selected-tile {
  outline: 3px solid var(--accent);
  outline-offset: -5px;
  z-index: 1;
}

.cell.drag-hint-building {
  animation: hintBrightnessPulse 1.15s ease-in-out infinite;
}

.cell.drag-hint-merge {
  animation: hintBrightnessPulse 0.9s ease-in-out infinite;
}

.cell.drag-hint-building::after,
.cell.drag-hint-merge::after {
  content: "";
  position: absolute;
  inset: 7px;
  z-index: 12;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0.86;
  animation: hintGlowPulse 0.86s ease-in-out infinite;
}

.cell.drag-hint-building::after {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.94), rgba(194, 247, 255, 0.58) 42%, rgba(194, 247, 255, 0) 72%);
  box-shadow: 0 0 18px rgba(194, 247, 255, 0.92);
}

.cell.drag-hint-merge::after {
  background:
    radial-gradient(circle, rgba(255, 251, 220, 0.96), rgba(255, 174, 58, 0.7) 44%, rgba(255, 174, 58, 0) 74%);
  box-shadow: 0 0 18px rgba(255, 174, 58, 0.88);
}

.cell.has-glyph {
  background: var(--glyph-land);
}

.cell.wilderness {
  background: var(--wild-land);
  color: #58472a;
  font-size: 26px;
  cursor: default;
}

.cell.dragging {
  opacity: 0.45;
}

.cell.building {
  background: var(--building-land);
  color: #143d39;
}

.cell.building-active .glyph-char {
  animation: buildingGlyphBreath 2.4s ease-in-out infinite;
}

.cell.grain-boosted {
  background: #e5bf6f;
  color: #55340d;
  animation: grainCellPulse 1.16s ease-in-out infinite;
}

.cell.grain-boosted::before {
  position: absolute;
  inset: 5px;
  z-index: 12;
  border-radius: 5px;
  background: linear-gradient(115deg, transparent 0%, rgba(255, 247, 191, 0) 28%, rgba(255, 247, 191, 0.7) 48%, rgba(255, 247, 191, 0) 68%, transparent 100%);
  content: "";
  opacity: 0.78;
  pointer-events: none;
  transform: translateX(-58%);
  animation: grainSweep 1.65s ease-in-out infinite;
}

.cell.grain-boosted .glyph-char {
  position: relative;
  z-index: 30;
  animation: grainGlyphPulse 0.92s ease-in-out infinite;
}

.cell.grain-boosted .level-badge {
  z-index: 35;
}

.cell.core {
  background: #e2c27f;
  color: #4c3310;
}

.glyph-char {
  line-height: 1;
}

.glyph-weight-1 {
  font-weight: 400;
}

.glyph-weight-2 {
  font-weight: 500;
}

.glyph-weight-3 {
  font-weight: 600;
}

.glyph-weight-4 {
  font-weight: 700;
}

.glyph-weight-5 {
  font-weight: 900;
}

.level-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  border: 1px solid currentColor;
  border-radius: 50%;
  padding: 0 4px;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.building-outline {
  position: absolute;
  pointer-events: none;
  border: 0 solid transparent;
}

.building-outline.top {
  top: 3px;
  right: 3px;
  left: 3px;
  border-top-width: 4px;
}

.building-outline.right {
  top: 3px;
  right: 3px;
  bottom: 3px;
  border-right-width: 4px;
}

.building-outline.bottom {
  right: 3px;
  bottom: 3px;
  left: 3px;
  border-bottom-width: 4px;
}

.building-outline.left {
  top: 3px;
  bottom: 3px;
  left: 3px;
  border-left-width: 4px;
}

@keyframes hintBrightnessPulse {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.16);
  }
}

@keyframes hintGlowPulse {
  0%,
  100% {
    transform: scale(0.78);
    opacity: 0.58;
  }

  50% {
    transform: scale(1.12);
    opacity: 1;
  }
}

@keyframes buildingGlyphBreath {
  0%,
  100% {
    filter: brightness(1);
    transform: translateY(0) scale(1);
  }

  50% {
    filter: brightness(1.08);
    transform: translateY(-1px) scale(1.025);
  }
}

@keyframes grainCellPulse {
  0%,
  100% {
    box-shadow: inset 0 0 0 rgba(255, 231, 138, 0), 0 0 0 rgba(210, 139, 45, 0);
  }

  50% {
    box-shadow: inset 0 0 18px rgba(255, 231, 138, 0.72), 0 0 14px rgba(210, 139, 45, 0.34);
  }
}

@keyframes grainGlyphPulse {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }

  50% {
    filter: brightness(1.16);
    transform: scale(1.055);
  }
}

@keyframes grainSweep {
  0% {
    transform: translateX(-70%);
  }

  48%,
  100% {
    transform: translateX(70%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell.building-active .glyph-char,
  .cell.grain-boosted,
  .cell.grain-boosted::before,
  .cell.grain-boosted .glyph-char,
  .cell.drag-hint-building,
  .cell.drag-hint-merge,
  .cell.drag-hint-building::after,
  .cell.drag-hint-merge::after {
    animation: none;
  }
}


.bottom-panel {
  flex: 0 0 auto;
  display: grid;
  gap: 5px;
  padding: 6px;
}

.secondary-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.nav-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.nav-button.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: #184945;
}

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

.hand-panel h2 {
  margin-bottom: 6px;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 15px;
  font-weight: 700;
}

.section-heading h2 {
  margin-bottom: 0;
}

.glyph-tray {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.info-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(43, 38, 28, 0.18);
}

.floating-info {
  position: absolute;
  z-index: 120;
  display: none;
  width: min(250px, calc(100% - 18px));
  pointer-events: auto;
}

.floating-info.open {
  display: block;
}

.floating-info.measuring {
  visibility: hidden;
}

.info-title {
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.info-body {
  margin-top: 6px;
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 12px;
  line-height: 1.45;
}

.info-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.info-buildings {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.info-building {
  border-left: 3px solid var(--accent);
  padding-left: 7px;
}

.info-building-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.info-building-kind,
.info-building-effect {
  margin-top: 2px;
}

.info-action {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  background: #fffdf6;
  color: var(--ink);
  cursor: pointer;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 12px;
}

.info-action.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.glyph {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-height: 52px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 28px;
  touch-action: none;
  user-select: none;
}

.hand-slot {
  min-width: 0;
}

.hand-slot.empty-slot {
  border-style: dashed;
  background: #f8f4ea;
  color: var(--muted);
}

.hand-slot.empty-slot::after {
  content: "";
  width: 16px;
  height: 16px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  opacity: 0.55;
  transform: rotate(45deg) translate(-2px, -2px);
}

.drag-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 10px 26px rgba(43, 38, 28, 0.2);
  font-size: 30px;
  line-height: 1;
  pointer-events: none;
}

.resource-list {
  display: grid;
  grid-template-columns: 0.58fr 0.72fr repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.status-panel:empty {
  display: none;
}

.status-item,
.status-message {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  background: #ffffff;
  font-family: "Microsoft YaHei", sans-serif;
}

.status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.status-item span {
  color: var(--muted);
  font-size: 10px;
}

.status-item strong {
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.status-message {
  grid-column: 1 / -1;
  border-color: #dfb78d;
  background: #fff4df;
  color: #794916;
  font-size: 12px;
}

.resource-item {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 3px;
  background: #ffffff;
}

.resource-name {
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 10px;
  line-height: 1;
}

.resource-value {
  color: var(--ink);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-rate {
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
}

.resource-rate.positive {
  color: #287046;
}

.resource-rate.negative {
  color: #9a3f2a;
}

.empty {
  padding: 13px 0;
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

.codex-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
}

.codex-row + .codex-row {
  margin-top: 7px;
}

.codex-row.locked {
  opacity: 0.48;
}

.codex-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.codex-main {
  font-size: 21px;
  line-height: 1;
}

.codex-meta,
.codex-detail {
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
}

.codex-meta {
  font-size: 12px;
  text-align: right;
}

.codex-detail {
  font-size: 12px;
  line-height: 1.4;
}

.codex-detail p {
  margin: 3px 0 0;
}

.codex-detail p:first-child {
  margin-top: 0;
}

.secondary-panel {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: end;
  justify-content: center;
  padding: 8px;
  background: rgba(32, 28, 20, 0.24);
}

.secondary-panel.open {
  display: flex;
}

.secondary-panel:not(.open) .secondary-x-button {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(28, 24, 18, 0.58);
}

.modal-overlay.open {
  display: grid;
}

.ad-overlay {
  place-items: end center;
  padding: 8px;
  background: rgba(32, 28, 20, 0.72);
}

.modal-sheet {
  width: min(320px, 100%);
  border: 1px solid #9a875f;
  border-radius: 8px;
  padding: 18px;
  background: #fffaf0;
  box-shadow: 0 18px 44px rgba(30, 25, 17, 0.32);
}

.modal-sheet h2 {
  margin: 0 0 14px;
  font-size: 22px;
  line-height: 1.1;
  text-align: center;
}

.login-sheet {
  display: grid;
  gap: 10px;
}

.login-sheet input {
  height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font: 16px "Microsoft YaHei", sans-serif;
}

.modal-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font: 12px "Microsoft YaHei", sans-serif;
  text-align: center;
}

.ad-sheet {
  display: grid;
  gap: 12px;
  width: min(430px, 100%);
  border-color: var(--line);
  padding: 16px;
  background: var(--panel);
  text-align: center;
}

.ad-sheet h2 {
  margin-bottom: 2px;
  font-size: 18px;
}

.ad-countdown {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 132px;
  margin: 0 auto;
  border: 2px solid #b77b32;
  border-radius: 8px;
  background: #fff4df;
  color: #794916;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.56);
  font: 700 34px "Microsoft YaHei", sans-serif;
}

.ad-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ad-actions .info-action {
  min-height: 40px;
}

.secondary-sheet {
  display: flex;
  flex-direction: column;
  width: min(430px, 100%);
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px rgba(32, 28, 20, 0.24);
}

.secondary-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 11px 48px;
}

.secondary-header h2 {
  margin: 0;
  font-size: 16px;
  text-align: center;
}

.secondary-x-button {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(50% - min(215px, 50vw) + 12px);
  z-index: 260;
  display: grid;
  place-items: center;
  min-width: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #9a875f;
  border-radius: 999px;
  background: #fff7e8;
  color: var(--ink);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(32, 28, 20, 0.22);
}

.secondary-content {
  flex: 1 1 auto;
  overflow: auto;
  padding: 10px;
}

.codex-section + .codex-section {
  margin-top: 14px;
}

.codex-section h3 {
  margin: 0 0 8px;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 13px;
}

.glyph-codex-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.glyph-codex-item {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.glyph-codex-item span {
  font-size: 24px;
  line-height: 1;
}

.glyph-codex-item small {
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 10px;
}

.tech-summary {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 10px;
  padding: 9px 10px;
  background: #ffffff;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

.detail-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 7px;
  padding: 9px 10px;
  background: #ffffff;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 13px;
}

.detail-line span {
  color: var(--muted);
}

.detail-line strong {
  color: var(--ink);
}

.detail-line.positive strong {
  color: #287046;
}

.detail-line.negative strong {
  color: #9a3f2a;
}

.tech-tree {
  display: grid;
  gap: 8px;
}

.tech-card {
  position: relative;
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #ffffff;
}

.tech-card.locked {
  opacity: 0.48;
}

.tech-card.available {
  border-color: #b68b43;
  background: #fff8e8;
}

.tech-card.done {
  border-color: #9ab9aa;
  background: #f3fbf6;
}

.tech-title-group {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.tech-type-tag {
  flex: 0 0 auto;
  border: 1px solid #a78b55;
  border-radius: 999px;
  padding: 2px 5px;
  background: #fff5dc;
  color: #7b5314;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.tech-type-tag.branch {
  border-color: #89a9a1;
  background: #e8f4f0;
  color: #2f6d67;
}

.tech-badge,
.tech-lock {
  color: var(--muted);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 12px;
}

.tech-card.available .tech-badge {
  color: #8a5b12;
  font-weight: 700;
}

.tech-card.done .tech-badge {
  color: #287046;
  font-weight: 700;
}

.tech-research-button {
  min-height: 34px;
}

@media (max-width: 860px) {
  .app {
    width: min(430px, 100vw);
    padding: 8px;
  }

  .board-panel,
  .bottom-panel {
    padding: 8px;
  }

  .board {
    max-height: none;
  }

  .glyph-tray {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 460px) {
  .text-button {
    width: 100%;
  }

  .action-row {
    min-width: 142px;
  }
}
