* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root { --ink: #f4ead2; --gold: #ffcf6b; --panel: rgba(18, 14, 10, .92); }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Courier New", "Apple SD Gothic Neo", monospace;
  background: #0b0f08; color: var(--ink);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
img { image-rendering: pixelated; }

/* topbar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 42px; z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: linear-gradient(#1a130b, rgba(26, 19, 11, .4));
  font-size: 13px; border-bottom: 2px solid #3a2a16;
}
.topbar .back { color: var(--ink); opacity: .8; text-decoration: none; }
.topbar .back:hover { opacity: 1; color: var(--gold); }
.topbar .brand { font-weight: bold; color: var(--gold); letter-spacing: .5px; }
.topbar .spacer { flex: 1; }
.topbar .hs { font-size: 12px; opacity: .9; }
.topbar .hs b { color: var(--gold); }
.topbar button { background: #2a1f12; color: var(--ink); border: 1px solid #4a3620; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-family: inherit; }

#stage { position: fixed; inset: 42px 0 0 0; overflow: hidden; background: #2a5232; }
#game { display: block; width: 100%; height: 100%; }

/* HUD */
#hud { position: absolute; top: 50px; left: 10px; z-index: 20; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#hud.hidden { display: none; }
.bar { width: 190px; height: 16px; background: #1c140b; border: 2px solid #3a2a16; border-radius: 4px; position: relative; overflow: hidden; }
.bar .fill { height: 100%; transition: width .12s linear; }
.bar .lbl { position: absolute; inset: 0; font-size: 10px; line-height: 14px; text-align: center; color: #fff; text-shadow: 0 1px 1px #000; letter-spacing: .5px; }
#hpFill { background: linear-gradient(#ff6b6b, #c83232); }
#hungerFill { background: linear-gradient(#ffd76b, #d99b2a); }
#fireFill { background: linear-gradient(#ff9d3d, #d8531a); }

.resrow { display: flex; gap: 10px; font-size: 14px; margin-top: 2px; text-shadow: 0 1px 2px #000; }
.resrow span { background: rgba(20, 14, 8, .6); padding: 2px 7px; border-radius: 5px; border: 1px solid #3a2a16; }
.resrow b { color: var(--gold); }

#topinfo { position: absolute; top: 50px; right: 10px; z-index: 20; text-align: right; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#phase { font-size: 15px; font-weight: bold; padding: 3px 10px; border-radius: 6px; text-shadow: 0 1px 2px #000; }
#phase.day { background: rgba(255, 200, 90, .25); color: #ffe6a8; }
#phase.night { background: rgba(80, 60, 160, .35); color: #c9b8ff; }
.info2 { font-size: 12px; text-shadow: 0 1px 2px #000; }
.info2 b { color: var(--gold); }

/* build bar */
#buildbar { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; gap: 5px; padding: 5px; background: rgba(14, 10, 6, .8); border: 2px solid #3a2a16; border-radius: 10px; max-width: 96vw; overflow-x: auto; }
#buildbar.hidden { display: none; }
#buildbar.active { box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(255, 207, 107, .4); }
.slot { width: 64px; flex: 0 0 auto; background: #241a0f; border: 2px solid #4a3620; border-radius: 8px; padding: 4px 3px 3px; text-align: center; cursor: pointer; position: relative; transition: transform .08s; }
.slot:hover { transform: translateY(-2px); border-color: #6a5030; }
.slot.sel { border-color: var(--gold); background: #3a2a16; box-shadow: 0 0 8px rgba(255, 207, 107, .5); }
.slot.poor { opacity: .45; }
.slot .num { position: absolute; top: 2px; left: 4px; font-size: 9px; color: #998; }
.slot .ic { font-size: 20px; line-height: 1.1; }
.slot .nm { font-size: 9.5px; color: var(--ink); white-space: nowrap; overflow: hidden; }
.slot .ct { font-size: 9px; color: var(--gold); margin-top: 1px; white-space: nowrap; }

/* touch controls */
#touchpad { position: absolute; inset: 42px 0 0 0; z-index: 15; pointer-events: none; }
#touchpad.hidden { display: none; }
#joy { position: fixed; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .2); display: none; z-index: 16; pointer-events: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255, 207, 107, .55); border: 2px solid rgba(255, 255, 255, .4); }
.tbtns { position: absolute; right: 14px; bottom: 84px; display: flex; flex-direction: column; gap: 10px; pointer-events: auto; }
.tbtn { width: 60px; height: 60px; border-radius: 50%; background: rgba(40, 28, 16, .8); border: 2px solid #6a5030; color: var(--ink); font-size: 22px; display: flex; align-items: center; justify-content: center; }
.tbtn:active { background: rgba(255, 207, 107, .4); }
#btnAttack { width: 78px; height: 78px; font-size: 30px; background: rgba(120, 40, 30, .8); border-color: #a44; }

/* overlay */
#overlay { position: absolute; inset: 42px 0 0 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(circle at 50% 40%, rgba(40, 26, 12, .75), rgba(6, 8, 5, .94)); }
#overlay.hidden { display: none; }
.panel { background: var(--panel); border: 3px solid #5a4226; border-radius: 14px; padding: 26px 24px; max-width: 560px; width: 100%; text-align: center; box-shadow: 0 12px 50px rgba(0, 0, 0, .6); }
.panel h1 { font-size: clamp(24px, 6vw, 38px); color: var(--gold); text-shadow: 0 2px 0 #5a3812; margin-bottom: 6px; }
.panel h2 { font-size: 15px; color: #d8c9a8; font-weight: normal; margin-bottom: 14px; }
.panel .big { font-size: 18px; margin: 8px 0; }
.panel .big b, .panel .score b { color: var(--gold); }
.panel .score { font-size: 22px; margin: 6px 0; }
.panel .best { font-size: 13px; opacity: .75; margin-bottom: 14px; }
.panel button { font-family: inherit; font-size: 17px; font-weight: bold; color: #2a1a08; background: linear-gradient(#ffd87a, #e8a534); border: none; border-radius: 10px; padding: 12px 30px; cursor: pointer; box-shadow: 0 4px 0 #a06a16; margin: 6px 0; }
.panel button:active { transform: translateY(2px); box-shadow: 0 2px 0 #a06a16; }
.panel .hint { font-size: 12px; opacity: .7; margin-top: 12px; line-height: 1.5; }
.howto { text-align: left; font-size: 12.5px; line-height: 1.7; margin: 14px auto; max-width: 440px; background: rgba(0, 0, 0, .25); border: 1px solid #4a3620; border-radius: 10px; padding: 12px 16px; }
.howto b { color: var(--gold); }
.howto .k { display: inline-block; background: #2a1f12; border: 1px solid #5a4226; border-radius: 4px; padding: 0 6px; font-size: 11px; }
