:root {
  --bg: #0f1b2d;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --accent: #2f9e5b;
  --accent-ink: #ffffff;
  --gold: #f5c542;
  --danger: #d9443a;
  --line: #e4e7ec;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd0ff; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
#login { background: radial-gradient(circle at 30% 20%, #9be27a 0, #4caf50 35%, #23683a 100%); }
#modal { background: rgba(10, 20, 35, .45); }

.card { background: var(--card); border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); padding: 22px; width: 100%; }
.login-card { max-width: 380px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.logo { font-size: 46px; font-weight: 900; letter-spacing: -1px; color: #2b6cb0; text-shadow: 3px 3px 0 #ffd23f; }
.logo span { color: #e8573d; }
.tagline { margin: 0 0 8px; color: var(--muted); }
input { font: inherit; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; outline: none; width: 100%; }
input:focus { border-color: #2b6cb0; }
.err { color: var(--danger); min-height: 1.2em; font-size: 14px; }

.btn { font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer; background: #eef1f6; color: var(--ink); transition: transform .06s, filter .15s; }
.btn:hover { filter: brightness(.96); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 600; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.active { background: #ffd23f; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.round { width: 64px; height: 64px; border-radius: 50%; font-size: 26px; padding: 0; background: rgba(255,255,255,.85); }
kbd { font: 600 11px ui-monospace, monospace; background: rgba(0,0,0,.08); border-radius: 4px; padding: 1px 4px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.who, .actions { display: flex; gap: 8px; align-items: center; background: rgba(255,255,255,.88); padding: 6px 10px; border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.12); flex-wrap: wrap; }
.actions { padding: 6px; }
#hud-name { font-weight: 800; }
.badge { background: linear-gradient(135deg, #ffd23f, #f59e0b); color: #5a3a00; font-size: 11px; font-weight: 900; padding: 3px 7px; border-radius: 6px; letter-spacing: .5px; }
.coins b { font-variant-numeric: tabular-nums; }

.banner { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.95); padding: 8px 12px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.15); white-space: nowrap; }

.help { position: absolute; left: 50%; transform: translateX(-50%); bottom: 112px; background: rgba(20,30,45,.7); color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 13px; text-align: center; max-width: calc(100% - 32px); pointer-events: none; }
#play-help { bottom: 112px; }
.help kbd { background: rgba(255,255,255,.2); }

.hotbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; display: flex; gap: 6px; padding: 8px; background: rgba(20,30,45,.75); border-radius: 16px; max-width: calc(100% - 20px); overflow-x: auto; scrollbar-width: thin; }
.slot { position: relative; flex: 0 0 auto; width: 62px; height: 78px; border-radius: 10px; background: rgba(255,255,255,.12); border: 2px solid transparent; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #fff; font-size: 10px; text-align: center; user-select: none; }
.slot.sel { border-color: #ffd23f; background: rgba(255,210,63,.25); }
.slot.empty { opacity: .4; }
.slot .sw { width: 36px; height: 36px; border-radius: 6px; background-size: cover; image-rendering: pixelated; display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.slot .num { position: absolute; top: 2px; left: 5px; font-size: 10px; opacity: .7; }
.slot .cnt { position: absolute; top: 2px; right: 5px; font-size: 10px; font-weight: 800; }
.slot .nm { line-height: 1.1; max-width: 58px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.joy { position: absolute; left: 24px; bottom: 120px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.25); border: 2px solid rgba(255,255,255,.5); display: none; touch-action: none; }
#joy-knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.85); }
.jump { position: absolute; right: 24px; bottom: 130px; display: none; }
#mobile-rotate { position: absolute; right: 100px; bottom: 130px; }
body.touch .joy, body.touch .jump { display: block; }
body.touch #play-help, body.touch #build-help { display: none !important; }
body:not(.touch) #mobile-rotate { display: none !important; }

.modal-card { max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 22px; }
#modal-body { overflow-y: auto; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.shop-item { border: 2px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.shop-item .sw { width: 48px; height: 48px; border-radius: 8px; background-size: cover; image-rendering: pixelated; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.shop-item .price { color: var(--muted); font-size: 13px; }
.shop-item .row { display: flex; gap: 4px; }
.shop-item .row .btn { padding: 6px 8px; font-size: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; flex-wrap: wrap; }
.list-row .grow { flex: 1; min-width: 120px; }
.list-row .meta { color: var(--muted); font-size: 13px; }
.share-row { background: #eefbf2; border-color: #b7e4c7; }
.share-row .meta { overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

#toast { position: fixed; top: 74px; left: 50%; transform: translateX(-50%) translateY(-20px); background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 30; pointer-events: none; font-weight: 600; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.chip { background: #ffd23f; color: #5a3a00; font-weight: 800; font-size: 13px; padding: 4px 9px; border-radius: 8px; }
.invite-row { display: flex; gap: 8px; margin-bottom: 14px; }
.invite-row input { flex: 1; padding: 9px 12px; }
.section-title { margin: 16px 0 8px; font-size: 15px; }
.online { font-weight: 700; font-variant-numeric: tabular-nums; }

.chat { position: absolute; top: 64px; left: 10px; width: min(340px, calc(100% - 20px)); display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.chat-log { display: flex; flex-direction: column; gap: 3px; max-height: 190px; overflow-y: auto; scrollbar-width: none; }
.chat-row { align-self: flex-start; max-width: 100%; background: rgba(20,30,45,.62); color: #fff; padding: 4px 9px; border-radius: 9px; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; transition: opacity .6s; }
.chat-row b { color: #9fd3ff; }
.chat-row b.adm { color: #ffd23f; }
.chat-row.sys { background: rgba(20,30,45,.45); color: #d8e2f0; font-style: italic; font-size: 13px; }
.chat-row.old { opacity: 0; }
.chat.open { pointer-events: auto; }
.chat.open .chat-row.old { opacity: 1; }
.chat-form input { background: rgba(255,255,255,.96); padding: 10px 12px; }
.chat-btn { position: absolute; right: 24px; bottom: 210px; width: 52px; height: 52px; font-size: 22px; display: none; }
body.touch .chat-btn { display: block; }

@media (max-width: 640px) {
  .btn.small { padding: 7px 9px; font-size: 13px; }
  .btn.small kbd { display: none; }
  .banner { top: auto; bottom: 200px; }
}

/* Liv och mättnad */
.stats { position: absolute; top: 64px; left: 10px; background: rgba(255,255,255,.88); padding: 4px 10px; border-radius: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 18px; line-height: 1.25; pointer-events: none; letter-spacing: 1px; }
/* Flikar i butiken och garderoben */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.wear-row { display: flex; gap: 6px; flex-wrap: wrap; }
.shop-grid { min-height: min(52vh, 460px); align-content: start; }

/* Minikarta under liv och mättnad */
.minimap { position: absolute; top: 122px; left: 10px; width: 160px; height: 160px; border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.25); border: 3px solid rgba(255,255,255,.9); pointer-events: none; background: #4f9a38; }
.touch .minimap { width: 120px; height: 120px; }

/* Minecraft-sikte med ring som visar hur långt man kommit med att bryta */
.xhair { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%); pointer-events: none; --p: 0; }
.xhair::before { content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(rgba(255,255,255,.95) calc(var(--p) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 11px, #000 12px, #000 15px, transparent 16px); mask: radial-gradient(circle, transparent 11px, #000 12px, #000 15px, transparent 16px); }
.xhair::after { content: '+'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -55%); color: #fff; font: 700 26px system-ui; text-shadow: 0 0 3px #000; }
.lockhint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(20,30,45,.8); color: #fff; padding: 16px 26px; border-radius: 16px; font-size: 20px; font-weight: 800; text-align: center; pointer-events: none; }
.lockhint small { font-weight: 500; font-size: 13px; opacity: .8; }
.inv-bar { display: flex; gap: 6px; padding: 8px; background: rgba(20,30,45,.85); border-radius: 14px; overflow-x: auto; margin-bottom: 6px; }
.inv-grid { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; background: rgba(20,30,45,.85); border-radius: 14px; }

/* Hjälprutan (H) */
.help-list { display: flex; flex-direction: column; gap: 6px; }
.help-row { display: flex; gap: 12px; align-items: baseline; }
.help-keys { flex: 0 0 120px; display: flex; gap: 4px; flex-wrap: wrap; }
.help-keys kbd { background: #eef1f6; border: 1px solid #cfd6de; border-bottom-width: 2px; border-radius: 6px; padding: 1px 7px; font: 700 12px system-ui; }

/* Ljudreglage under minikartan */
.volume { position: absolute; top: 290px; left: 10px; width: 160px; display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.88); padding: 4px 10px; border-radius: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.volume input { flex: 1; min-width: 0; accent-color: #2b6cb0; }
.touch .volume { top: 250px; width: 120px; }

.invite-row select { flex: 1; font: inherit; padding: 10px; border-radius: 10px; border: 2px solid var(--line); }

/* Snabbknappar till höger (Shift + 1–5) */
.quickbar { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 6px; padding: 8px; background: rgba(20,30,45,.75); border-radius: 16px; }
.quickbar:empty { display: none; }
.touch .quickbar { display: none; }

.land-map { width: 100%; max-width: 378px; aspect-ratio: 1; display: block; margin: 8px auto; border-radius: 10px; background: #2f6b25; cursor: pointer; image-rendering: pixelated; }

/* Samtal med bybor */
.npc-log { max-height: 220px; overflow-y: auto; background: #f6f8fb; border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; }
.npc-log p { margin: 6px 0; }
.npc-opts { display: flex; flex-wrap: wrap; gap: 6px; }

.legal { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.legal a { color: inherit; }

/* Adminens kartredigerare */
.maped { position: fixed; inset: 0; z-index: 19; background: #1d2733; display: flex; flex-direction: column; }
.maped-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 12px; background: rgba(255,255,255,.95); color: #222; }
.maped-bar b { margin-right: 6px; }
.maped-sub { display: flex; flex-wrap: wrap; gap: 4px; padding-left: 10px; border-left: 2px solid #ddd; }
.maped-canvas { flex: 1; width: 100%; min-height: 0; cursor: crosshair; display: block; }
.maped-hint { position: absolute; bottom: 10px; right: 12px; color: #fff; font: 12px system-ui; opacity: .8; pointer-events: none; }
#toast { z-index: 40; }
.inv-search { width: 100%; box-sizing: border-box; margin: 10px 0 2px; padding: 9px 12px; border-radius: 10px; border: 1px solid #cfd6df; font-size: 15px; }
