:root {
  --ink: #14282b;
  --paper: #d8cfaa;
  --cream: #eee7cf;
  --teal: #0b3a43;
  --teal-deep: #082c34;
  --gold: #c5a357;
  --shadow: #585b52;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #64787a;
  color: var(--ink);
  font: 12px "Lucida Console", Monaco, "Courier New", monospace;
}

button,
select { font: inherit; }

button { cursor: pointer; }

.app {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) 25px;
  width: 100%;
  height: 100%;
  min-width: 860px;
  background: #b9bab0;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 11px;
  color: #f5ebc9;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px),
    linear-gradient(90deg, #082e36, #114954 55%, #082e36);
  border-bottom: 2px solid var(--gold);
  box-shadow: inset 0 1px #3c7379, inset 0 -1px #071f25;
}

.brand {
  white-space: nowrap;
  font: bold 17px Georgia, "Times New Roman", serif;
  letter-spacing: 1.1px;
  text-shadow: 1px 1px #071d21;
}

.brand span:last-child {
  color: #d7ca9d;
  font-size: 12px;
  letter-spacing: 2px;
}

.brand-globe {
  display: inline-grid;
  place-items: center;
  width: 23px;
  height: 23px;
  margin-right: 5px;
  border: 1px solid #d7bf77;
  border-radius: 50%;
  color: #d7bf77;
  font: bold 19px serif;
  vertical-align: middle;
}

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

.win-button,
select {
  min-height: 26px;
  padding: 4px 9px;
  color: #18272a;
  background: #dcdcd4;
  border: 2px outset #f5f5ef;
}

.win-button:active { border-style: inset; }
.win-button.is-running { color: #f3e4b8; background: #285b55; }

.speed-label {
  margin-left: 3px;
  color: #d6c797;
  font-size: 9px;
  letter-spacing: 1px;
}

select { min-width: 55px; padding-right: 2px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(530px, 1.58fr) minmax(300px, .62fr);
  gap: 8px;
  min-height: 0;
  padding: 8px;
}

.map-panel,
.sidebar > section {
  min-height: 0;
  background: #d4d4cb;
  border: 2px inset #f2f2ec;
}

.map-panel {
  display: grid;
  grid-template-rows: 25px 27px minmax(0, 1fr) 26px;
  gap: 6px;
  padding: 7px;
}

.map-modes {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  padding: 2px 4px;
  background: #b9bab0;
  border: 1px solid #8d8f88;
  white-space: nowrap;
}

.map-modes > span {
  margin: 0 3px;
  color: #43575a;
  font-size: 8px;
  letter-spacing: 1px;
}

.map-modes .zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 0 0 auto;
  color: inherit;
}

.zoom-button { width: 23px; padding: 1px 4px; font-weight: bold; }
.zoom-level { min-width: 46px; padding-inline: 4px; }

.mode-button {
  min-height: 20px;
  padding: 2px 7px;
  color: #23373a;
  background: #dadad2;
  border: 1px outset #f2f2eb;
  font-size: 9px;
}

.mode-button:active { border-style: inset; }

.mode-button.is-active {
  color: #f2e5bc;
  background: #26565d;
  border-style: inset;
}

.status {
  overflow: hidden;
  padding: 5px 8px 4px;
  color: #f1e6c2;
  background: var(--teal-deep);
  border: 1px solid #61767a;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.map-frame {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #103f53;
  border: 2px inset #6d7069;
  box-shadow: inset 0 0 26px rgba(4,22,27,.5);
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  cursor: grab;
}

.map-frame.is-dragging #map { cursor: grabbing; }

.map-plaque {
  position: absolute;
  top: 9px;
  left: 50%;
  z-index: 2;
  min-width: 210px;
  padding: 5px 10px;
  transform: translateX(-50%);
  color: #efe2b9;
  background: rgba(10,39,43,.9);
  border: 1px solid #c6a75b;
  box-shadow: 2px 2px 0 rgba(15,26,27,.55);
  font: bold 11px Georgia, serif;
  letter-spacing: 1.2px;
  text-align: center;
  pointer-events: none;
}

.map-tooltip {
  position: absolute;
  z-index: 4;
  max-width: 235px;
  padding: 7px 8px;
  color: #f1e5c1;
  background: rgba(8,36,41,.94);
  border: 1px solid #c4a558;
  box-shadow: 3px 3px 0 rgba(12,24,25,.45);
  line-height: 1.45;
  pointer-events: none;
}

