/* Warm parchment-and-oak palette, so the UI sits next to the world art
   rather than fighting it. */
:root {
  --ink: #f2e9d8;
  --ink-dim: #b8ab94;
  --panel: #2b2117;
  --panel-2: #362a1d;
  --panel-3: #40311f;
  --edge: #5c452c;
  --edge-bright: #8a6a42;
  --gold: #d9b45f;
  --good: #8fc46a;
  --bad: #d97a6a;
  --xp: #7ab8d9;
  --loot: #d9c46a;
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute only works through the browser's default
   `[hidden] { display: none }` rule, which ANY author `display` declaration
   overrides. Several things here set display (.screen is grid, .panel and
   #console are flex), so hiding them in JS did nothing at all: the login screen
   stayed on top of the running game, and panels could never be closed.
   This rule makes `hidden` mean hidden, everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #14100b;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  user-select: none;
  -webkit-user-select: none;
}

/* --------------------------------------------------------------- login */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 30%, #3a2f20 0%, #16110c 70%);
  z-index: 100;
}

.screen.overlay { background: rgba(12, 9, 6, 0.82); }

.login-card {
  width: min(380px, 90vw);
  padding: 28px;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 38px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 0 #1a1410;
}

.tagline { margin: 0 0 22px; color: var(--ink-dim); font-style: italic; }

.login-card label {
  display: block;
  text-align: left;
  margin-bottom: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
}

input[type='text'] {
  width: 100%;
  padding: 10px 12px;
  background: #1d1610;
  border: 1px solid var(--edge);
  border-radius: 5px;
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
}
input[type='text']:focus { outline: none; border-color: var(--gold); }

button {
  font-family: var(--font);
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(#4a3a26, #362a1d);
  border: 1px solid var(--edge-bright);
  border-radius: 5px;
  padding: 9px 14px;
  font-size: 14px;
}
button:hover { background: linear-gradient(#5c4830, #40311f); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

#login-btn,
#reconnect-btn { width: 100%; margin-top: 14px; padding: 11px; font-size: 16px; color: var(--gold); }

.error { color: var(--bad); margin: 12px 0 0; min-height: 1em; }
.stage { color: var(--ink-dim); margin: 10px 0 0; font-size: 12px; font-style: italic; }
.hint { color: var(--ink-dim); font-size: 12px; margin: 16px 0 0; }
.muted { color: var(--ink-dim); }

/* ---------------------------------------------------------------- canvas */

#game { position: fixed; inset: 0; }

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

#hover-label {
  position: absolute;
  pointer-events: none;
  padding: 3px 8px;
  background: rgba(20, 15, 10, 0.9);
  border: 1px solid var(--edge);
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;
  z-index: 20;
  transform: translate(12px, -50%);
}
#hover-label .sub { color: var(--ink-dim); font-size: 11px; }
#hover-label .locked { color: var(--bad); font-size: 11px; }

/* ---------------------------------------------------------------- vitals */

.panel-plain {
  position: absolute;
  background: rgba(30, 23, 16, 0.86);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 8px 10px;
  backdrop-filter: blur(2px);
}

#vitals { top: 10px; left: 10px; width: 232px; z-index: 10; }

.vitals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
#player-name { font-weight: bold; color: var(--gold); }

.bar {
  position: relative;
  height: 17px;
  background: #1a130d;
  border: 1px solid var(--edge);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 5px;
}
.bar .fill { height: 100%; width: 0%; transition: width 0.18s ease-out; }
.bar span {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 11px;
  line-height: 17px;
  text-shadow: 0 1px 2px #000;
}
.bar.hp .fill { background: linear-gradient(#c25a4a, #8f3b2f); }
.bar.action .fill { background: linear-gradient(#c9a44a, #96772f); }

.coins { color: var(--gold); }
.buffs { display: flex; gap: 4px; }
.buffs .buff {
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--edge-bright);
  border-radius: 3px;
  color: var(--good);
}

/* --------------------------------------------------------------- sidebar */

#sidebar {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 15;
}
#sidebar button {
  position: relative;
  width: 46px;
  height: 46px;
  font-size: 21px;
  padding: 0;
}
#sidebar button span {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 9px;
  color: var(--ink-dim);
}
#sidebar button.active { border-color: var(--gold); background: linear-gradient(#6a5334, #4a3a26); }

/* ------------------------------------------------------------------- log */

#log-wrap {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: min(430px, 45vw);
  z-index: 10;
}
#log {
  max-height: 190px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(24, 18, 12, 0.78);
  border: 1px solid var(--edge);
  border-radius: 7px 7px 0 0;
  border-bottom: none;
  font-size: 13px;
  line-height: 1.45;
  scrollbar-width: thin;
}
#log div { margin-bottom: 1px; word-wrap: break-word; }
#log .info { color: var(--ink); }
#log .good { color: var(--good); }
#log .bad { color: var(--bad); }
#log .xp { color: var(--xp); }
#log .loot { color: var(--loot); }
#log .system { color: var(--gold); font-style: italic; }
#log .chat { color: #e8dcc4; }
#log .chat b { color: var(--gold); }

