:root {
  --bg: #12160f;
  --panel: rgba(24, 20, 14, 0.86);
  --border: #6b4f2f;
  --border-hi: #a8804c;
  --text: #f2e8d2;
  --muted: #b5a68a;
  --accent: #f2a524;
  --good: #8fdc6a;
  --bad: #ff6a5a;
  --warn: #f0c060;
  font-family: 'Pixelify Sans', ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; image-rendering: pixelated; display: block; }
button {
  font: inherit; color: var(--text); background: #3b2c1b; border: 2px solid var(--border);
  padding: 5px 10px; cursor: pointer; border-radius: 2px;
}
button:hover:not(:disabled) { border-color: var(--border-hi); background: #4a3722; }
button:disabled { opacity: 0.45; cursor: default; }
button.big { font-size: 18px; padding: 10px 18px; width: 100%; margin-top: 10px; background: #5a3d1c; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; margin-top: 6px; }
input {
  font: inherit; color: var(--text); background: #1b1610; border: 2px solid var(--border);
  padding: 6px 8px; outline: none; width: 100%;
}
input:focus { border-color: var(--border-hi); }
.muted { color: var(--muted); }
.tiny { font-size: 12px; color: var(--muted); line-height: 1.35; }
.error { color: var(--bad); min-height: 1em; }
.row { display: flex; align-items: center; gap: 4px; }
.row.gap { gap: 10px; margin-top: 10px; flex-wrap: wrap; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(10,14,8,.55), rgba(5,7,4,.92)); z-index: 20; }
.card { background: var(--panel); border: 3px solid var(--border); padding: 24px; box-shadow: 0 0 0 3px #00000088; }
.login-card { width: min(380px, calc(100vw - 32px)); text-align: center; }
.login-card h1 { margin: 0; font-size: 46px; letter-spacing: 6px; color: var(--accent); text-shadow: 3px 3px 0 #6b2a10; }
.login-card .sub { margin: 4px 0 18px; color: var(--muted); }
.login-card label { display: block; text-align: left; margin-bottom: 10px; }
.colors { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.colors button { width: 30px; height: 30px; padding: 0; border-width: 3px; }
.colors button.sel { border-color: #fff; }

.panel { background: var(--panel); border: 2px solid var(--border); padding: 8px 10px; box-shadow: 0 0 0 2px #00000066; }
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud .panel, #hud input, #hud button, #hud .modal { pointer-events: auto; }

#status { position: absolute; top: 10px; left: 10px; width: 220px; }
#status .who { margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: relative; height: 14px; background: #1b1610; border: 1px solid #000; margin: 3px 0; }
.bar .fill { position: absolute; inset: 0 auto 0 0; transition: width .2s; }
.bar .fill.hp { background: linear-gradient(#e2574a, #a8302a); }
.bar .fill.hunger { background: linear-gradient(#e0a64a, #a8702a); }
.bar span { position: absolute; inset: 0; font-size: 11px; line-height: 13px; text-align: center; text-shadow: 1px 1px 0 #000; }
.coin { color: #f6c840; }
#effects { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.fx { font-size: 11px; padding: 1px 5px; border: 1px solid; border-radius: 2px; background: #00000055; }

#topright { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#clock { text-align: right; min-width: 150px; }
#minimap { width: 160px; height: 160px; border: 2px solid var(--border); image-rendering: pixelated; background: #000; pointer-events: none; }

#chat { position: absolute; left: 10px; bottom: 10px; width: min(380px, 40vw); pointer-events: auto; }
#log { max-height: 180px; overflow-y: auto; font-size: 13px; line-height: 1.3; text-shadow: 1px 1px 0 #000; padding: 4px; scrollbar-width: none; }
#log div { margin: 1px 0; }
#log .sys { color: var(--muted); font-style: italic; }
#log .good, #log .coin { color: var(--good); }
#log .bad { color: var(--bad); }
#log .warn { color: var(--warn); }
#log .level { color: #ffd84a; }
#log .pick { color: #e6dcc4; }
#log .name { color: var(--accent); }

#bottom { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#basket { display: grid; grid-template-columns: repeat(12, 40px); gap: 3px; padding: 6px; }
.slot { width: 40px; height: 40px; background: #1b1610; border: 2px solid #3d2e1c; position: relative; cursor: pointer; }
.slot canvas { width: 32px; height: 32px; image-rendering: pixelated; position: absolute; left: 2px; top: 2px; }
.slot.sel { border-color: var(--accent); }
.slot:hover { border-color: var(--border-hi); }
.slot .q { position: absolute; right: 1px; top: -2px; font-size: 12px; color: #ffe08a; text-shadow: 1px 1px 0 #000; }
.slot .fresh { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: #000; }
.slot .fresh i { display: block; height: 100%; background: #8fdc6a; }
.hint { font-size: 12px; color: var(--muted); text-shadow: 1px 1px 0 #000; }

#item-detail { width: min(520px, 92vw); }
#item-detail h3 { margin: 0 0 2px; font-size: 18px; }
#item-detail .latin { font-style: italic; color: var(--muted); }
#item-detail p { margin: 4px 0; font-size: 14px; line-height: 1.35; }
#item-detail .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.prog { height: 6px; background: #1b1610; margin-top: 6px; }
.prog i { display: block; height: 100%; width: 0; background: var(--accent); }

#prompt { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); background: var(--panel); border: 2px solid var(--border); padding: 3px 8px; font-size: 13px; }
#toast { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); font-size: 26px; color: #ffd84a; text-shadow: 2px 2px 0 #000; opacity: 0; transition: opacity .4s; text-align: center; }
#toast.show { opacity: 1; }

.modal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(640px, 94vw); max-height: 78vh; overflow-y: auto; padding: 16px 18px; z-index: 10; }
.modal h2 { margin: 0 0 8px; color: var(--accent); }
.modal .close { position: absolute; top: 8px; right: 8px; padding: 2px 8px; }
.modal ul { padding-left: 18px; line-height: 1.45; }

.shop-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed #4a3a26; }
.shop-item .desc { font-size: 13px; color: var(--muted); }

#journal-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.jentry { display: grid; grid-template-columns: 40px 1fr; gap: 8px; background: #1b161088; border: 1px solid #3d2e1c; padding: 6px; }
.jentry canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.jentry.unknown canvas { filter: brightness(0) opacity(.5); }
.jentry .n { font-weight: 600; }
.jentry .l { font-style: italic; color: var(--muted); font-size: 12px; }
.jentry .d { font-size: 12px; line-height: 1.3; margin-top: 3px; }
.tag { font-size: 11px; padding: 0 4px; border: 1px solid; margin-left: 4px; }

.skill { margin: 8px 0; }
.skill .top { display: flex; justify-content: space-between; }
.skill .desc { font-size: 12px; color: var(--muted); }
.skill .bar .fill { background: linear-gradient(#7fc4e0, #3a7ca8); }

#players-list div { padding: 3px 0; }

#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 4; transition: box-shadow .6s; }
#vignette.poison { box-shadow: inset 0 0 120px 30px rgba(60, 200, 60, 0.45); }
#vignette.nausea { box-shadow: inset 0 0 120px 20px rgba(160, 180, 60, 0.35); }

@media (max-width: 1150px) {
  #chat { bottom: 120px; width: min(320px, 45vw); }
}
@media (max-width: 760px) {
  #basket { grid-template-columns: repeat(8, 36px); }
  .slot { width: 36px; height: 36px; } .slot canvas { width: 28px; height: 28px; }
  #minimap { width: 110px; height: 110px; }
  #chat { width: 60vw; } #log { max-height: 110px; }
}

#foray { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); min-width: 300px; max-width: min(520px, 46vw); text-align: center; }
#foray .foray-top { font-size: 16px; color: var(--accent); }
#foray-me { font-size: 14px; }
#goal { font-size: 13px; color: #ffe08a; margin-top: 2px; }
#board { width: 190px; font-size: 13px; }
#board .board-h { color: var(--accent); margin: 2px 0; font-size: 13px; }
#board .board-h + div { margin-bottom: 6px; }
.lb-row { display: flex; justify-content: space-between; gap: 6px; }
.lb-row.me { color: #ffe08a; }
.bounty { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.bounty canvas { width: 24px; height: 24px; image-rendering: pixelated; flex: none; }
.bounty .bpts { margin-left: auto; color: var(--good); white-space: nowrap; }
.modal h3 { color: #e6c873; margin: 14px 0 4px; font-size: 16px; }
button.primary { background: #4a5a1c; border-color: #8aa83a; }
.traits { margin: 6px 0; display: grid; grid-template-columns: 110px 1fr; gap: 2px 8px; font-size: 13px; }
.traits .tk { color: var(--muted); }
.traits .unk { color: #6f6352; font-style: italic; }
.examine { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.examine button { font-size: 12px; padding: 3px 7px; }
.labels { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 6px; font-size: 13px; }
.labels button { font-size: 12px; padding: 3px 7px; }
.labels button.on { border-color: #ffe08a; color: #ffe08a; }
.slot .lab { position: absolute; left: 1px; bottom: 0; font-size: 10px; color: #8fdc6a; text-shadow: 1px 1px 0 #000; }
.group { border: 1px solid #3d2e1c; padding: 8px; margin-bottom: 10px; background: #1b161066; }
.group .tell { font-size: 13px; color: #ffe08a; margin: 2px 0 8px; }
.group .members { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.jentry .tr { font-size: 11px; line-height: 1.3; color: #d8ccb2; margin-top: 3px; }
.jentry .tr b { color: var(--muted); font-weight: 400; }
.stars { color: #f6c840; font-size: 12px; }
.mastered { color: #8fdc6a; font-size: 11px; border: 1px solid #8fdc6a; padding: 0 3px; margin-left: 4px; }
#results-list .res { display: flex; justify-content: space-between; font-size: 18px; padding: 4px 0; border-bottom: 1px dashed #4a3a26; }
#hof-list .res { display: grid; grid-template-columns: 30px 1fr 80px 70px 80px; padding: 3px 0; color: var(--text); }
#log .rumour { color: #ffb0f0; }
@media (max-width: 1150px) { #board { width: 160px; } #foray { top: auto; bottom: auto; top: 10px; max-width: 40vw; min-width: 0; } }

#sense-cd { font-size: 12px; margin-top: 4px; }
#sense-cd.ready { color: #ffe08a; }
#sense-cd.cd { color: var(--muted); }
#log .sense { color: #ffe08a; }
#log .trip { color: #e0a0ff; font-style: italic; }

/* ---------------- Mantar.io ---------------- */
.small { font-size: 12px; }
.menu-card { width: min(420px, calc(100vw - 32px)); text-align: center; }
.menu-card h1 { margin: 0; font-size: 52px; letter-spacing: 5px; color: var(--accent); text-shadow: 3px 3px 0 #6b2a10; }
.menu-card h1 span { font-size: 26px; color: #e8dcc4; text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
.menu-card .sub { color: var(--muted); margin: 6px 0 16px; line-height: 1.4; }
.menu-card .sub b { color: var(--bad); }
.menu-card input { text-align: center; font-size: 18px; }
.how { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 12px; color: var(--muted); margin: 12px 0; }
.how b { color: var(--text); }
.hof { margin-top: 10px; text-align: left; font-size: 13px; }
.hof .h { color: var(--accent); margin-bottom: 4px; text-align: center; }
.hof .row { display: grid; grid-template-columns: 24px 1fr 60px 60px; }
.death-card { width: min(520px, calc(100vw - 32px)); text-align: center; max-height: 92vh; overflow-y: auto; }
.death-card h2 { color: var(--bad); margin: 0 0 10px; font-size: 26px; }
.lesson { display: grid; grid-template-columns: 56px 1fr; gap: 10px; text-align: left; background: #1b1610; border: 1px solid #4a3a26; padding: 10px; margin: 8px 0; }
.lesson canvas { width: 56px; height: 56px; image-rendering: pixelated; }
.lesson .tell { color: #ffe08a; font-size: 13px; margin-top: 4px; }
.lesson .d { font-size: 13px; line-height: 1.35; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.stats div { background: #1b1610; border: 1px solid #3d2e1c; padding: 6px 2px; }
.stats b { display: block; font-size: 20px; color: var(--text); }
.stats span { font-size: 11px; color: var(--muted); }
#death-learned { font-size: 13px; color: var(--good); min-height: 1em; }
#death-learned canvas { width: 24px; height: 24px; image-rendering: pixelated; vertical-align: middle; }
.big-num { font-size: 26px; }
#status { width: 200px; }
#cds { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.cd { font-size: 11px; padding: 1px 5px; border: 1px solid #6b5a40; color: var(--muted); }
.cd.ready { color: #ffe08a; border-color: #ffe08a; }
#board { width: 180px; }
#board .board-h { color: var(--accent); margin-bottom: 4px; }
#minimap { width: 140px; height: 140px; }

/* The T in MANTAR is a fly agaric */
.t-agaric { height: 0.86em; width: auto; vertical-align: -0.08em; margin: 0 0.04em 0 0.02em; filter: drop-shadow(3px 3px 0 #6b2a10); }

/* ---------------- touch / phones ---------------- */
html, body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
canvas#game { touch-action: none; }
.mob { display: none; }
body.touch .mob { display: block; }
body.touch .desk { display: none; }
#touch-ui { display: none; }
body.touch #touch-ui {
  display: flex; flex-direction: column; gap: 10px; position: absolute;
  right: calc(14px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); pointer-events: auto;
}
.tbtn {
  width: 64px; height: 64px; border-radius: 50%; font-size: 14px; background: rgba(40, 30, 18, 0.78);
  border: 3px solid var(--border-hi); touch-action: none;
}
.tbtn:active { background: #6b4a22; }
body.touch #chat-input { display: none; }
@media (max-width: 700px), (max-height: 500px) {
  #status { width: auto; min-width: 120px; padding: 5px 7px; top: calc(6px + env(safe-area-inset-top)); left: 6px; }
  .big-num { font-size: 20px; }
  #status #known-count, #status #cds { font-size: 10px; }
  #board { width: 120px; font-size: 11px; padding: 5px 7px; }
  #board-top .lb-row:nth-child(n+6) { display: none; }
  #topright { top: calc(6px + env(safe-area-inset-top)); right: 6px; }
  #minimap { display: none; }
  #chat { width: 55vw; bottom: calc(10px + env(safe-area-inset-bottom)); left: 6px; }
  #log { max-height: 80px; font-size: 11px; }
  .modal { width: 96vw; max-height: 86vh; padding: 12px; }
  #journal-list .group .members { grid-template-columns: 1fr; }
  .menu-card h1 { font-size: 40px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------- compact field notes (side panel, game keeps running) ---------------- */
#journal.notes {
  position: absolute; left: 10px; top: 150px; width: min(330px, 92vw);
  max-height: max(220px, calc(100vh - 380px)); overflow-y: auto; padding: 6px 8px; z-index: 10;
  background: rgba(20, 16, 11, 0.9); scrollbar-width: thin;
}
.notes-h { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--accent); }
.notes-h .close { position: static; margin-left: auto; padding: 0 6px; font-size: 12px; }
.notes-key { font-size: 10px; margin: 2px 0 4px; }
.ng { border-top: 1px solid #3d2e1c; padding: 3px 0; }
.ng-h { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #c9b98a; }
.ng-h canvas { width: 16px; height: 16px; image-rendering: pixelated; }
.ntell { font-size: 10px; color: #ffe08a; line-height: 1.25; margin: 1px 0 2px; }
.nrow { display: grid; grid-template-columns: 8px 1fr auto; column-gap: 6px; align-items: center; font-size: 12px; padding: 2px 2px; cursor: pointer; border-radius: 2px; }
.nrow:hover { background: #ffffff0d; }
.nrow > i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.nrow .fx { font-size: 10px; padding: 0 4px; white-space: nowrap; }
.nrow > span.muted { font-size: 10px; }
.nrow .stars { font-size: 9px; text-align: right; }
.nmore { grid-column: 1 / -1; font-size: 11px; line-height: 1.3; color: #d8ccb2; padding: 3px 0 3px 14px; }
.nmore b { color: var(--muted); font-weight: 400; }
.nunk { font-size: 11px; color: var(--muted); font-style: italic; border-top: 1px solid #3d2e1c; padding-top: 4px; }
@media (max-width: 700px), (max-height: 500px) {
  #journal.notes { left: 6px; right: 86px; width: auto; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); max-height: 46vh; }
}
.ng-tip { margin-left: auto; color: #ffe08a; font-size: 10px; }

/* field notes: a grid of mushroom squares */
#journal.notes { width: auto; max-width: 92vw; }
.sq-grid { display: grid; grid-template-columns: repeat(7, 40px); gap: 4px; margin-top: 6px; }
.sq { position: relative; width: 40px; height: 40px; background: #1b1610; border: 2px solid #3d2e1c; cursor: pointer; }
.sq canvas { position: absolute; left: 2px; top: 2px; width: 32px; height: 32px; image-rendering: pixelated; }
.sq.unknown canvas { filter: brightness(0) opacity(0.45); }
.sq.sel { outline: 2px solid #fff; }
.sq-star { position: absolute; right: 1px; top: -3px; font-size: 10px; color: #f6c840; text-shadow: 1px 1px 0 #000; }
.sq-info { min-height: 18px; font-size: 13px; margin-top: 6px; }
@media (max-width: 700px), (max-height: 500px) {
  .sq-grid { grid-template-columns: repeat(6, 36px); }
  .sq { width: 36px; height: 36px; } .sq canvas { width: 28px; height: 28px; }
}
/* 100 species: a 10-wide grid of smaller squares */
.sq-grid { grid-template-columns: repeat(10, 30px); gap: 3px; }
.sq { width: 30px; height: 30px; }
.sq canvas { left: 1px; top: 1px; width: 24px; height: 24px; }
#journal.notes { max-height: calc(100vh - 170px); }
@media (max-width: 700px), (max-height: 500px) {
  .sq-grid { grid-template-columns: repeat(8, 30px); }
  .sq { width: 30px; height: 30px; } .sq canvas { width: 24px; height: 24px; }
}
