:root {
  --frame: #1d2421;
  --ink: #f3ecd6;
  --muted: #b9b39c;
  --plate: #2b3430;
  --plate-line: #4c5a52;
  --accent: #e2b04a;
  --ok: #7fc06a;
  --bad: #e05a5a;
  --font: "Pixelify Sans", ui-monospace, "Courier New", monospace;
  color-scheme: dark;
}
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--frame); }
body {
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; cursor: pointer; }

.plate {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  background: var(--plate);
  border: 2px solid var(--plate-line);
  border-radius: 4px;
  padding: 6px 10px;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  pointer-events: none;
}
.plate b { font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.plate span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.plate kbd {
  font-family: var(--font); background: var(--frame); border: 1px solid var(--plate-line);
  border-radius: 3px; padding: 0 4px; color: var(--accent);
}

.mapbox {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#minimap {
  width: clamp(120px, 22vw, 200px);
  display: block;
  image-rendering: pixelated;
  border: 3px solid var(--plate-line);
  border-radius: 4px;
  background: var(--plate);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  cursor: crosshair;
  touch-action: none;
}
#status {
  font-size: 12px;
  background: var(--plate);
  border: 1px solid var(--plate-line);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--muted);
}
#status::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: var(--accent); vertical-align: 1px; }
#status[data-state="online"]::before { background: var(--ok); }
#status[data-state="offline"]::before { background: var(--bad); }

.pad {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 156px; height: 156px;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 4px;
  opacity: .8;
}
.pad[hidden] { display: none; }
.pad button {
  font: 700 20px var(--font); color: var(--ink);
  background: var(--plate); border: 2px solid var(--plate-line); border-radius: 6px; touch-action: none;
}
.pad button.on { background: var(--accent); color: var(--frame); }
.pad .u { grid-area: 1 / 2; } .pad .l { grid-area: 2 / 1; } .pad .r { grid-area: 2 / 3; } .pad .d { grid-area: 3 / 2; }

.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(17, 22, 20, .72);
  user-select: auto; -webkit-user-select: auto; touch-action: auto;
}
.login[hidden] { display: none; }
.login-card {
  width: min(100%, 320px);
  background: var(--plate);
  border: 2px solid var(--plate-line);
  border-radius: 4px;
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
}
.login-card h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: .05em; color: var(--accent); }
.login-card label { font-size: 15px; color: var(--muted); }
.login-card input, .login-card button {
  font: 500 18px var(--font);
  border-radius: 3px; padding: 6px 10px;
}
.login-card input { background: var(--frame); color: var(--ink); border: 2px solid var(--plate-line); }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button { font-weight: 700; background: var(--accent); color: var(--frame); border: 0; cursor: pointer; }
.login-error { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--bad); }

/* Ausbildung */
.tut {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  width: min(360px, calc(100vw - 2 * clamp(120px, 22vw, 200px) - 60px));
  min-width: 180px;
  background: var(--plate); border: 2px solid var(--accent); border-radius: 4px;
  padding: 6px 10px; text-align: center;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  pointer-events: none;
}
.tut[hidden] { display: none; }
@media (max-width: 820px) {
  .tut { left: calc(12px + env(safe-area-inset-left, 0px)); transform: none; top: calc(96px + env(safe-area-inset-top, 0px)); width: min(300px, 55vw); min-width: 0; }
}
.tut b { color: var(--accent); font-size: 13px; letter-spacing: .05em; }
.tut span { font-size: 15px; }

