/* Chwezland: 8-bit styling. Chunky borders, pixel font, a limited palette. */

/* The pixel font, served from our own server (Discord Activities can't load Google Fonts).
   Press Start 2P, SIL Open Font License (see fonts/OFL.txt). */
@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/press-start-2p-latin.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/press-start-2p-latin-ext.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  --black: #000000;
  --navy: #1d2b53;
  --plum: #7e2553;
  --forest: #008751;
  --brown: #ab5236;
  --stone: #5f574f;
  --silver: #c2c3c7;
  --cream: #fff1e8;
  --red: #ff004d;
  --orange: #ffa300;
  --yellow: #ffec27;
  --green: #00e436;
  --sky: #29adff;
  --peach: #ffccaa;
  --pink: #ff77a8;
  --font: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--black);
  color: var(--cream);
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.8;
  image-rendering: pixelated;
}

/* ── HUD ─────────────────────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--navy);
  border-bottom: 4px solid var(--cream);
}
.hud-title { font-size: 14px; color: var(--yellow); text-shadow: 2px 2px 0 var(--plum); letter-spacing: 2px; }
.hud-stats { display: flex; gap: 20px; justify-content: flex-end; }

/* The Discord server (realm) you're playing in, centered in the HUD */
.hud-realm {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  background: var(--black);
  border: 3px solid var(--cream);
  box-shadow: 3px 3px 0 var(--plum);
  max-width: 40vw;
}
.realm-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--plum) center / cover no-repeat;
  border: 2px solid var(--stone);
  color: var(--yellow);
  font-size: 12px;
  image-rendering: pixelated;
}
.realm-text { display: flex; flex-direction: column; line-height: 1.5; min-width: 0; }
.realm-label { font-size: 7px; color: var(--silver); }
.realm-text b { font-weight: normal; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 700px) {
  .hud { grid-template-columns: 1fr; justify-items: center; }
  .hud-stats { justify-content: center; }
  .hud-realm { max-width: 90vw; }
}
.hud-stats b { color: var(--yellow); font-weight: normal; }

/* ── Town ────────────────────────────────────────────────────────────── */
.town-wrap { display: flex; justify-content: center; padding: 16px; }
.town {
  position: relative;
  width: min(100%, calc((100vh - 140px) * 16 / 9), 1280px);
  aspect-ratio: 16 / 9;
  border: 4px solid var(--cream);
  box-shadow: 0 0 0 4px var(--black), 0 0 0 8px var(--stone);
}
#town-canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

.hotspot {
  position: absolute;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}
.hotspot:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 2px; }
.hotspot-label {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -4px);
  white-space: nowrap;
  padding: 4px 6px;
  background: var(--navy);
  border: 2px solid var(--cream);
  color: var(--yellow);
  font-size: 8px;
  pointer-events: none;
  opacity: 0;
}
.hotspot:hover .hotspot-label, .hotspot:focus-visible .hotspot-label { opacity: 1; }

