/* Tokenheim viewer — game-client chrome with readable type */

@import url("https://fonts.googleapis.com/css2?family=Jersey+10&family=Jersey+15&family=Jersey+25&display=swap");

:root {
  --void: #16110d;
  --stone: #5a4a36;
  --stone-mid: #7a6548;
  --stone-light: #a08860;
  --stone-dark: #2e2418;
  --copper: #c4924a;
  --copper-dark: #8a6230;
  --copper-light: #e8c482;
  --wood: #3a2c20;
  --wood-mid: #4e3c2a;
  --wood-light: #6a5238;
  --wood-dark: #241810;
  --beige: #d2bc8a;
  --beige-light: #e8d6a8;
  --beige-dark: #a89058;
  --ink: #1a1208;
  --text: #f2e6c8;
  --mute: #c4b090;
  --yellow: #ffe566;
  --orange: #ff9a3c;
  --live: #3fbf8a;
  --world: #0c0a08;
  --font: "Jersey 15", "Jersey 10", "Courier New", monospace;
  --display: "Jersey 25", "Jersey 15", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }

html:has(body.viewer),
body.viewer {
  overflow: hidden;
  overscroll-behavior: none;
}

body.viewer {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.25;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(196, 146, 74, 0.14), transparent 55%),
    linear-gradient(180deg, #1c1510, var(--void));
  -webkit-font-smoothing: antialiased;
}

body.desk-open { overflow: hidden; }

button, input { font: inherit; }

.app {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

/* —— Top bar —— */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.logo__mark {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex: 0 0 auto;
}

.logo__word {
  font-family: var(--display);
  font-size: clamp(28px, 3.2vw, 34px);
  line-height: 1;
  color: var(--yellow);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.85);
  letter-spacing: 0.02em;
}

.auth-actions { display: flex; gap: 6px; }

.btn {
  appearance: none;
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  background:
    linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
  color: var(--yellow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
  padding: 5px 12px;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(232, 196, 130, 0.12),
    2px 2px 0 rgba(0, 0, 0, 0.35);
}

.btn:hover { filter: brightness(1.1); }

.btn--accent,
.btn.is-active {
  background: linear-gradient(180deg, var(--copper-light), var(--copper) 50%, var(--copper-dark));
  color: var(--ink);
  text-shadow: none;
  border-color: #e0c078 #5a3c18 #5a3c18 #e0c078;
}

/* —— Panel chrome: stacked moldings + large true-pixel corner flourishes —— */

.frame {
  position: relative;
  height: 100%;
  min-height: 0;
  padding: 8px;
  background: #2a1c12;
  border: 3px solid #120c08;
  box-shadow:
    0 0 0 1px #6a4a28,
    3px 3px 0 rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px #e8c482,
    inset 0 0 0 2px #b88848,
    inset 0 0 0 4px #6a4828,
    inset 0 0 0 5px #1a120c,
    inset 0 0 0 7px #3a2818;
  overflow: hidden;
}

.frame__corner {
  position: absolute;
  width: 32px;
  height: 32px;
  background: url("/art/frame-corner-16.png") 0 0 / 32px 32px no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 4;
  pointer-events: none;
}

.frame__corner--tl { top: 2px; left: 2px; }
.frame__corner--tr { top: 2px; right: 2px; transform: scaleX(-1); }
.frame__corner--bl { bottom: 2px; left: 2px; transform: scaleY(-1); }
.frame__corner--br { bottom: 2px; right: 2px; transform: scale(-1); }

.frame__well {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  padding: 5px;
  background:
    repeating-linear-gradient(
      90deg,
      var(--wood-dark) 0 2px,
      var(--wood) 2px 5px,
      var(--wood-mid) 5px 7px,
      var(--wood) 7px 11px
    );
  border: 2px solid #120c08;
  box-shadow:
    inset 2px 2px 0 rgba(0, 0, 0, 0.45),
    inset -1px -1px 0 rgba(232, 196, 130, 0.1);
  overflow: hidden;
}

.frame__well--stack {
  grid-template-rows: auto minmax(0, 1fr);
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  background:
    linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  border-style: solid;
  border-width: 1px;
  border-color: var(--stone-dark) var(--stone-light) var(--stone-light) var(--stone-dark);
  box-shadow: inset 1px 1px 0 rgba(255, 220, 160, 0.1);
  color: var(--mute);
}

.status h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 400;
  color: var(--yellow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
}

.icon-btn {
  appearance: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  color: var(--yellow);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover { filter: brightness(1.12); }
.icon-btn svg { width: 12px; height: 12px; display: block; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}

.live i {
  width: 8px;
  height: 8px;
  background: #3fbf8a;
  box-shadow: 1px 1px 0 #000;
  flex: 0 0 auto;
}

.live.is-offline {
  color: var(--mute);
}

.live.is-offline i {
  background: #6a5a48;
}

/* Stage */

.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(250px, 26vw, 330px);
  gap: 8px;
  overflow: hidden;
}

.world, .minimap, .ledger, .side {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.world__canvas,
.minimap__view {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--world);
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-dark) var(--copper-dark) var(--copper-dark) var(--stone-dark);
  box-shadow:
    inset 3px 3px 0 rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(196, 146, 74, 0.15);
}

