:root {
  color-scheme: light dark;
  font-family: system-ui, sans-serif;
  --border: color-mix(in srgb, currentColor 25%, transparent);
}

body {
  margin: 0;
}

input,
button {
  font: inherit;
  padding: 0.5rem 0.75rem;
}

/* Sign-in views (rendered by webapp's <AuthGate>). */
.webapp-login,
.webapp-status,
.webapp-error {
  max-width: 32rem;
  margin: 3rem auto;
  padding: 0 1rem;
}

.webapp-login {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.webapp-error {
  color: #c62828;
}

.webapp-status,
.account,
.placeholder {
  opacity: 0.7;
}

/* World page: header on top; the map fills the rest beside a panel (a bottom sheet on
   phones). */
.world-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.top-bar h1 {
  font-size: 1.15rem;
  margin: 0;
}

.top-bar .account {
  margin-left: auto;
}

.top-bar .clock {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.top-bar button,
.tabs button {
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:hover {
  text-decoration: underline;
}

.home-link .short {
  display: none;
}

/* Home page: a card per world. */
.home {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem;
}

.home h2 {
  font-size: 1.1rem;
  margin: 0.5rem 0 1rem;
}

.world-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
}

.world-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.world-card:hover,
.world-card:focus-visible {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 6%, transparent);
}

.world-card-name {
  font-size: 1.2rem;
  font-weight: 600;
}

.world-card-size {
  opacity: 0.7;
}

.views {
  display: flex;
  gap: 0.25rem;
}

button.active {
  font-weight: 600;
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

.world-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.map-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

/* Out of the layout flow, so the canvas's own size never stops the area shrinking. */
.map {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  background: rgb(28, 58, 98);
}

.map:active {
  cursor: grabbing;
}

.map-message {
  padding: 1rem;
}

.panel {
  width: 300px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.sheet-toggle {
  display: none;
  margin-left: auto;
}

.tab-body {
  padding: 0.5rem 0.75rem;
  overflow: auto;
}

.tab-body h2 {
  font-size: 1rem;
  margin: 0.25rem 0 0.5rem;
}

.tab-body h3 {
  font-size: 0.9rem;
  margin: 0.9rem 0 0.4rem;
  opacity: 0.85;
}

.facts dd a {
  color: inherit;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  margin: 0;
}

.facts dt {
  opacity: 0.7;
}

.facts dd {
  margin: 0;
}

.tab-body a {
  color: inherit;
}

button.follow {
  padding: 0.3rem 0.7rem;
  margin: 0 0 0.6rem;
}

.sort {
  margin-bottom: 0.5rem;
  opacity: 0.85;
}

.sort button {
  padding: 0.2rem 0.6rem;
}

.town-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.town-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
}

.town-list li.active {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

.town-meta {
  opacity: 0.7;
  white-space: nowrap;
}

.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.town-filter {
  padding: 0.25rem 0.4rem;
}

.event-list,
.people-list,
.history {
  list-style: none;
  margin: 0;
  padding: 0;
}

.event-list li,
.people-list li {
  display: flex;
  flex-direction: column;
  padding: 0.3rem 0.4rem;
  border-left: 3px solid transparent;
  margin-bottom: 0.15rem;
}

.event-list .when,
.people-list .meta,
.people-list .why {
  font-size: 0.85em;
  opacity: 0.7;
}

.event-list .birth,
.event-list .marriage {
  border-left-color: #43a047;
}

.event-list .death {
  border-left-color: #757575;
}

.event-list .raid,
.event-list .death.serious {
  border-left-color: #e53935;
}

.event-list .rations {
  border-left-color: #fb8c00;
}

.event-list .move,
.event-list .house {
  border-left-color: #1e88e5;
}

.people-list li.watched {
  border-left-color: #ffeb3b;
}

button.older {
  margin: 0.5rem 0;
  padding: 0.3rem 0.7rem;
}

.history li {
  font-size: 0.85em;
  opacity: 0.8;
  padding: 0.15rem 0;
}

@media (max-width: 700px) {
  .top-bar .account,
  .top-bar .clock .year,
  .home-link .long {
    display: none;
  }

  .home-link .short {
    display: inline;
  }

  .home-page .top-bar button {
    margin-left: auto;
  }

  .top-bar .views {
    margin-left: auto;
  }

  .world-layout {
    flex-direction: column;
  }

  /* Bottom sheet: just the tab bar until opened. */
  .panel {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .panel .tab-body {
    display: none;
  }

  .panel.open .tab-body {
    display: block;
    height: 40dvh;
  }

  .sheet-toggle {
    display: block;
  }
}

/* Level controls over the map in the low view. */
.level-controls {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  min-width: 2.75rem;
}

.level-controls button {
  min-height: 2.5rem;
  padding: 0.25rem 0.5rem;
}

.level-controls .level {
  padding: 0.2rem 0.4rem;
  text-align: center;
  font-size: 0.8rem;
  white-space: nowrap;
  color: #fff;
  background: rgb(0 0 0 / 0.6);
  border-radius: 0.25rem;
}