.town-tip {
  position: absolute;
  left: 50%;
  top: 6px; /* The War Room tent sits along the bottom */
  transform: translateX(-50%);
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 8px;
  pointer-events: none;
  animation: blink 1.2s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.footer { text-align: center; color: var(--stone); font-size: 8px; padding-bottom: 12px; }

/* ── Window (classic RPG dialog box) ─────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.hidden { display: none !important; }

.window {
  width: min(760px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--navy);
  border: 4px solid var(--cream);
  box-shadow: 0 0 0 4px var(--black), 8px 8px 0 4px var(--black);
  animation: pop 0.12s steps(3);
}
@keyframes pop { from { transform: scale(0.9); } to { transform: scale(1); } }

.window-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 4px solid var(--cream);
  background: var(--plum);
}
.window-head h2 { margin: 0; font-size: 12px; color: var(--yellow); font-weight: normal; }
.window-body { padding: 14px; overflow-y: auto; }

h3 { font-size: 10px; color: var(--yellow); font-weight: normal; margin: 18px 0 8px; }
h3:first-child { margin-top: 0; }
p { margin: 6px 0; }
.muted { color: var(--silver); }
.small { font-size: 8px; }
.gold { color: var(--yellow); }
.good { color: var(--green); }
.bad { color: var(--red); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--font);
  font-size: 9px;
  padding: 8px 10px;
  color: var(--black);
  background: var(--cream);
  border: none;
  box-shadow: inset -3px -3px 0 var(--silver), 0 0 0 2px var(--black);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--yellow); }
.btn:active:not(:disabled) { box-shadow: inset 3px 3px 0 var(--silver), 0 0 0 2px var(--black); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--green); box-shadow: inset -3px -3px 0 var(--forest), 0 0 0 2px var(--black); }
.btn-danger { background: var(--red); color: var(--cream); box-shadow: inset -3px -3px 0 var(--plum), 0 0 0 2px var(--black); }
.btn-danger:hover:not(:disabled) { background: var(--orange); color: var(--black); }

/* Tabs (tavern: notice board / recruits) */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 3px solid var(--cream); }
.tab {
  font-family: var(--font);
  font-size: 9px;
  padding: 8px 12px;
  background: var(--black);
  color: var(--silver);
  border: 3px solid var(--stone);
  border-bottom: none;
  cursor: pointer;
  margin-bottom: -3px;
}
.tab.active { background: var(--navy); color: var(--yellow); border-color: var(--cream); }
.tab:hover:not(.active) { color: var(--cream); }

.trait { color: var(--pink); }

/* Gear rarity colors */
.rarity-common .item-name { color: var(--silver); }
.rarity-uncommon .item-name { color: var(--green); }
.rarity-rare .item-name { color: var(--sky); }
.rarity-epic .item-name { color: var(--pink); }
.loot-card.rarity-rare { border-color: var(--sky); }
.loot-card.rarity-epic { border-color: var(--pink); box-shadow: 0 0 0 2px var(--plum); }
.gear-row { padding: 8px; border-bottom: 2px dashed var(--stone); }
/* Loot comparison: what each eligible hero wears now, and the Power change */
.compare { margin: 8px 0; border-top: 2px dashed var(--stone); padding-top: 6px; }
.compare-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; padding: 3px 0; }
.compare-row .current { grid-column: 1 / -1; overflow-wrap: anywhere; }
.compare-row .name { color: var(--yellow); overflow-wrap: anywhere; }
.delta-up { color: var(--green); }
.delta-down { color: var(--red); }
.btn .delta-up, .btn .delta-down { color: inherit; font-weight: bold; }
.gear-row .btn { font-size: 8px; padding: 6px 8px; }

/* Admin page */
.admin { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px; }
.admin-window { width: min(1100px, 100%); max-height: none; }
.admin .card.retired { opacity: 0.5; border-style: dashed; }
.admin-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.admin-form label { display: flex; flex-direction: column; gap: 6px; font-size: 8px; color: var(--silver); }
.admin-form .wide { grid-column: 1 / -1; }
.admin-form .check { flex-direction: row; align-items: center; gap: 8px; }
.admin-form input[type='text'], .admin-form input[type='number'], .admin-form select {
  font-family: var(--font);
  font-size: 10px;
  padding: 8px;
  background: var(--black);
  color: var(--cream);
  border: 3px solid var(--cream);
  width: 100%;
  max-width: none;
}
.admin-form input:focus, .admin-form select:focus { outline: none; border-color: var(--yellow); }
a.btn { text-decoration: none; display: inline-block; }
.footer a { color: var(--silver); }
.recruit .btn { margin-top: 6px; }
.recruit.hired { opacity: 0.55; }
.hired-stamp { border-color: var(--green); color: var(--green); margin-top: 6px; }

