:root {
  --bg: #1c1a17;
  --panel: #2b2722;
  --panel-border: #4a4238;
  --text: #d8d0c0;
  --muted: #8f8677;
  --accent: #c8a45a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
#app {
  display: grid;
  grid-template-columns: 1fr 240px;
  height: 100vh;
}
#gamewrap {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: #000;
}
#game {
  /* flex-basis 0 so the backing store's own size never feeds back into layout: the
     renderer sizes it from this element, in device pixels, and letterboxes itself. */
  flex: 1 1 0;
  display: block;
  width: 100%; min-height: 0;
  cursor: crosshair;
  outline: none;
  background: #000;
}
#console {
  height: 150px; flex: 0 0 auto;
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 2px solid var(--panel-border);
}
#log {
  flex: 1; overflow-y: auto; padding: 4px 8px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
}
/* The arrival time on every line: quiet, so the words stay the loudest
   thing on the line. */
#log .ts { color: #7a746a; font-size: 11px; }
#log .say { color: #f0d060; }
#log .server { color: #dcdcdc; }
/* World news — arrivals, departures, deaths, level-ups — reads apart from
   messages addressed to you. */
#log .event { color: #8fb8d8; font-style: italic; }
#log .loot { color: #7ed77e; }
#log .level { color: #ff8; font-weight: bold; }
#log .error { color: #f66; }
/* The way between levels is blocked: a state of the world rather than a
   mistake of yours, so it gets its own colour between the two. */
#log .blocked { color: #f09a5a; }
/* Noises — eating, and whatever else gets a sound — in Tibia's
   creature-sound orange, apart from the yellow of words. */
#log .noise { color: #ffae42; }
/* The minimap's level peek: small arrows in the panel title, and the
   viewed level named beside them while it is not your own. */
#maplevelctl { float: right; }
#maplevelctl button {
  background: #201c17; color: var(--text); border: 1px solid var(--panel-border);
  padding: 0 6px; margin-left: 2px; cursor: pointer; font-size: 10px; line-height: 16px;
}
#maplevelctl button:hover { border-color: var(--accent); }
#maplevel { color: var(--accent); margin-left: 6px; font-size: 11px; }
#log .own { color: #ffe9a0; }
#chat {
  border: 0; border-top: 1px solid var(--panel-border);
  background: #16140f; color: var(--text); padding: 6px 8px; font: inherit; outline: none;
}
#chat:focus { background: #221f18; }

#side {
  background: var(--panel); border-left: 2px solid var(--panel-border);
  overflow-y: auto; padding: 6px;
  display: flex; flex-direction: column; gap: 6px;
}
.panel {
  background: #201d19; border: 1px solid var(--panel-border);
  padding: 6px; border-radius: 3px;
}
.panel .title { font-weight: bold; color: var(--accent); margin-bottom: 4px; }
.panel .title small { color: var(--muted); font-weight: normal; }
.row { display: flex; justify-content: space-between; margin-top: 3px; }
.row b.hungry { color: #e66; }
.bar {
  position: relative; height: 14px; background: #111; border: 1px solid #000;
  margin: 3px 0; overflow: hidden;
}
.bar > div { height: 100%; width: 0; transition: width .15s; }
.bar.hp > div { background: linear-gradient(#e33, #900); }
.bar.food > div { background: linear-gradient(#c98a3a, #7a4d18); }
.bar.food.empty > div { background: linear-gradient(#6a3030, #3a1a1a); }
.bar.xp > div { background: linear-gradient(#69d, #236); }
.bar span {
  position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 14px;
  color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000;
}
/* Shown only while the player stands on safe ground. */
/* Statuses share one line. The row hands the whole remaining width to the
   value so it can be measured for overflow: the labels are shortened until
   they fit rather than wrapping or being cut off. */
.row.statuses { align-items: baseline; gap: 6px; }
#statuses {
  flex: 1 1 auto; min-width: 0; overflow: hidden;
  display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap;
}
#statuses .status {
  padding: 0 3px; border: 1px solid #3a4048; border-radius: 2px;
  font-size: 10px; font-weight: bold; letter-spacing: .5px; color: #b9c2cc;
}
#statuses .status.good { border-color: #4a6a8c; color: #9cc4ee; }
#statuses .status.warn { border-color: #8c7a3a; color: #e0c46a; }
#statuses .status.bad { border-color: #8c4a4a; color: #e88; }
#statuses .status.icon { border: 0; padding: 0; font-size: 12px; letter-spacing: 0; }
#statuses .none { color: #666; font-size: 11px; }

/* Skills: a name, a thin bar of progress to the next level, and the level. */
.skillstitle { margin-top: 6px; font-size: 12px; }
#skills .skill {
  display: grid; grid-template-columns: 5.2em 1fr 2em; align-items: center; gap: 6px;
  margin-top: 2px; font-size: 12px;
}
#skills .skill span { color: var(--muted); text-transform: capitalize; }
#skills .skill b { text-align: right; }
#skills .skillbar { height: 6px; background: #111; border: 1px solid #000; overflow: hidden; }
#skills .skillbar > div { height: 100%; width: 0; background: linear-gradient(#9c7, #463); transition: width .15s; }

#inv, #depot {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
}
#inv .slot, #depot .slot {
  aspect-ratio: 1; background: #111; border: 1px solid #3a342c;
  display: flex; align-items: center; justify-content: center; position: relative;
  cursor: pointer;
}
/* A touch long-press is the right-click, so the browser's own answers to a
   held finger — iOS's magnifier and callout, text selection, double-tap
   zoom — must stand aside on everything that takes one. */
#game, #minimap, #inv .slot, #depot .slot {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
#inv .slot:hover, #depot .slot:hover { border-color: var(--accent); }
/* The weapon and armor the server is actually fighting with. */
#inv .slot.equipped { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(200, 164, 90, .5); }
#inv .slot canvas { width: 32px; height: 32px; image-rendering: pixelated; }
#inv .slot .count, #depot .slot .count {
  position: absolute; right: 2px; bottom: 0; font-size: 10px; color: #fff; text-shadow: 0 0 2px #000;
}
#minimap { width: 100%; image-rendering: pixelated; border: 1px solid #000; cursor: pointer; }

#buttons { display: flex; flex-wrap: wrap; gap: 4px; }
#buttons button {
  flex: 1 1 auto;
  background: #16140f; color: var(--accent); border: 1px solid var(--panel-border);
  padding: 5px 10px; font: inherit; font-weight: bold; border-radius: 2px; cursor: pointer;
}
#buttons button:hover, #buttons button:focus-visible { border-color: var(--accent); background: #221f18; }
/* PvP on is the state worth noticing, so the button goes red for it. */
#buttons button.on { border-color: #8c4a4a; color: #e88; }
#buttons button.on:hover, #buttons button.on:focus-visible { border-color: #e88; }
/* Logging out is refused while something is after you; say so by feel. */
#buttons button:disabled { color: var(--muted); cursor: not-allowed; opacity: .55; }
#buttons button:disabled:hover { border-color: var(--panel-border); background: #16140f; }

#help, #scores, #login {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
}
#help[hidden], #scores[hidden], #login[hidden] { display: none; }
#help, #scores { z-index: 10; }
#helpbox {
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 4px;
  padding: 18px 22px; max-width: 460px; max-height: 85vh; overflow-y: auto;
}
#helpbox h2 { margin: 0 0 10px; color: var(--accent); font-size: 20px; letter-spacing: 1px; }
/* Each section of the help has its own heading and its own key/value list,
   so the controls can be found without reading how the game works. */