#chat-form { display: flex; }
#chat-input {
  border-radius: 0 0 7px 7px;
  background: rgba(20, 15, 10, 0.88);
  font-size: 13px;
  padding: 7px 10px;
}

/* ---------------------------------------------------------------- panels */

.panel {
  position: absolute;
  right: 66px;
  top: 10px;
  bottom: 10px;
  width: min(380px, 42vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 25;
}
.panel.wide { width: min(720px, 70vw); }

.panel header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--panel-3);
  border-bottom: 1px solid var(--edge);
  border-radius: 6px 6px 0 0;
}
.panel header h2 {
  margin: 0;
  font-size: 16px;
  color: var(--gold);
  flex: 1;
  letter-spacing: 0.5px;
}
.panel header .close {
  padding: 0;
  width: 26px;
  height: 26px;
  font-size: 18px;
  line-height: 1;
  background: none;
  border-color: transparent;
}
.panel header .close:hover { border-color: var(--edge-bright); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px; scrollbar-width: thin; }

/* ------------------------------------------------------------- inventory */

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

.slot {
  position: relative;
  aspect-ratio: 1;
  background: #1d1610;
  border: 1px solid var(--edge);
  border-radius: 4px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.slot.empty { cursor: default; opacity: 0.5; }
.slot:not(.empty):hover { border-color: var(--gold); }
.slot .icon {
  width: 62%;
  height: 62%;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.4);
}
.slot .qty {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 10px;
  color: var(--gold);
  text-shadow: 0 1px 2px #000;
}
.slot.selected { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }

#equipment {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--edge);
}
#equipment .eq-slot {
  flex: 1;
  min-height: 54px;
  background: #1d1610;
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 4px;
  text-align: center;
  font-size: 10px;
  color: var(--ink-dim);
  cursor: pointer;
}
#equipment .eq-slot .icon { width: 22px; height: 22px; margin: 2px auto; border-radius: 3px; }
#equipment .eq-slot.filled { color: var(--ink); border-color: var(--edge-bright); }

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--edge);
}
.item-actions button { padding: 5px 10px; font-size: 12px; }
.item-title { color: var(--gold); margin-bottom: 4px; }

/* ------------------------------------------------------------ skill tree */

.branch { margin-bottom: 18px; }
.branch h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--edge);
}
.node-row { display: flex; gap: 8px; flex-wrap: wrap; }

.node {
  width: 158px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.node:hover { border-color: var(--edge-bright); }
.node.owned { border-color: var(--good); background: #2a3a22; cursor: default; }
.node.locked { opacity: 0.62; }
.node.affordable { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(217, 180, 95, 0.4); }
.node .nname { font-weight: bold; margin-bottom: 3px; }
.node .ndesc { color: var(--ink-dim); line-height: 1.35; margin-bottom: 5px; }
.node .ncost { color: var(--gold); }
.node .nblock { color: var(--bad); font-size: 11px; }
.node .nowned { color: var(--good); }

/* -------------------------------------------------------------- listings */

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 5px;
  margin-bottom: 5px;
}
.row .icon { width: 22px; height: 22px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.4); }
.row .grow { flex: 1; min-width: 0; }
.row .name { display: block; }
.row .sub { display: block; color: var(--ink-dim); font-size: 11px; }
.row button { padding: 4px 9px; font-size: 12px; }
.row.disabled { opacity: 0.55; }

.section-title {
  margin: 14px 0 7px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--ink-dim);
}
.section-title:first-child { margin-top: 0; }

.pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 9px;
  font-size: 10px;
  border: 1px solid currentColor;
}

.qty-input { width: 54px; padding: 4px 6px; font-size: 12px; }

/* ------------------------------------------------------------------ farm */

.farm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 9px; }
.card {
  padding: 9px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 6px;
}
.card h4 { margin: 0 0 6px; font-size: 13px; color: var(--gold); }
.plots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 0; }
.plot {
  aspect-ratio: 1;
  background: #3a2b1c;
  border: 1px solid var(--edge);
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: 10px;
  cursor: pointer;
}
.plot.ready { background: #4a5a28; border-color: var(--good); }
.plot.growing { background: #33401f; }

.trait-bar { height: 5px; background: #1a130d; border-radius: 3px; overflow: hidden; margin-top: 2px; }
.trait-bar div { height: 100%; background: var(--gold); }
.animal { display: flex; gap: 8px; align-items: center; }
.animal.selected { outline: 1px solid var(--gold); }

/* --------------------------------------------------------------- console */

#console {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: min(760px, 92vw);
  max-height: 52vh;
  display: flex;
  flex-direction: column;
  background: rgba(10, 12, 10, 0.95);
  border: 1px solid #3f7a4a;
  border-radius: 7px;
  z-index: 60;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12.5px;
}
#console-out {
  flex: 1;
  overflow-y: auto;
  padding: 9px 11px;
  color: #9fe0a8;
  line-height: 1.5;
  white-space: pre-wrap;
  min-height: 90px;
}
#console-out .err { color: #e08a7a; }
#console-out .cmd { color: #d9d97a; }
#console-form {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-top: 1px solid #3f7a4a;
}
#console-form .prompt { color: #6ac47a; }
#console-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #cfe8cf;
  font-family: inherit;
  font-size: inherit;
  padding: 2px 0;
}
#console-input:focus { outline: none; }

::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-track { background: #1a130d; }
::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 4px; }

/* Diagnostic trace shown on the login screen when entering the world fails. */
#login-trace {
  margin: 12px 0 0;
  padding: 8px 10px;
  max-height: 190px;
  overflow: auto;
  text-align: left;
  background: #1a130d;
  border: 1px solid var(--edge);
  border-radius: 5px;
  font: 11px/1.45 'Consolas', 'Courier New', monospace;
  color: #b8ab94;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------------- fishing */

#fishing {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  width: min(430px, 88vw);
  padding: 12px 14px 14px;
  background: rgba(24, 20, 14, 0.94);
  border: 2px solid var(--edge-bright);
  border-radius: 9px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  z-index: 30;
  text-align: center;
}

.fish-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 9px;
}
#fish-name { color: var(--gold); font-weight: bold; font-size: 15px; }
#fish-state { color: var(--ink-dim); font-size: 12px; font-style: italic; }
#fish-state.struggling { color: var(--bad); font-style: normal; font-weight: bold; }

.fish-bar {
  position: relative;
  height: 21px;
  margin-bottom: 7px;
  background: #140f0a;
  border: 1px solid var(--edge);
  border-radius: 4px;
  overflow: hidden;
}
.fish-bar .zone { position: absolute; top: 0; bottom: 0; opacity: 0.28; }
.fish-bar .zone.safe { left: 0; width: 68%; background: #4a8f3a; }
.fish-bar .zone.warn { left: 68%; width: 20%; background: #c9a44a; }
.fish-bar .zone.danger { left: 88%; width: 12%; background: #c2402f; }

#tension-fill, #progress-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  transition: width 0.09s linear;
}
#tension-fill { background: linear-gradient(90deg, #6ac45a, #d9b45f); }
#tension-fill.warn { background: linear-gradient(90deg, #d9b45f, #e08a3c); }
#tension-fill.danger { background: linear-gradient(90deg, #e08a3c, #e04a34); }
#progress-fill { background: linear-gradient(90deg, #4a7fa8, #7ab8d9); }

.fish-label {
  position: absolute;
  inset: 0;
  font-size: 11px;
  line-height: 21px;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

#reel-btn {
  width: 100%;
  margin-top: 5px;
  padding: 11px;
  font-size: 15px;
  color: var(--gold);
  touch-action: none;
}
#reel-btn.active { background: linear-gradient(#7a5f34, #5c4830); border-color: var(--gold); }
#fishing.danger { border-color: #e04a34; }
