:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #090806;
  color: #f8efe0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 18% 8%, rgba(222, 159, 86, 0.22), transparent 30%), #090806;
}

.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  width: auto;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.app-tabs {
  position: fixed;
  right: 28px;
  top: 28px;
  width: min(560px, calc(100vw - 56px));
  z-index: 35;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 2px;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.tab-button,
.login-open,
.modal-heading button {
  border: 1px solid rgba(248, 239, 224, 0.14);
  border-radius: 999px;
  padding: 10px 14px;
  background: #20170f;
  color: #f8efe0;
  cursor: pointer;
  font-weight: 800;
}

.tab-button {
  min-width: 0;
  flex: 1 1 auto;
  margin-bottom: -1px;
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: #15100b;
  text-align: center;
}

.tab-button.active,
.login-open:hover {
  border-color: #e9b872;
  color: #e9b872;
}

.tab-button.active {
  background: #2b1e12;
  box-shadow: 0 6px 0 #2b1e12;
}

.tabs-toggle {
  flex: 0 0 54px;
  text-align: center;
  margin-left: auto;
}

.app-tabs.tabs-collapsed .tab-button[data-tab] {
  display: none;
}

.login-open {
  background: #1c160f;
}

.hidden {
  display: none !important;
}

.login-dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 24px;
  background: #16110c;
  color: #f8efe0;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
}

.login-dialog::backdrop {
  background: #000000;
}

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

.login-message {
  min-height: 1.2em;
  margin: 0;
  color: #ffb3a7;
}

.shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  position: relative;
}

.hero,
.panel {
  border: 1px solid rgba(248, 239, 224, 0.14);
  border-radius: 26px;
  background: #1c160f;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.32);
}

.hero {
  padding: 30px;
}

.eyebrow,
.label {
  margin: 0;
  color: #e9b872;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 12px 0 14px;
  max-width: 680px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.7rem, 7vw, 5.6rem);
  line-height: 0.92;
}

h2,
h3,
h4 {
  margin: 0;
}

p {
  color: #d8c7ad;
  line-height: 1.6;
}

.status-panel {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.status-panel div {
  padding: 18px;
  border-radius: 18px;
  background: #2a2016;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.record-grid div {
  padding: 18px;
  border-radius: 18px;
  background: #2a2016;
}

strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.status-panel,
.admin-panel,
.events-panel {
  grid-column: 1 / -1;
}

.world-panel {
  grid-column: 1 / -1;
  grid-row: 1;
}

.shell.tabs-open .world-panel {
  grid-column: 1 / -1;
  grid-row: 1;
}

.detail-panel {
  grid-column: 2;
  align-self: start;
  position: fixed;
  right: 28px;
  top: 67px;
  z-index: 25;
  width: min(560px, calc(100vw - 56px));
  max-height: calc(100vh - 92px);
  overflow: auto;
  border-top-right-radius: 0;
}

.overlay-panel:not(.detail-panel) {
  grid-column: 1 / -1;
  position: fixed;
  right: 28px;
  top: 67px;
  z-index: 24;
  width: min(560px, calc(100vw - 56px));
  max-height: calc(100vh - 92px);
  overflow: auto;
  border-top-right-radius: 0;
}

.shell.tabs-open .overlay-panel:not(.hidden),
.shell.tabs-open .detail-panel:not(.hidden):not(.collapsed) {
  margin-top: 0;
}

.detail-panel.collapsed {
  display: none;
}

.panel {
  padding: 18px;
}

canvas {
  width: 100%;
  margin-top: 16px;
  display: block;
  border-radius: 18px;
  background: #11140e;
  cursor: grab;
  user-select: none;
}

canvas.dragging {
  cursor: grabbing;
}

.map-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 16px;
}

.map-row canvas {
  min-width: 0;
  margin-top: 0;
  flex: 1 1 auto;
}

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