#helpbox h3 {
  margin: 12px 0 6px; padding-bottom: 3px; border-bottom: 1px solid var(--panel-border);
  color: var(--accent); font-size: 14px; letter-spacing: 1px; text-transform: uppercase;
}
#helpbox h2 + h3 { margin-top: 0; }
#helpbox dl {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 14px;
  margin: 0; font-size: 12px;
}
#helpbox dt { color: var(--accent); white-space: nowrap; }
#helpbox dd { margin: 0; color: var(--muted); }
#helpclose, #scoresclose {
  display: block; width: 100%; margin-top: 14px;
  background: var(--accent); color: #221; border: 0; padding: 7px;
  font: inherit; font-weight: bold; cursor: pointer;
}
/* The highscores: one small table per board — level, then each skill —
   flowing side by side as the width allows. */
#scoresbox {
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 4px;
  padding: 18px 22px; max-width: 640px; max-height: 85vh; overflow-y: auto;
}
#scoresbox h2 { margin: 0 0 10px; color: var(--accent); font-size: 20px; letter-spacing: 1px; }
#scoresbody { display: flex; flex-wrap: wrap; gap: 14px; }
#scoresbody table { border-collapse: collapse; font-size: 12px; min-width: 150px; }
#scoresbody caption {
  color: var(--accent); font-size: 13px; letter-spacing: 1px; text-transform: uppercase;
  text-align: left; padding-bottom: 4px; border-bottom: 1px solid var(--panel-border);
}
#scoresbody td { padding: 2px 6px; color: var(--muted); }
#scoresbody td.rank { color: var(--accent); text-align: right; }
#scoresbody td.val { text-align: right; color: var(--text); }
#scoresbody tr.me td { color: #ffe9a0; }
/* The collage of web/static/bg/ images behind the login form, darkened so
   the form stays readable over anything. */
#loginbg {
  position: absolute; inset: 0; z-index: -1; overflow: hidden;
  display: grid; gap: 2px;
  filter: brightness(0.4) saturate(0.9);
}
#loginbg img { width: 100%; height: 100%; object-fit: cover; display: block; }

#loginform {
  background: var(--panel); border: 2px solid var(--panel-border); padding: 24px 28px;
  width: 320px; display: flex; flex-direction: column; gap: 10px; border-radius: 4px;
}
#loginform h1 { margin: 0; color: var(--accent); font-size: 26px; letter-spacing: 1px; }
#loginform p { margin: 0; color: var(--muted); font-size: 12px; }
#loginonline { color: var(--accent); min-height: 1em; }
#loginform label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
#loginform input {
  background: #16140f; border: 1px solid var(--panel-border); color: var(--text);
  padding: 6px 8px; font: inherit; font-size: 14px;
}
#loginform button {
  background: var(--accent); color: #221; border: 0; padding: 8px; font: inherit; font-weight: bold;
  cursor: pointer; margin-top: 4px;
}
#loginerr { color: #f66; min-height: 1.4em; font-size: 12px; }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #side { flex-direction: row; flex-wrap: wrap; border-left: 0; border-top: 2px solid var(--panel-border); max-height: 40vh; }
  .panel { flex: 1 1 45%; }
}
