:root {
  color-scheme: dark;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  color: #f1f7ff;
  background: #152d42;
  --panel: #102538ef;
  --surface: #142d43;
  --edge: #92b7d341;
  --muted: #afc7dc;
  --ice: #a0e4fa;
  --gold: #ffcf7f;
  --shadow: 0 12px 35px #06162466;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; outline: none; touch-action: none; }
button, input, select {
  border: 1px solid var(--edge);
  border-radius: 11px;
  padding: 9px 12px;
  font: inherit;
  color: inherit;
  background: var(--surface);
}
button { cursor: pointer; font-weight: 700; transition: background .16s, border-color .16s, box-shadow .16s; }
button:hover { background: #23465f; border-color: #b5d9eb77; }
:where(button, input, select, ol):focus-visible { outline: 2px solid var(--ice); outline-offset: 3px; }
input, select { width: 100%; min-width: 0; }
input::placeholder { color: #99b7cb; }
kbd {
  display: inline-block; padding: 1px 5px; border-radius: 5px; background: #d2edff16;
  color: #e3f4ff; font: 700 .9em/1.4 "Segoe UI Variable", system-ui, sans-serif;
}

#lobby {
  position: relative; min-height: 100svh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at 54% 50%, #111e2e31 10%, #0a1d2ecf 100%);
}
.lobby-shell {
  display: grid; grid-template-columns: 1.05fr .95fr; width: min(100%, 850px);
  isolation: isolate; overflow: hidden; border: 1px solid #ebf7ff6e; border-radius: 29px;
  background: #0d2235f5; box-shadow: 0 24px 85px #07142285, inset 0 1px #e3f7ff30;
}
.lobby-panel { padding: clamp(24px, 5vw, 52px); }
.season {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 15px;
  color: #c1eafa; text-transform: uppercase; letter-spacing: .13em; font-size: 10px; font-weight: 800;
}
.season span { color: var(--ice); font-size: 17px; }
h1 { margin: 0 0 29px; font-size: clamp(40px, 7vw, 70px); font-weight: 850; line-height: .94; letter-spacing: -.07em; }
h1 em { color: var(--ice); font-style: normal; }
#join, #admin-grant { display: grid; gap: 8px; }
label { color: #e2edf7; font-size: 13px; font-weight: 700; }
label[for="world"] { margin-top: 8px; }
#join input, #join select { padding: 11px 12px; background: #152e45; }
.world-note { color: var(--muted); font-size: 12px; margin: 1px 0 10px; }
.play {
  display: flex; justify-content: space-between; align-items: center; margin-top: 2px;
  background: linear-gradient(115deg, #ffe6ab, #fcc071); color: #263247;
  border-color: #ffe7b2; font-weight: 850; padding: 12px 15px;
}
.play:hover { background: #ffe2a2; border-color: #fff1cd; }
.play span { font-size: 19px; line-height: 1; }
#lobby-notice { margin: -9px 0 16px; color: #ffccac; font-size: 13px; }
.hero-card {
  position: relative; display: grid; place-content: center; justify-items: center; align-content: center;
  min-width: 0; padding: 20px; overflow: hidden; border-left: 1px solid #c7e7fb35;
  background: radial-gradient(circle at 52% 43%, #547f98 0%, #284f6e 49%, #172f4b 100%);
}
.hero-card::before, .hero-card::after {
  content: ""; position: absolute; pointer-events: none; inset: 12% 14%; border-radius: 50%;
  border: 1px solid #d8efff36; transform: rotate(-21deg); box-shadow: 0 0 65px #cbeeff15;
}
.hero-card::after { inset: 19% 18%; border-color: #e6f5ff27; transform: rotate(18deg); }
#portrait, #hero-name { position: relative; z-index: 1; }
#portrait { display: block; width: min(100%, 225px); height: auto; filter: drop-shadow(0 9px 14px #0d223a60); }
#hero-name { max-width: 100%; overflow-wrap: anywhere; text-align: center; color: #e4f4ff; }

#game { position: fixed; inset: 0; pointer-events: none; --gutter: 18px; }
#game header { position: absolute; inset: var(--gutter) var(--gutter) auto; display: flex; justify-content: space-between; align-items: start; gap: 10px; }
#session, .actions button, #leaderboard, .map-widget, #admin, .map-panel, #drop-dialog {
  background: var(--panel); border: 1px solid var(--edge);
  box-shadow: var(--shadow), inset 0 1px #c6edff18;
}
#session { margin: 0; padding: 10px 13px; border-radius: 12px; font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }
.actions { display: flex; gap: 5px; flex-shrink: 0; }
.actions button { pointer-events: auto; font-size: 13px; }
.actions button:hover { background: #24465d; }

#leaderboard, .map-widget { position: absolute; right: var(--gutter); width: clamp(135px, 17vw, 226px); border-radius: 15px; }
#leaderboard { top: 69px; padding: 11px; }
#leaderboard h2 { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: clamp(11px, 1.05vw, 14px); }
#leaderboard h2 span { color: var(--gold); }
#leaderboard ol {
  list-style: none; counter-reset: placement; margin: 0; padding: 0; max-height: min(26vh, 210px);
  overflow: auto; pointer-events: auto; font-size: clamp(10px, 1vw, 13px); scrollbar-width: thin;
}
#leaderboard li {
  counter-increment: placement; display: grid; grid-template-columns: 18px minmax(0, 1fr);
  gap: 6px; align-items: center; min-height: 27px; padding: 3px 5px; border-radius: 7px; color: #d7e8f5;
}
#leaderboard li::before { content: counter(placement); color: #9bbad1; font-size: 10px; font-variant-numeric: tabular-nums; }
#leaderboard li[aria-current="true"] { color: var(--gold); background: #f6cc7d16; font-weight: 800; }
#leaderboard li:first-child::before { color: var(--gold); }
.leader-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.leader-row strong { font-variant-numeric: tabular-nums; }
.leader-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard p { display: flex; justify-content: space-between; gap: 5px; margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--edge); color: var(--muted); font-size: 11px; }
#player-score { color: var(--gold); font-variant-numeric: tabular-nums; }

.map-widget { bottom: var(--gutter); padding: 7px; }
#map-toggle {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  padding: 3px 4px 7px; border: 0; border-radius: 6px; background: none;
  color: #e7f2ff; font-size: 11px; pointer-events: auto;
}
#map-toggle:hover { color: var(--ice); }
#minimap, #expanded-map { display: block; height: auto; background: #3f6686; border: 1px solid #b3e8f2a3; border-radius: 9px; }
#minimap { width: 100%; }

.hud {
  position: absolute; bottom: var(--gutter); left: 50%; transform: translateX(-50%);
  width: min(700px, calc(100% - 24px)); padding: 10px;
  text-align: center;
}
#weapon-cooldown {
  position: absolute; bottom: var(--gutter); left: var(--gutter);
  display: grid; grid-template-columns: 30px 43px; align-items: center;
  gap: 3px 7px; padding: 5px 8px 5px 5px;
  border: 1px solid #c2e4f150; border-radius: 11px; background: #142d4399;
  font-size: 12px; font-weight: 750;
}
#weapon-cooldown-icon { grid-row: span 2; display: grid; place-items: center; }
#weapon-cooldown-icon .item-icon { width: 100%; height: auto; }
#weapon-cooldown-time { color: var(--gold); text-align: center; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #061624; }
#weapon-cooldown-bar { grid-column: 2; width: 100%; height: 5px; accent-color: var(--gold); }
#status { margin: 0 0 7px; color: #f5fbff; text-shadow: 0 1px 3px #102538, 0 1px 4px #102538; font-size: clamp(14px, 1.45vw, 19px); font-weight: 750; min-height: 1.25em; }
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.meter { display: flex; align-items: center; gap: 5px; min-width: 0; --fill: #68dbb0; --fill-dark: #27886f; }
.hunger-meter { --fill: #ffcc81; --fill-dark: #c77a49; }
.meter > span {
  display: grid; place-items: center; flex: 0 0 auto; width: clamp(24px, 3.25vw, 37px); aspect-ratio: 1;
  border-radius: 10px; background: #254358; border: 1px solid #d5edff25;
}
.meter .item-icon { width: 80%; height: 80%; }
.meter-track { flex: 1; min-width: 0; position: relative; }
.meter-track strong {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  color: white; font-size: clamp(9px, 1.05vw, 13px); font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px #0b2135, 0 1px 3px #0b2135;
}
.meter progress {
  display: block; width: 100%; height: clamp(18px, 1.75vw, 25px); appearance: none;
  border: 1px solid #9dc2dc48; background: #0c1d2d; border-radius: 7px; overflow: hidden; accent-color: var(--fill);
}
.meter progress::-webkit-progress-bar { background: #0c1d2d; }
.meter progress::-webkit-progress-value { background: linear-gradient(110deg, var(--fill-dark), var(--fill)); }
.meter progress::-moz-progress-bar { background: var(--fill); }
.inventory { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; }
.inventory button, #recipes button {
  position: relative; display: grid; place-items: center; padding: 0; min-width: 0; width: 100%; aspect-ratio: 1;
  border: 1px solid #a8cfe446; border-radius: 10px; background: #29465e;
  box-shadow: inset 0 1px #d4efff19; pointer-events: auto;
}
.inventory button { background: #29465eb8; cursor: grab; user-select: none; }
.inventory button.empty { background: #172e438c; border-color: #c2e4f140; }
.inventory button:hover { background: #395e79c9; border-color: #b7e8fa9f; }
#recipes button:hover { background: #395e79; border-color: #b7e8fa9f; }
.inventory button[aria-pressed="true"] { background: #38596acc; border-color: var(--gold); box-shadow: inset 0 0 0 1px #f7d09262, 0 0 11px #ffd18524; }
.inventory button.drop-target { box-shadow: inset 0 0 0 2px var(--ice); }
.inventory kbd, .inventory b { position: absolute; color: #f6fcff; line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #041322; }
.inventory kbd { top: 5px; left: 5px; font-size: clamp(8px, .9vw, 11px); padding: 0; background: none; }
.inventory b { bottom: 5px; right: 5px; font-size: clamp(9px, 1.15vw, 15px); }
.inventory .empty .item-icon { visibility: hidden; }
.item-icon { width: 76%; height: 76%; pointer-events: none; }

.craft { position: absolute; top: 69px; left: var(--gutter); max-width: min(455px, calc(100vw - 175px)); }
.craft:not(:has(button:not([hidden]))) { display: none; }
.craft h2 { width: max-content; margin: 0 0 6px; padding: 4px 8px; border: 1px solid var(--edge); border-radius: 7px; background: var(--panel); font-size: 11px; color: #e6f4ff; }
#recipes { display: flex; flex-wrap: wrap; gap: 5px; }
#recipes button { width: clamp(32px, 5vw, 49px); }
#recipes button:disabled { opacity: .6; cursor: default; }
[data-tooltip]::after {
  content: attr(data-tooltip); display: none; position: absolute; z-index: 4;
  width: max-content; max-width: 168px; padding: 7px 9px; color: #f0f7ff; background: #12283c;
  border: 1px solid #91bdd568; border-radius: 9px; white-space: pre-line; text-align: left;
  font: 650 11px/1.45 "Segoe UI Variable", system-ui, sans-serif;
  pointer-events: none; box-shadow: var(--shadow);
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { display: block; }
.inventory [data-tooltip]::after { bottom: calc(100% + 7px); left: 0; }
.inventory [data-tooltip]:nth-child(n+6)::after { left: auto; right: 0; }
.inventory.dragging-item [data-tooltip]::after { display: none; }
#recipes [data-tooltip]::after { top: calc(100% + 6px); left: 0; }

#admin {
  position: absolute; top: 68px; right: var(--gutter); z-index: 2; pointer-events: auto;
  width: min(290px, calc(100vw - 24px)); max-height: calc(100% - 80px); overflow: auto;
  padding: 14px; border-radius: 15px;
}
#admin h2, #drop-dialog h2 { margin: 0 0 12px; font-size: 19px; }
#admin > button { width: 100%; margin-top: 8px; }
#admin-result { margin: 8px 0 0; color: var(--gold); font-size: 13px; }
#admin-result:empty { display: none; }
#drop-dialog {
  position: fixed; inset: 0; margin: auto; z-index: 4; height: fit-content;
  max-height: calc(100% - 24px); width: min(360px, calc(100% - 24px)); padding: 18px;
  color: #f0f6ff; border-radius: 15px;
}
#drop-dialog p { margin: 10px 0 16px; color: var(--muted); }
#drop-dialog form { display: flex; justify-content: flex-end; gap: 8px; }
#drop-dialog [value="drop"] { background: #ffd095; color: #202c3d; }
#drop-shade { display: none; position: fixed; inset: 0; z-index: 3; background: #091a2b62; pointer-events: none; }
#drop-dialog[open] + #drop-shade { display: block; }

#map-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; z-index: 3; background: #071a2e7d; }
.map-panel { display: grid; gap: 9px; min-width: 0; max-width: 100%; max-height: 100%; overflow: auto; padding: 12px; border-radius: 16px; pointer-events: auto; }
.map-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.map-heading h2 { margin: 0; font-size: 19px; }
.map-heading button { padding: 5px 8px; font-size: 12px; }
#expanded-map { width: min(100%, 1000px, 112svh); }
.map-legend { display: flex; flex-wrap: wrap; gap: 5px 15px; margin: 0; padding: 0; list-style: none; color: #dcebf7; font-size: 12px; }
.map-legend li { display: flex; align-items: center; gap: 6px; }
.map-legend i { width: 8px; height: 8px; border-radius: 50%; }
.legend-player { background: #ffd471; }
.legend-iron { background: #e3e8e5; }
.map-legend .legend-diamond, .map-legend .legend-amethyst { border-radius: 1px; transform: rotate(45deg); }
.legend-diamond { background: #6ee7ff; }
.legend-amethyst { background: #ef98fb; }
@media (max-width: 1150px) { .map-widget { bottom: 162px; } }
@media (max-width: 1020px) { #weapon-cooldown { bottom: calc(var(--gutter) + 138px); } }
@media (max-width: 620px) {
  #game { --gutter: 8px; }
  .lobby-shell { grid-template-columns: 1fr; }
  .hero-card { grid-row: 1; border-left: 0; border-bottom: 1px solid #c7e7fb35; padding: 3px 12px 10px; }
  #portrait { width: 105px; }
  #game header button, #session { padding: 7px; font-size: 11px; }
  #leaderboard, .craft, #admin { top: 48px; }
  #leaderboard { padding: 8px; }
  #leaderboard ol { max-height: 19vh; }
  .hud { width: calc(100% - 16px); padding: 7px; }
  #weapon-cooldown { bottom: calc(var(--gutter) + 105px); }
  .map-widget { bottom: 133px; width: 118px; }
  .inventory { gap: 3px; }
  .inventory button { border-radius: 6px; }
  .inventory kbd { top: 3px; left: 3px; }
  .inventory b { bottom: 3px; right: 3px; }
}
@media (max-height: 500px) {
  #leaderboard ol { max-height: 14vh; }
  .map-widget { width: 100px; bottom: 112px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