/* Rennen */
.run {
  position: relative; overflow: hidden;
  width: clamp(120px, 22vw, 200px); height: 22px;
  font: 500 13px var(--font); color: var(--ink);
  background: var(--plate); border: 2px solid var(--plate-line); border-radius: 4px;
  padding: 0; cursor: pointer;
}
.run-fill { position: absolute; inset: 0 auto 0 0; background: #4a6b3c; transition: width .15s linear; }
.run.on .run-fill, .run.running .run-fill { background: #7a9a3c; }
.run.on { border-color: var(--accent); }
.run-label { position: relative; font-variant-numeric: tabular-nums; }

/* Chat */
.chat {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: min(380px, calc(100vw - 24px - 200px));
  display: flex; flex-direction: column; gap: 4px;
}
body.touch .chat { bottom: calc(186px + env(safe-area-inset-bottom, 0px)); }
.chat-log {
  max-height: 132px; overflow-y: auto;
  font-size: 14px; line-height: 1.3;
  background: rgba(29, 36, 33, .72); border-radius: 4px; padding: 4px 8px;
  user-select: text; -webkit-user-select: text;
  scrollbar-width: thin;
}
.chat-log:empty { display: none; }
.line.sys { color: #f2d48a; }
.line.chat b { color: var(--accent); font-weight: 700; }
#chat-input {
  width: 100%; box-sizing: border-box;
  font: 500 14px var(--font); color: var(--ink);
  background: rgba(29, 36, 33, .72); border: 2px solid var(--plate-line); border-radius: 4px; padding: 3px 8px;
}
#chat-input:focus { outline: none; border-color: var(--accent); background: var(--plate); }

/* Rucksack */
.inv {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--plate); border: 2px solid var(--plate-line); border-radius: 4px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}
.inv header button {
  width: 100%; display: flex; justify-content: space-between; gap: 12px;
  font: 700 14px var(--font); color: var(--ink);
  background: none; border: 0; padding: 4px 8px; cursor: pointer;
}
.inv header button::after { content: "▾"; color: var(--accent); }
.inv.closed header button::after { content: "▴"; }
#inv-count { color: var(--muted); font-weight: 500; margin-left: auto; font-variant-numeric: tabular-nums; }
.inv-grid { display: grid; grid-template-columns: repeat(4, 40px); gap: 3px; padding: 0 6px 6px; }
.inv.closed .inv-grid { display: none; }
.slot {
  width: 40px; height: 40px; box-sizing: border-box;
  background: var(--frame) center / 32px no-repeat; image-rendering: pixelated;
  border: 2px solid #38433d; border-radius: 3px;
  touch-action: none; cursor: pointer;
}
.slot.sel { border-color: var(--accent); background-color: #3a3a26; }
.slot.drag { position: fixed; z-index: 10; pointer-events: none; transform: translate(-50%, -50%); opacity: .85; border-color: var(--accent); }
@media (max-height: 520px), (max-width: 520px) {
  .inv-grid { grid-template-columns: repeat(4, 34px); }
  .slot { width: 34px; height: 34px; background-size: 26px; }
  .chat { width: calc(100vw - 24px - 180px); }
  .chat-log { max-height: 96px; font-size: 13px; }
}

/* Kontextmenü und Hover */
.menu {
  position: fixed; z-index: 20; min-width: 150px;
  background: var(--plate); border: 2px solid var(--plate-line); border-radius: 4px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
  padding: 2px 0;
}
.menu[hidden] { display: none; }
.menu-title { font-size: 12px; color: var(--muted); padding: 2px 10px 3px; border-bottom: 1px solid var(--plate-line); }
.menu button {
  display: block; width: 100%; text-align: left;
  font: 500 15px var(--font); color: var(--ink);
  background: none; border: 0; padding: 5px 10px; cursor: pointer;
}
.menu button b { color: var(--accent); font-weight: 700; }
.menu button:hover, .menu button:focus-visible { background: var(--frame); outline: none; }
.hover {
  position: fixed; z-index: 5; pointer-events: none;
  font-size: 13px; background: rgba(29, 36, 33, .85); border-radius: 3px; padding: 2px 6px; white-space: nowrap;
}
.hover[hidden] { display: none; }

/* Bereichswechsel */
.fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.fade.go { animation: fade .35s ease-out; }
@keyframes fade { from { opacity: 1; } to { opacity: 0; } }
body.touch .plate .hint { display: none; }

/* Leben */
.run.hp { cursor: default; display: flex; align-items: center; justify-content: center; }
.run.hp .run-fill { background: #8f3a30; }

/* Taler und angebotene Plätze */
.inv-coins { font-size: 13px; color: var(--accent); padding: 0 8px 4px; font-variant-numeric: tabular-nums; }
.slot.marked { border-color: #7fc06a; background-color: #2e3d2a; }

/* Anklickbare Chatzeilen */
.line.link { color: #c9a2f0; cursor: pointer; text-decoration: underline dotted; }
.line.link:hover { color: #e2c8ff; }

/* Kontextmenü mit mehreren Dingen */
.grp-head {
  display: block; width: 100%; text-align: left;
  font: 500 15px var(--font); color: var(--ink);
  background: none; border: 0; padding: 5px 10px; cursor: pointer;
}
.grp-head::before { content: "▸ "; color: var(--muted); }
.grp.open .grp-head::before { content: "▾ "; }
.grp-head b { color: var(--accent); }
.grp-head small { color: var(--muted); font-size: 12px; }
.grp-head:hover { background: var(--frame); }
.grp-body { border-left: 2px solid var(--accent); margin-left: 12px; }
.grp-body[hidden] { display: none; }
.grp-body button { padding-left: 10px; }

/* Fenster: Werkstatt, Laden, Handel */
.dlg {
  position: fixed; z-index: 15; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
  background: var(--plate); border: 2px solid var(--accent); border-radius: 4px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .45);
  user-select: auto; -webkit-user-select: auto;
}
.dlg[hidden] { display: none; }
.dlg header { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--plate-line); }
.dlg h2 { margin: 0; font-size: 18px; color: var(--accent); }
#dlg-close { font: 700 16px var(--font); color: var(--ink); background: none; border: 0; cursor: pointer; padding: 2px 6px; }
#dlg-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.dlg-note { margin: 0; font-size: 14px; color: var(--muted); }
.dlg-note.small { font-size: 12px; }
.dlg-note.ok { color: var(--ok); }
.ico { width: 32px; height: 32px; flex: none; background: var(--frame) center / 26px no-repeat; image-rendering: pixelated; border: 2px solid #38433d; border-radius: 3px; }
.ico.click { cursor: pointer; }
.ico.click:hover { border-color: var(--bad); }
.btn {
  font: 700 14px var(--font); color: var(--frame); background: var(--accent);
  border: 0; border-radius: 3px; padding: 4px 9px; cursor: pointer;
}
.btn:disabled { background: #4c5a52; color: var(--muted); cursor: default; }
.recipe { display: flex; align-items: center; gap: 6px; }
.recipe.off .recipe-text { opacity: .55; }
.recipe-text { flex: 1; display: flex; flex-direction: column; }
.recipe-text small { color: var(--muted); font-size: 12px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, 64px); gap: 6px; }
.shop-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  font: 600 13px var(--font); color: var(--accent); background: var(--frame); border: 2px solid #38433d; border-radius: 3px; cursor: pointer;
}
.shop-item:hover { border-color: var(--accent); }
.shop-item .ico { border: 0; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trade-side h3 { margin: 0 0 4px; font-size: 14px; }
.trade-grid { display: flex; flex-wrap: wrap; gap: 4px; min-height: 36px; }
.trade-coins { margin: 4px 0 0; color: var(--accent); font-size: 14px; }
.trade-coin-input { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.trade-coin-input input { width: 70px; font: 500 14px var(--font); color: var(--ink); background: var(--frame); border: 2px solid var(--plate-line); border-radius: 3px; padding: 2px 4px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