.panel-heading span,
#backend-status,
#knowledge {
  color: #e9b872;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86rem;
}

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

.generation-picker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: #d8c7ad;
}

.map-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  margin-left: 12px;
}

.assist-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}

.assist-tool {
  border: 1px solid rgba(233, 184, 114, 0.45);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  padding: 0;
  background: #2f2417;
  color: #f8efe0;
  cursor: grab;
  font-size: 1.35rem;
  line-height: 1;
}

.bad-tool {
  border-color: rgba(255, 95, 95, 0.72);
  background: #3a1717;
}

.assist-tool:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.population-status {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.population-status div {
  padding: 12px;
  border-radius: 14px;
  background: #261d14;
}

.population-status div.warning {
  border: 1px solid rgba(255, 209, 102, 0.65);
  background: #4a3512;
}

.population-status div.critical {
  border: 1px solid rgba(255, 49, 49, 0.72);
  background: #4a1717;
}

.population-status span,
.population-status strong {
  display: block;
}

.population-status span {
  color: #bda98b;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.population-status strong {
  margin-top: 4px;
  font-size: 1.4rem;
}

.population-status meter {
  width: 100%;
  margin-top: 8px;
}

.generation-picker select,
.map-controls button,
.history-controls button {
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 12px;
  padding: 9px 11px;
  background: #261d14;
  color: #f8efe0;
}

#zoom-label {
  min-width: 48px;
  color: #e9b872;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.history-controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.history-controls button:disabled {
  opacity: 0.45;
}

.login-form input,
.login-form button,
.danger-button {
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 14px;
  padding: 12px 14px;
  background: #261d14;
  color: #f8efe0;
}

.login-form button,
.danger-button {
  cursor: pointer;
  font-weight: 800;
}

.danger-button {
  margin-top: 12px;
  background: #5b2424;
}

.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.admin-note {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.db-stats-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.db-stats-heading button {
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 12px;
  padding: 9px 11px;
  background: #261d14;
  color: #f8efe0;
  cursor: pointer;
}

.db-stats {
  margin-top: 12px;
  overflow-x: auto;
}

.db-stats table {
  width: 100%;
  border-collapse: collapse;
}

.top-savers table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
}

.db-stats th,
.db-stats td,
.top-savers th,
.top-savers td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(248, 239, 224, 0.12);
  text-align: left;
}

.db-stats td:last-child,
.db-stats th:last-child {
  text-align: right;
}

.top-savers td:last-child,
.top-savers th:last-child {
  text-align: right;
}

.saver-form {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.saver-form input,
.saver-form button {
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 14px;
  padding: 10px 12px;
  background: #261d14;
  color: #f8efe0;
}

#person-detail {
  margin-top: 16px;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.person-profile {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.portrait {
  width: 96px;
  height: 112px;
  flex: 0 0 auto;
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 22px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
}

.person-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: #e9b872;
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.person-link:hover {
  color: #ffdca6;
}

.empty {
  color: #bda98b;
}

.trait-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.trait-grid section {
  padding: 12px;
  border-radius: 14px;
  background: #261d14;
}

ol {
  margin: 16px 0 0;
  padding-left: 22px;
  color: #eadbc5;
}

li {
  margin: 9px 0;
}

#events span {
  color: #e9b872;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  margin-right: 10px;
}

#events strong {
  display: inline;
  margin: 0 10px 0 0;
  font-size: 0.78rem;
  text-transform: uppercase;
}

#app-version {
  position: fixed;
  left: 12px;
  bottom: 10px;
  z-index: 20;
  padding: 7px 10px;
  border: 1px solid rgba(248, 239, 224, 0.16);
  border-radius: 999px;
  background: #090806;
  color: #e9b872;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .status-panel,
  .population-status,
  .trait-grid {
    grid-template-columns: 1fr;
  }

  .world-panel,
  .detail-panel {
    grid-column: 1;
    position: static;
  }
}