.btn-close { padding: 4px 8px; background: var(--red); color: var(--cream); box-shadow: inset -3px -3px 0 var(--plum), 0 0 0 2px var(--black); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ── Bars ────────────────────────────────────────────────────────────── */
.bar {
  display: block;
  height: 10px;
  background: var(--black);
  border: 2px solid var(--cream);
  margin: 4px 0;
}
.bar > span { display: block; height: 100%; background: var(--green); }
.bar.renown > span { background: var(--orange); }
.bar.guild > span { background: var(--yellow); }
input[type='number'] { font-family: var(--font); font-size: 10px; padding: 8px; background: var(--black); color: var(--cream); border: 3px solid var(--cream); width: 120px; }

/* ── Cards (contracts, heroes, upgrades) ─────────────────────────────── */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.card {
  background: var(--black);
  color: var(--cream);
  border: 3px solid var(--silver);
  padding: 10px;
}
/* Buttons don't inherit font or spacing by default; make card-buttons match */
button.card { font-family: var(--font); font-size: inherit; line-height: 1.8; text-align: left; width: 100%; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--yellow); }
.card.selected { border-color: var(--green); background: #002a18; }
.card.disabled { opacity: 0.45; cursor: not-allowed; }

/* Contract notices look like parchment pinned to the board */
.notice {
  background: var(--peach);
  color: var(--black);
  border: 3px solid var(--brown);
  box-shadow: 4px 4px 0 var(--black);
  position: relative;
}
.notice::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--red);
  box-shadow: 0 0 0 2px var(--black);
  transform: translateX(-50%);
}
.notice.clickable:hover { border-color: var(--plum); background: var(--cream); }
.notice.guided { border-color: var(--green); box-shadow: 4px 4px 0 var(--black), 0 0 0 3px var(--yellow); }
.guided-stamp { border-color: var(--forest); color: var(--forest); margin-bottom: 6px; }
.notice.taken { opacity: 0.5; filter: grayscale(1); cursor: default; text-align: center; }
.notice .title { color: var(--plum); font-size: 9px; margin-bottom: 6px; }
.notice .flavor { font-size: 8px; color: var(--stone); margin-bottom: 8px; }
.notice .stats { font-size: 8px; }
.stamp {
  display: inline-block;
  padding: 2px 6px;
  border: 2px solid var(--red);
  color: var(--red);
  transform: rotate(-6deg);
  font-size: 8px;
}

.hero-card { display: flex; gap: 10px; align-items: center; }
.hero-card .info { flex: 1; min-width: 0; }
.hero-card .name { color: var(--yellow); overflow-wrap: anywhere; }
.portrait { image-rendering: pixelated; flex-shrink: 0; background: var(--navy); border: 2px solid var(--stone); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--black); border: 3px solid var(--stone); padding: 8px; }
.stat .label { font-size: 8px; color: var(--silver); }
.stat .value { font-size: 12px; color: var(--yellow); }

.list-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px; border-bottom: 2px dashed var(--stone); }
.list-row:last-child { border-bottom: none; }
.you { color: var(--green); }

/* ── Forms ───────────────────────────────────────────────────────────── */
input[type='text'] {
  font-family: var(--font);
  font-size: 10px;
  padding: 8px;
  background: var(--black);
  color: var(--cream);
  border: 3px solid var(--cream);
  width: 100%;
  max-width: 340px;
}
input[type='text']:focus { outline: none; border-color: var(--yellow); }

/* ── Results & toast ─────────────────────────────────────────────────── */
.result { text-align: center; padding: 10px; margin-bottom: 12px; border: 3px solid var(--cream); background: var(--black); }
.result .big { font-size: 14px; margin: 8px 0; }
.result.triumph .big { color: var(--yellow); animation: blink 0.5s steps(1) 6; }
.result.success .big { color: var(--green); }
.result.scraped .big { color: var(--orange); }

.result.failure .big { color: var(--red); }

/* ── Titles & trophies ───────────────────────────────────────────────── */
.hero-title { color: var(--orange); }
.trophy { border-color: var(--stone); }
.trophy .title { color: var(--silver); margin-bottom: 6px; }
.trophy.won { border-color: var(--yellow); }
.trophy.won .title { color: var(--yellow); }
.trophy.locked { opacity: 0.5; border-style: dashed; }