.map-tooltip b { color: #e7c875; }

.record-window {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 12;
  display: grid;
  grid-template-rows: 28px minmax(0, 1fr) 39px;
  width: min(465px, calc(100% - 34px));
  max-height: min(470px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  color: #162c30;
  background: #d5d5cd;
  border: 2px outset #f3f3ed;
  box-shadow: 8px 9px 0 rgba(4,20,23,.48);
}

.record-window[hidden] { display: none; }

.record-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 4px 3px 7px;
  color: #f3e8c5;
  background: linear-gradient(90deg, #0b3b44, #276069);
  border-bottom: 1px solid #b4954b;
  font-weight: bold;
  letter-spacing: .8px;
}

.record-titlebar b { color: #e2c568; }

.record-titlebar button {
  width: 21px;
  height: 20px;
  padding: 0;
  color: #18282b;
  background: #d7d7cf;
  border: 2px outset #f5f5ef;
  font: bold 14px Arial, sans-serif;
}

.record-titlebar button:active { border-style: inset; }

.record-body {
  overflow: auto;
  padding: 10px;
  background:
    linear-gradient(rgba(255,255,255,.4), rgba(255,255,255,0) 45px),
    #e8e4d5;
}

.record-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  padding-bottom: 7px;
  border-bottom: 1px solid #aaa48f;
}

.record-heading h2 { margin: 0; color: #173f46; font: bold 21px Georgia, serif; }
.record-heading p { margin: 3px 0 0; color: #5c6564; font-size: 9px; }
.record-stamp { padding: 3px 5px; color: #755c2f; border: 1px solid #a98e52; font-size: 8px; white-space: nowrap; }

.record-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.record-field { min-width: 0; padding: 5px 6px; background: #f5f1df; border: 1px solid #bbb6a4; }
.record-field small { display: block; color: #697171; font-size: 7px; letter-spacing: .8px; }
.record-field b { display: block; overflow: hidden; margin-top: 2px; color: #173f46; text-overflow: ellipsis; }
.record-section { margin-top: 9px; padding: 7px 8px; color: #e8dec0; background: #173940; border: 1px inset #617476; line-height: 1.45; }
.record-section strong { color: #d7b95f; }
.record-history { margin: 4px 0 0; padding-left: 16px; }
.record-history li { margin-top: 4px; }

.record-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px 8px;
  background: #c7c7bf;
  border-top: 1px solid #92948d;
}

.legend {
  display: flex;
  align-items: center;
  gap: 5px 11px;
  overflow: hidden;
  padding: 3px 6px;
  color: #263b3e;
  white-space: nowrap;
  font-size: 9px;
}

.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; background: var(--key); border: 1px solid #3e4947; }
.legend b { width: 12px; text-align: center; }
.mountain-key { color: #655b4d; }
.river-key { color: #26718d; }
.city-key { color: #7e2724; }
.border-key { color: #80513d; }

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(145px, .85fr) minmax(165px, 1fr);
  gap: 8px;
  min-height: 0;
}

.sidebar > section {
  display: flex;
  flex-direction: column;
  padding: 7px;
}

.panel-heading {
  margin: -1px -1px 7px;
  padding: 4px 7px;
  color: #eee2bd;
  background: #16434a;
  border-bottom: 1px solid #a98a47;
  font-weight: bold;
  letter-spacing: 1.2px;
}

.world-title {
  margin-bottom: 7px;
  color: #1b4448;
  font: bold 18px Georgia, serif;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.stat {
  min-width: 0;
  padding: 5px 6px;
  background: #ece8d9;
  border: 1px solid #9b9b91;
  box-shadow: inset 1px 1px #fff;
  color: #536063;
  font-size: 7px;
}

.stat b {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: #153e46;
  font-size: 13px;
  text-overflow: ellipsis;
}

.chronicle,
.societies {
  min-height: 0;
  overflow: auto;
  scrollbar-color: #777 #d3d3ca;
}

.chronicle {
  flex: 1;
  padding: 8px;
  color: #e7ddbd;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 3px),
    #112f35;
  border: 2px inset #606966;
  line-height: 1.45;
}

.entry {
  margin: 0 0 8px;
  padding: 0 0 8px 10px;
  border-bottom: 1px dotted #526667;
  position: relative;
}

.entry::before {
  position: absolute;
  left: 0;
  top: 3px;
  color: #c8a75b;
  content: "›";
}

.entry .turn {
  color: #d6b562;
  font-size: 9px;
}

.societies { flex: 1; }

.society {
  margin-bottom: 5px;
  padding: 6px 7px;
  background: #ece8d9;
  border: 1px solid #96978f;
  box-shadow: inset 1px 1px #fff;
  cursor: pointer;
}

.society.is-selected {
  background: #fff3c8;
  outline: 2px solid #826933;
}

.society header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: bold;
}

.society-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.society small { display: block; margin-top: 4px; color: #526064; font-size: 9px; }
.swatch { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border: 1px solid #363b3a; }

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow: hidden;
  padding: 5px 9px;
  color: #dfd5b3;
  background: #12343b;
  border-top: 1px solid #4d6768;
  white-space: nowrap;
  font-size: 9px;
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: minmax(520px, 1fr) 300px; }
  .brand span:last-child { display: none; }
  .legend { gap: 4px 7px; }
}
