* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #87ceeb; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none;
}
#app { position: fixed; inset: 0; }
canvas { display: block; }
.hidden { display: none !important; }

#crosshair { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 26px; color: #fff; opacity: .85; text-shadow: 0 0 2px #000; pointer-events: none; z-index: 5; }

/* damage flash */
#hurt { position: fixed; inset: 0; z-index: 8; background: radial-gradient(circle, transparent 45%, rgba(180,0,0,.55)); opacity: 0; pointer-events: none; transition: opacity .12s; }
#hurt.show { opacity: 1; }

/* survival HUD */
#stats { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); z-index: 6; display: flex; flex-direction: column; gap: 2px; width: 360px; }
.statrow { display: flex; justify-content: flex-start; gap: 0; font-size: 15px; line-height: 1; filter: drop-shadow(0 1px 1px #000); }
#food { justify-content: flex-end; }
.statrow span { width: 18px; text-align: center; }

/* HUD */
#hud { position: fixed; left: 12px; bottom: 100px; z-index: 5; font-size: 13px; text-shadow: 0 1px 2px #000; line-height: 1.6; font-variant-numeric: tabular-nums; pointer-events: none; }
#coords { font-weight: 600; }
#info { opacity: .85; }

/* topbar */
#topbar { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.4); padding: 6px 12px; border-radius: 8px; backdrop-filter: blur(4px); font-size: 13px; }
#world-name { font-weight: 600; }
#save-btn { background: #4e9636; color: #fff; border: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
#save-btn:hover { background: #5aad3f; }
#save-status { opacity: .9; min-width: 60px; }

/* hotbar */
#hotbar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6; display: flex; gap: 4px; padding: 4px; background: rgba(0,0,0,.35); border-radius: 8px; }
.slot { position: relative; width: 50px; height: 50px; border-radius: 6px; background: rgba(0,0,0,.25); border: 2px solid rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.slot.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.4); }
.swatch { width: 32px; height: 32px; border-radius: 4px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25), inset 0 4px 0 rgba(255,255,255,.18); }
.slot .count { position: absolute; right: 3px; bottom: 1px; font-size: 11px; text-shadow: 0 1px 2px #000; }
.slot .num { position: absolute; left: 3px; top: 1px; font-size: 10px; opacity: .6; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 108px; transform: translateX(-50%) translateY(10px); z-index: 7; background: rgba(0,0,0,.7); padding: 8px 16px; border-radius: 8px; font-size: 13px; opacity: 0; transition: all .25s; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* overlays shared */
#overlay, #menu, #inventory, #death { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, rgba(30,50,80,.5), rgba(0,0,0,.78)); backdrop-filter: blur(3px); }
#death { z-index: 25; background: radial-gradient(circle, rgba(90,0,0,.5), rgba(20,0,0,.85)); }

.panel, .menu-panel, .inv-panel, .death-panel { background: rgba(20,24,32,.92); border: 1px solid rgba(255,255,255,.1); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.panel { padding: 30px 38px; text-align: center; max-width: 460px; }
.panel h1, .menu-panel h1, .death-panel h1 { font-size: 30px; margin-bottom: 4px; }
.sub { opacity: .7; margin-bottom: 18px; font-size: 14px; }
#play-btn, #create-btn, #respawn-btn { background: #4e9636; color: #fff; border: none; font-size: 17px; font-weight: 700; padding: 11px 34px; border-radius: 10px; cursor: pointer; box-shadow: 0 5px 0 #356b28; }
#play-btn:active, #create-btn:active, #respawn-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #356b28; }
.controls { display: grid; gap: 5px; text-align: left; font-size: 13px; opacity: .9; margin: 18px 0 14px; }
.controls div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.06); padding-bottom: 4px; }
.note { font-size: 12px; opacity: .6; line-height: 1.6; margin-top: 8px; }

/* menu */
.menu-panel { padding: 28px 32px; width: min(860px, 94vw); text-align: center; }
.menu-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; text-align: left; margin-top: 8px; }
.menu-panel h2 { font-size: 16px; margin-bottom: 10px; opacity: .9; }
#world-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.world-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 10px 12px; }
.world-title { font-weight: 700; font-size: 15px; }
.world-meta { font-size: 12px; opacity: .6; margin-top: 3px; }
.world-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-play { background: #4e9636; color: #fff; border: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn-del { background: rgba(255,255,255,.08); color: #fff; border: none; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.btn-del:hover { background: #a13b3b; }
.menu-right label { display: block; font-size: 13px; opacity: .85; margin-bottom: 12px; }
.menu-right input, .menu-right select { display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: rgba(0,0,0,.3); color: #fff; font-size: 14px; }
.menu-right select option { background: #1a1e28; color: #fff; }
#create-btn { width: 100%; margin-top: 4px; }
.muted { opacity: .55; font-size: 13px; padding: 12px 4px; }

/* inventory + crafting */
.inv-panel { padding: 22px 26px; width: min(760px, 94vw); }
.inv-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.inv-head h2 { font-size: 18px; }
#inv-close { background: rgba(255,255,255,.1); border: none; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.inv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.inv-hint { font-size: 12px; opacity: .55; margin-bottom: 8px; }
.inv-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.inv-grid.hb { margin-top: 4px; }
.inv-sep { font-size: 12px; opacity: .6; margin: 12px 0 4px; }
.craft-col h3 { font-size: 15px; margin-bottom: 10px; }
.craft-col small { opacity: .55; font-weight: 400; }
#recipes { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.recipe { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 8px; padding: 8px 10px; color: #fff; cursor: pointer; text-align: left; }
.recipe:hover:not(.disabled) { background: rgba(78,150,54,.35); border-color: #4e9636; }
.recipe.disabled { opacity: .4; cursor: not-allowed; }
.rout { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.rout .sw { width: 16px; height: 16px; border-radius: 3px; display: inline-block; }
.rin { font-size: 11px; opacity: .7; }

/* death */
.death-panel { padding: 40px 50px; text-align: center; }
.death-panel h1 { color: #ff6b6b; }
.death-panel p { opacity: .8; margin: 10px 0 20px; }

/* auth screen */
#auth { position: fixed; inset: 0; z-index: 22; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, rgba(30,50,80,.5), rgba(0,0,0,.8)); backdrop-filter: blur(3px); }
.auth-panel { padding: 30px 34px; width: min(400px, 92vw); text-align: center; background: rgba(20,24,32,.94); border: 1px solid rgba(255,255,255,.1); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.auth-tabs .tab { flex: 1; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: #fff; padding: 9px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.auth-tabs .tab.active { background: #4e9636; border-color: #4e9636; font-weight: 700; }
#auth-form label { display: block; text-align: left; font-size: 13px; opacity: .85; margin-bottom: 12px; }
#auth-form input { display: block; width: 100%; margin-top: 5px; padding: 10px 11px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: rgba(0,0,0,.3); color: #fff; font-size: 14px; }
#auth-submit { width: 100%; background: #4e9636; color: #fff; border: none; font-size: 16px; font-weight: 700; padding: 11px; border-radius: 10px; cursor: pointer; box-shadow: 0 4px 0 #356b28; }
#auth-submit:active { transform: translateY(2px); box-shadow: 0 2px 0 #356b28; }
#auth-submit:disabled { opacity: .6; cursor: wait; }
.auth-err { color: #ff8a8a; font-size: 13px; min-height: 18px; margin-bottom: 10px; text-align: left; }

/* menu topline (user + logout) */
.menu-topline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 13px; opacity: .9; }
#logout-btn { background: rgba(255,255,255,.08); color: #fff; border: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 12px; }
#logout-btn:hover { background: #a13b3b; }

#loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #1a1e28; font-size: 16px; color: #9fb; }

@media (max-width: 720px) {
  .menu-cols, .inv-cols { grid-template-columns: 1fr; }
}