/* Waiting grid is a canvas of discrete solid-hue segments (see viewer.js) */
.world__grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.world__canvas.is-waiting .world__grid {
  display: block;
}

.world__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  z-index: 1;
}

.world__label {
  margin: 0;
  color: var(--yellow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
}

.world__sub {
  margin: 0;
  color: var(--mute);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
}

.side {
  display: grid;
  grid-template-rows: clamp(150px, 27%, 200px) minmax(0, 1fr);
  gap: 8px;
}

.map-art {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(196, 146, 74, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(196, 146, 74, 0.12) 1px, transparent 1px),
    linear-gradient(135deg, #1c1810 25%, #0a0806 25% 50%, #242018 50% 75%, #0a0806 75%);
  background-size: 16px 16px, 16px 16px, 32px 32px;
  image-rendering: pixelated;
}

.map-art--large { background-size: 16px 16px, 16px 16px, 32px 32px; }

.map-cursor {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  background: var(--yellow);
  box-shadow: 0 0 0 1px #000;
}

.map-cursor--large {
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
}

/* Icon tabs */

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  padding: 4px;
  background:
    linear-gradient(180deg, #2a1e14, var(--wood-dark));
  border-bottom: 1px solid var(--stone-dark);
  box-shadow: inset 0 -1px 0 rgba(232, 196, 130, 0.1);
}

.tab {
  appearance: none;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  cursor: pointer;
  padding: 0;
}

.tab__icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  opacity: 0.85;
}

.tab:hover {
  filter: brightness(1.08);
}

.tab:hover .tab__icon {
  opacity: 1;
}

.tab.is-active {
  background: linear-gradient(180deg, var(--copper-light), var(--copper) 55%, var(--copper-dark));
  border-color: #e0c078 #5a3c18 #5a3c18 #e0c078;
  box-shadow: inset 1px 1px 0 rgba(255, 245, 200, 0.35);
}

.tab.is-active .tab__icon {
  opacity: 1;
}

.panel {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(80, 55, 25, 0.05) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, var(--beige-light), var(--beige));
  border-style: solid;
  border-width: 2px;
  border-color: var(--beige-dark) var(--beige-light) var(--beige-light) var(--beige-dark);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 210, 0.35);
}

.panel__pane h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 400;
  color: #4a3010;
}

.panel__lede {
  margin: 0 0 10px;
  color: #5a4020;
  font-size: 17px;
}

.panel__empty {
  padding: 8px 10px;
  border-style: solid;
  border-width: 1px;
  border-color: var(--beige-dark) var(--beige-light) var(--beige-light) var(--beige-dark);
  background: rgba(168, 144, 88, 0.35);
  color: #3a2810;
  box-shadow: inset 1px 1px 0 rgba(255, 245, 210, 0.35);
}

.panel__check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  color: var(--ink);
}