/* ── War Room ────────────────────────────────────────────────────────── */
.raid-card { position: relative; border-color: var(--plum); }
.raid-card .title { color: var(--yellow); margin-bottom: 6px; }
.raid-card.mine { border-color: var(--green); }
.you-stamp { position: absolute; top: 6px; right: 6px; border-color: var(--green); color: var(--green); }
.card .title { overflow-wrap: anywhere; }
.card:not(.notice) .flavor { font-size: 8px; color: var(--silver); margin: 4px 0; }
.raid-head { margin: 14px 0; }
button.clickable-row {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 2px dashed var(--stone);
  color: var(--cream);
  font-family: var(--font);
  font-size: inherit;
  text-align: left;
  line-height: 1.8;
  cursor: pointer;
}
button.clickable-row:hover { background: var(--navy); }
.meters { grid-template-columns: 1fr; }
.meter-row { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr auto; gap: 8px; align-items: center; padding: 4px 0; }
.meter-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-row.you > span:first-child { color: var(--green); }
.bar.meter { margin: 0; }
.bar.meter > span { background: var(--orange); }
.meter-row.you .bar.meter > span { background: var(--green); }
.battle-log { max-height: 320px; overflow-y: auto; background: var(--black); border: 3px solid var(--stone); padding: 8px; font-size: 8px; line-height: 2; }
.log-line.key { color: var(--yellow); }
.log-line.tease { color: var(--pink); }


.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(600px, 90vw);
  padding: 10px 14px;
  background: var(--navy);
  border: 3px solid var(--cream);
  box-shadow: 4px 4px 0 var(--black);
  z-index: 20;
  font-size: 9px;
}
.toast.error { border-color: var(--red); }

/* ── Beta ────────────────────────────────────────────────────────────── */
.beta-badge { font-size: 7px; color: var(--black); background: var(--orange); padding: 2px 4px; vertical-align: middle; text-shadow: none; letter-spacing: 0; }
.feedback-bar { display: flex; justify-content: center; padding: 0 16px 12px; }
.btn-feedback { font-size: 8px; }
textarea {
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.8;
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: var(--black);
  color: var(--cream);
  border: 3px solid var(--cream);
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--yellow); }
.gate-window .start-form { text-align: left; }
.gate-window:has(.start-form) { width: min(760px, 100%); max-height: calc(100vh - 32px); }
.start-form .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 10px; }

/* ── Signing in (Discord Activity) ───────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
}
.gate-window { width: min(460px, 100%); text-align: center; }
.gate-window .btn-row { justify-content: center; }

/* ── Touch screens: building names always showing (there's no hover) ── */
@media (hover: none) {
  .hotspot-label { opacity: 0.9; font-size: 6px; padding: 2px 4px; }
}

/* ── Phones (Discord mobile): the town fills the width, menus become full-screen sheets ── */
@media (max-width: 600px) {
  html, body { font-size: 9px; }
  .hud { padding: 6px 8px; gap: 6px; }
  .hud-title { font-size: 11px; }
  .hud-stats { gap: 12px; }
  .town-wrap { padding: 6px 0; }
  .town { width: 100%; border-width: 3px; box-shadow: none; }
  .town-tip { white-space: nowrap; font-size: 6px; padding: 2px 6px; }
  .overlay { padding: 0; align-items: stretch; }
  .window { width: 100%; max-height: 100dvh; height: 100dvh; border-width: 3px; box-shadow: none; }
  .window-body { padding: 10px; }
  .window-head { position: sticky; top: 0; z-index: 1; }
  .btn { padding: 10px 12px; min-height: 36px; } /* Bigger tap targets */
  .btn-close { min-width: 40px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tab { white-space: nowrap; flex-shrink: 0; }
  .grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .meter-row { grid-template-columns: minmax(0, 1fr) 70px auto; gap: 6px; }
  .hero-card { align-items: flex-start; }
  input[type='text'], input[type='number'], textarea { font-size: 16px; } /* Stops phones zooming in on tap */
}
