* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  font-family: 'Segoe UI', 'Baloo 2', system-ui, -apple-system, sans-serif;
  background: #2c6b6f; color: #23383a;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: default; }
.hidden { display: none !important; }

/* The stamina bar and the fish bar above it share this width — as wide as fits
   between the stats panel on the left and the pack on the right. */
:root { --bar-w: clamp(240px, calc(100vw - 520px), 480px); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.panel-title { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #5a7c7e; margin-bottom: 6px; }

#statsPanel {
  position: absolute; left: 14px; bottom: 14px; width: 210px;
  background: rgba(255, 254, 248, 0.92); border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 10px 22px rgba(0,0,0,0.18);
}
.stat { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.stat-icon { width: 20px; text-align: center; font-size: 16px; }
.stat-bar { flex: 1; height: 12px; border-radius: 7px; background: #dde9e7; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.15); }
.stat-fill { height: 100%; width: 100%; border-radius: 7px; transition: width .35s ease, background-color .35s ease; }
.stat-num { width: 26px; text-align: right; font-size: 12px; font-weight: 700; color: #557072; font-variant-numeric: tabular-nums; }
.stat[data-stat="hunger"] .stat-fill { background: #f08a4b; }
.stat[data-stat="thirst"] .stat-fill { background: #4aa3df; }
.stat[data-stat="rest"] .stat-fill { background: #8f7bd6; }
.stat[data-stat="stamina"] .stat-fill { background: #f2c94c; }
/* Stamina, the energy bar: big and central, near the bottom. */
#staminaBar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); width: var(--bar-w); margin: 0;
  background: rgba(255, 254, 248, 0.94); border-radius: 18px; padding: 8px 14px; gap: 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 10px 22px rgba(0,0,0,0.2);
}
#staminaBar .stat-icon { width: 24px; font-size: 20px; }
#staminaBar .stat-bar { height: 22px; border-radius: 12px; }
#staminaBar .stat-fill { border-radius: 12px; background: linear-gradient(180deg, #ffe07a, #f2b632); transition: width .2s linear; }
#staminaBar .stat-num { width: 34px; font-size: 15px; }
#staminaBar.low .stat-fill { background: #e0523f; }
.stat.low .stat-fill { background: #e0523f; animation: pulse 1s ease-in-out infinite; }
.stat.low .stat-num { color: #e0523f; }
@keyframes pulse { 50% { opacity: .55; } }

#chatLog {
  position: absolute; left: 14px; bottom: 170px; width: min(420px, calc(100vw - 28px));
  display: flex; flex-direction: column; gap: 3px; pointer-events: none;
}
#chatLog .line {
  align-self: flex-start; max-width: 100%; padding: 4px 10px; border-radius: 10px;
  background: rgba(20, 44, 46, 0.62); color: #fff; font-size: 13px; line-height: 1.35;
  text-shadow: 0 1px 1px rgba(0,0,0,0.4); transition: opacity 1s ease;
  overflow-wrap: anywhere;
}
#chatLog .line.server { color: #ffe9a6; }
#chatLog .line.fade { opacity: 0; }
#chatLog .line b { color: #a9ecdf; font-weight: 700; }

#chatForm { position: absolute; left: 14px; bottom: 134px; width: 210px; }
#chatInput {
  width: 100%; height: 28px; border: none; border-radius: 14px; padding: 0 12px; font: inherit; font-size: 13px;
  background: rgba(255,254,248,0.85); color: #23383a; outline: none; box-shadow: 0 2px 0 rgba(0,0,0,0.08);
  -webkit-user-select: text; user-select: text;
}
#chatInput:focus { background: #fff; box-shadow: 0 0 0 2px #ffcf5c; }

#inventory {
  position: absolute; right: 14px; bottom: 14px; width: 224px;
  background: rgba(255, 254, 248, 0.92); border-radius: 16px; padding: 10px 12px 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 10px 22px rgba(0,0,0,0.18);
}
#inventoryGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot {
  position: relative; aspect-ratio: 1; border-radius: 10px; background: #e6f0ee;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.14); display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.slot.filled { background: #f7efd9; cursor: default; }
.slot.food { cursor: pointer; }
.slot.food:hover { background: #ffe9a6; transform: translateY(-1px); }
.slot .count {
  position: absolute; right: 4px; bottom: 1px; font-size: 11px; font-weight: 800; color: #3b4a4c;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}
.slot .name { display: none; }

#topRight { position: absolute; right: 14px; top: 12px; display: flex; gap: 6px; pointer-events: none; }
#onlineCount, #fpsCounter {
  padding: 4px 12px; border-radius: 12px; background: rgba(20, 44, 46, 0.55); color: #fff;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
#fpsCounter { min-width: 62px; text-align: center; pointer-events: auto; cursor: help; }
#logoutBtn {
  position: absolute; right: 14px; top: 44px; border: none; border-radius: 12px; padding: 5px 12px;
  background: rgba(255,254,248,0.85); font: inherit; font-size: 12px; font-weight: 700; color: #557072; cursor: pointer;
}
#logoutBtn:hover { background: #fff; }

/* ---------- Fishing HUD ---------- */
/* Sits directly above the stamina bar, same width. The fish's energy bar is the
   one at the bottom of it. */
#fishingHud {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); width: var(--bar-w);
  background: rgba(255, 254, 248, 0.94); border-radius: 18px; padding: 10px 14px 10px; text-align: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 12px 26px rgba(0,0,0,0.25);
}
#fishTop { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
#fishPhase { font-size: 15px; font-weight: 800; color: #2a6b6e; text-align: left; }
#fishCancel { border: none; background: none; font: inherit; font-size: 12px; font-weight: 700; color: #8a6c62; cursor: pointer; white-space: nowrap; }
#fishCancel span { font-weight: 400; opacity: .7; }
#fishHint { font-size: 12px; color: #6b8688; min-height: 16px; margin-bottom: 6px; text-align: left; }
#fishControls { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
#fishBarRow { display: flex; align-items: center; gap: 10px; }
#fishBarRow .stat-icon { width: 24px; text-align: center; font-size: 20px; }
#fishBar { position: relative; flex: 1; height: 22px; border-radius: 12px; background: #dde9e7; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.18); }
#fishBarFill { height: 100%; width: 100%; background: #4aa3df; border-radius: 12px; transition: width .12s linear, background-color .1s; }
#fishBar.wrong #fishBarFill { background: #e0523f; }   /* you're holding the wrong way */
#fishBar.bite #fishBarFill { background: #f2c94c; }
.fish-btn {
  height: 38px; min-width: 56px; border: none; border-radius: 12px; font: inherit; font-size: 17px; font-weight: 800;
  background: #dfeeec; color: #2a6b6e; box-shadow: 0 3px 0 #b5cfcb; cursor: pointer; touch-action: none;
}
.fish-btn-wide { flex: 1; font-size: 15px; }
.fish-btn.pull { background: #ffd9d2; color: #c2402c; box-shadow: 0 3px 0 #e6b0a6; }
.fish-btn.counter { background: #cdeed9; color: #1f7a45; box-shadow: 0 3px 0 #a3cfb3; }
.fish-btn.hold, .fish-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b5cfcb; }
#fishingHud.bite { animation: shake .18s linear infinite; }
@keyframes shake { 0%,100% { transform: translateX(-50%) rotate(0); } 25% { transform: translateX(calc(-50% - 2px)) rotate(-.4deg); } 75% { transform: translateX(calc(-50% + 2px)) rotate(.4deg); } }
#fishingHud.bite #fishPhase { color: #d24a1f; font-size: 17px; }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed; z-index: 5; pointer-events: none; padding: 5px 10px; border-radius: 9px;
  background: rgba(20, 44, 46, 0.88); color: #fff; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}

/* ---------- Login ---------- */
#loginOverlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 20;
  background: radial-gradient(circle at 50% 30%, rgba(143,208,201,0.9), rgba(30,72,76,0.94));
  -webkit-user-select: text; user-select: text;
}
#loginOverlay.visible { display: flex; }
.login-card {
  width: min(340px, calc(100vw - 32px)); background: #fffef8; border-radius: 22px; padding: 26px 26px 24px; text-align: center;
  box-shadow: 0 8px 0 rgba(0,0,0,0.08), 0 20px 40px rgba(0,0,0,0.3);
}
.login-otter { font-size: 52px; line-height: 1; animation: waddle 1.4s ease-in-out infinite; transform-origin: 50% 90%; display: inline-block; }
@keyframes waddle {
  0%, 100% { transform: rotate(-7deg) translateY(0); }
  25% { transform: rotate(0deg) translateY(-5px); }
  50% { transform: rotate(7deg) translateY(0); }
  75% { transform: rotate(0deg) translateY(-5px); }
}
.login-title { font-size: 28px; font-weight: 800; color: #2a6b6e; margin: 4px 0 2px; }
.login-sub { font-size: 13px; color: #6b8688; line-height: 1.45; margin-bottom: 16px; }
.login-card input {
  display: block; width: 100%; height: 42px; margin-bottom: 10px; padding: 0 14px; border: 2px solid #d5e6e3; border-radius: 12px;
  font: inherit; font-size: 15px; outline: none; background: #f6fbfa; color: #23383a;
}
.login-card input:focus { border-color: #4a9d9b; background: #fff; }
#loginError { min-height: 18px; margin: -2px 0 8px; font-size: 13px; color: #d24a1f; font-weight: 600; }
#joinBtn {
  width: 100%; height: 46px; border: none; border-radius: 14px; font: inherit; font-size: 16px; font-weight: 800;
  background: #ffcf5c; color: #4a3200; box-shadow: 0 4px 0 #b98a1c; cursor: pointer;
}
#joinBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b98a1c; }
#joinBtn:disabled { opacity: .6; cursor: default; }

@media (max-width: 760px) {
  :root { --bar-w: calc(100vw - 28px); }
  #staminaBar { bottom: 200px; }
  #fishingHud { bottom: 256px; }
  #statsPanel { width: 180px; }
  #inventory { width: 190px; }
  #chatLog { bottom: 170px; }
}