.panel__check input { accent-color: var(--copper-dark); }

/* Windows */

.desk[hidden] { display: none !important; }
.desk { position: fixed; inset: 0; z-index: 50; }

.desk__dim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(8, 5, 3, 0.7);
}

.win[hidden] { display: none !important; }

.win {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 300px;
  max-width: min(920px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: #2a1c12;
  border: 3px solid #120c08;
  box-shadow:
    0 0 0 1px #6a4a28,
    4px 4px 0 rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px #e8c482,
    inset 0 0 0 2px #b88848,
    inset 0 0 0 4px #6a4828,
    inset 0 0 0 5px #1a120c,
    inset 0 0 0 7px #3a2818;
  z-index: 2;
  overflow: hidden;
}

#win-map {
  width: min(860px, calc(100vw - 24px));
  height: min(620px, calc(100dvh - 24px));
}

#win-auth { width: min(400px, calc(100vw - 24px)); }

.win__bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 4px 10px;
  margin-bottom: 4px;
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  border-style: solid;
  border-width: 1px;
  border-color: var(--stone-dark) var(--stone-light) var(--stone-light) var(--stone-dark);
  cursor: default;
  user-select: none;
}

.win__title {
  font-size: 18px;
  color: var(--yellow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win__close {
  appearance: none;
  width: 26px;
  height: 22px;
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  background: linear-gradient(180deg, #8a5a40, #4a2818);
  color: var(--yellow);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
}

.win__close:hover {
  background: linear-gradient(180deg, #c45a40, #8a3020);
}

.win__body {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--wood);
  border-style: solid;
  border-width: 2px;
  border-color: var(--stone-dark) var(--stone-light) var(--stone-light) var(--stone-dark);
}

.win__body--map {
  overflow: hidden;
  background: var(--world);
}

.win__foot {
  margin-top: 4px;
  padding: 4px 8px;
  background: linear-gradient(180deg, var(--wood-mid), var(--wood-dark));
  border-style: solid;
  border-width: 1px;
  border-color: var(--stone-dark) var(--stone-light) var(--stone-light) var(--stone-dark);
  color: var(--mute);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}

.win__body--form {
  padding: 14px;
  display: grid;
  gap: 8px;
  align-content: start;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(80, 55, 25, 0.05) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, var(--beige-light), var(--beige));
}

.win__body--form h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  color: #4a3010;
}

.auth__sub { margin: 0; color: #5a4020; }
.auth__modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.auth__form { display: grid; gap: 8px; }
.auth__form[hidden] { display: none !important; }

.auth__form label {
  display: grid;
  gap: 2px;
  color: #5a4020;
}

.auth__form input {
  width: 100%;
  border-style: solid;
  border-width: 2px;
  border-color: var(--beige-dark) var(--beige-light) var(--beige-light) var(--beige-dark);
  background: #f3e6c4;
  color: var(--ink);
  padding: 6px 8px;
  outline: none;
}

.auth__form input:focus {
  border-color: var(--copper-dark);
  background: #fff6d8;
}

.win__actions { display: flex; justify-content: flex-end; gap: 8px; }
.auth__note { margin: 0; color: #5a4020; }

body.admin {
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  background: var(--void);
}

body.admin .shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(2rem, 6vw, 4rem);
  max-width: 42rem;
}

body.admin .brand {
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 34px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.85);
}

body.admin .brand::before {
  content: "";
  width: 32px;
  height: 32px;
  background: url("/logo.png") center / 32px 32px no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body.admin h1 {
  margin: 0 0 0.5rem;
  font-size: 22px;
  font-weight: 400;
  color: var(--yellow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.85);
}

body.admin .lede {
  margin: 0;
  color: var(--mute);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}

body.admin .meta { margin: 2rem 0 0; color: var(--mute); }
body.admin .meta a {
  color: var(--orange);
  text-decoration: none;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}

@media (max-width: 820px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr);
  }
  .side {
    grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
    grid-template-rows: 1fr;
  }
  #win-map {
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
  }
}
