:root {
  --nacht: #0b1020;
  --text: #1d2230;
  --text-leise: #6b7285;
  --linie: #e4e6ec;
  --akzent: #c8342b;
  --akzent-hell: #fbe9e7;
  --fenster: #fbfbfd;
  --kopf: #f1f2f6;
  --ungelesen: #2f6fde;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--nacht);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#welt, #welt canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* Ladebildschirm */
#laden {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(circle at 50% 40%, #1b2547, var(--nacht) 70%);
  color: #e9ecf5; transition: opacity .6s ease;
}
#laden.weg { opacity: 0; pointer-events: none; }
.laden-stern { font-size: 46px; color: #ffd27a; animation: funkeln 1.6s ease-in-out infinite; }
.laden-text { font-size: 15px; letter-spacing: .02em; opacity: .85; }
.laden-balken { width: 180px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.15); overflow: hidden; }
#laden-fortschritt { width: 0; height: 100%; background: #ffd27a; transition: width .2s; }
@keyframes funkeln { 0%,100% { transform: scale(1) rotate(0); opacity: .8 } 50% { transform: scale(1.18) rotate(20deg); opacity: 1 } }

/* Hinweis */
#hinweis {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px;
  background: rgba(12, 16, 32, .72); color: #fff; font-size: 15px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: pulsieren 2.2s ease-in-out infinite;
  pointer-events: none; white-space: nowrap;
}
@keyframes pulsieren { 0%,100% { opacity: .65 } 50% { opacity: 1 } }

/* Das Spiel ist fuer Querformat gebaut: im Hochformat bitten wir ums Kippen */
#hochformat { display: none; }
@media (orientation: portrait) {
  #hochformat {
    display: flex; flex-direction: column; gap: 18px; position: fixed; inset: 0; z-index: 50;
    align-items: center; justify-content: center; text-align: center; padding: 24px;
    background: radial-gradient(circle at 50% 40%, #1b2547, var(--nacht) 70%); color: #fff; font-size: 18px;
  }
  #hochformat .kipp-handy {
    width: 54px; height: 92px; border: 4px solid #ffd27a; border-radius: 10px;
    animation: kippen 2.4s ease-in-out infinite;
  }
}
@keyframes kippen { 0%, 25% { transform: rotate(0) } 55%, 85% { transform: rotate(-90deg) } 100% { transform: rotate(0) } }

#vollbild {
  position: fixed; right: calc(14px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top)); z-index: 12;
  padding: 8px 12px; border-radius: 999px; border: 0; font: inherit; font-size: 14px;
  background: rgba(12, 16, 32, .72); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#vollbild[hidden] { display: none; }

/* Mail-Programm */
#mail { position: fixed; z-index: 20; inset: 0; pointer-events: none; }
#mail[hidden] { display: none; }
.mail-fenster {
  position: absolute; display: flex; flex-direction: column; overflow: hidden;
  background: var(--fenster); border-radius: 0; pointer-events: auto;
  transform-origin: 0 0;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.mail-kopf {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  background: var(--kopf); border-bottom: 1px solid var(--linie);
}
.mail-titel { grid-column: 2; margin: 0; font-size: 17px; font-weight: 650; }
.mail-kopf button {
  border: 0; background: none; font: inherit; color: var(--akzent); padding: 8px 6px; cursor: pointer;
}
.mail-zurueck { grid-column: 1; justify-self: start; font-size: 16px; }
.mail-schliessen { grid-column: 3; justify-self: end; font-size: 18px; width: 40px; height: 40px; border-radius: 50% !important; }
.mail-schliessen:active, .mail-zurueck:active { background: rgba(0,0,0,.06) !important; }

.mail-inhalt { position: relative; flex: 1; overflow: hidden; }
.mail-liste, .mail-detail {
  position: absolute; inset: 0; margin: 0; padding: 0; list-style: none;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
}
.mail-liste.versteckt { transform: translateX(-30%); }
.mail-detail { background: var(--fenster); transform: translateX(100%); }
.mail-detail.offen { transform: translateX(0); }
.mail-detail[hidden] { display: block; visibility: hidden; }

.mail-eintrag {
  display: grid; grid-template-columns: 12px 42px minmax(0, 1fr); gap: 0 10px; align-items: start;
  padding: 14px 16px 14px 8px; border-bottom: 1px solid var(--linie); cursor: pointer;
}
.mail-eintrag:active { background: #eef1f8; }
.mail-punkt { width: 9px; height: 9px; border-radius: 50%; margin-top: 16px; background: var(--ungelesen); }
.mail-eintrag.gelesen .mail-punkt { visibility: hidden; }
.mail-avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--akzent-hell); color: var(--akzent); font-weight: 700; font-size: 17px;
}
.mail-zeile1 { display: flex; justify-content: space-between; gap: 8px; }
.mail-von { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-zeit { color: var(--text-leise); font-size: 13px; flex: none; }
.mail-betreff { font-size: 14.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-eintrag:not(.gelesen) .mail-betreff { font-weight: 600; }
.mail-vorschau {
  color: var(--text-leise); font-size: 13.5px; margin-top: 3px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.mail-detail { padding: 18px 18px calc(40px + env(safe-area-inset-bottom)); user-select: text; -webkit-user-select: text; }
.mail-detail h2 { margin: 0 0 14px; font-size: 21px; line-height: 1.25; }
.mail-absender { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--linie); }
.mail-absender .mail-avatar { flex: none; }
.mail-absender-name { font-weight: 650; }
.mail-absender-adresse, .mail-absender-datum { color: var(--text-leise); font-size: 13px; }
.mail-text { font-size: 16px; line-height: 1.55; padding-top: 14px; }
.mail-text p { margin: 0 0 12px; }

.mail-leer { padding: 40px 20px; text-align: center; color: var(--text-leise); }

/* Schneemann-Marsch (Pixelspiel auf dem Notebook) */
#spiel { position: fixed; z-index: 20; inset: 0; pointer-events: none; }
#spiel[hidden] { display: none; }
.spiel-fenster {
  position: absolute; display: flex; flex-direction: column; overflow: hidden; pointer-events: auto;
  background: #1a1423; color: #f4f1ea; font-family: ui-monospace, "Courier New", monospace;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.spiel-kopf {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px; background: #2e2236; border-bottom: 2px solid #4a3a4f;
}
.spiel-status { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; font-weight: 700; color: #e6c58a; }
.spiel-schliessen { border: 2px solid #6b5a6e; background: #4a3a4f; color: #f4f1ea; width: 38px; height: 38px; font: inherit; font-size: 16px; }
.spiel-feld { position: relative; flex: none; width: 100%; aspect-ratio: 320 / 176; background: #1c2a4f; }
.spiel-feld canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; }
.spiel-meldung {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(26, 20, 35, .72); padding: 8px;
}
.spiel-meldung[hidden] { display: none; }
.spiel-karte {
  max-width: 92%; max-height: 100%; overflow: auto; background: #2e2236; border: 3px solid #9cc3e6; padding: 10px 12px;
  font-size: 13px; line-height: 1.4; text-align: center; box-shadow: 4px 4px 0 #1a1423;
}
.spiel-karte h2 { margin: 0 0 6px; font-size: 15px; color: #9cc3e6; }
.spiel-karte p { margin: 4px 0; }
.spiel-karte button, .spiel-steuerung button, .spiel-knopf {
  font: inherit; color: #f4f1ea; background: #4a3a4f; border: 2px solid #6b5a6e; padding: 6px 10px; margin: 3px;
  box-shadow: 2px 2px 0 #1a1423;
}
.spiel-karte button:active, .spiel-steuerung button:active, .spiel-knopf:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #1a1423; }
.spiel-levelwahl { display: flex; flex-direction: column; align-items: stretch; margin-top: 6px; }
.spiel-levelwahl button:disabled { opacity: .4; }
.spiel-faehigkeiten { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 8px 4px; }
.spiel-knopf {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; padding: 6px 2px 4px;
  color: #c8e39a;
}
.spiel-knopf .zahl { position: absolute; top: 2px; right: 5px; font-size: 13px; font-weight: 700; color: #f2d36b; }
.spiel-knopf .name { font-size: 11px; color: #dcd6d6; }
.spiel-knopf.gewaehlt { border-color: #f2d36b; background: #74462a; }
.spiel-knopf.leer { opacity: .45; }
.spiel-steuerung { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; padding: 4px 8px calc(12px + env(safe-area-inset-bottom)); }
.spiel-steuerung .freigabe { min-width: 28px; text-align: center; font-weight: 700; color: #e6c58a; }
.spiel-steuerung .an { border-color: #f2d36b; }
.spiel-steuerung .tauwetter { background: #6e2a26; border-color: #a33a2e; }

/* Querformat: Spielfeld links so gross wie moeglich, Bedienung rechts */
@media (orientation: landscape) {
  .spiel-fenster {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr);
  }
  .spiel-kopf { grid-column: 1 / 3; padding: 6px calc(8px + env(safe-area-inset-right)) 6px calc(8px + env(safe-area-inset-left)); }
  .spiel-schliessen { width: 34px; height: 34px; }
  .spiel-feld {
    grid-column: 1; grid-row: 2; width: auto; height: 100%; max-width: 100%; aspect-ratio: 320 / 176;
    justify-self: center; align-self: center; margin-left: env(safe-area-inset-left);
  }
  .spiel-seite { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; overflow-y: auto; width: 190px; padding-right: env(safe-area-inset-right); }
  .spiel-faehigkeiten { grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 6px 6px 2px; }
  .spiel-knopf { padding: 3px 2px 2px; }
  .spiel-knopf svg { width: 18px; height: 18px; }
  .spiel-knopf .name { font-size: 10px; }
  .spiel-steuerung { padding: 4px 4px 8px; gap: 0; }
  .spiel-steuerung button { padding: 4px 7px; margin: 2px; }
}
@media (orientation: portrait) { .spiel-seite { display: contents; } }

/* Mail im Querformat: Lesespalte nicht ueber die ganze Breite ziehen */
@media (orientation: landscape) {
  .mail-liste, .mail-detail { padding-left: max(env(safe-area-inset-left), calc((100% - 760px) / 2)); padding-right: max(env(safe-area-inset-right), calc((100% - 760px) / 2)); }
  .mail-kopf { padding-top: 8px; padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }
}

/* Virtueller Joystick: ruht unten links als Hinweis, springt beim Beruehren unter den Finger */
#joystick {
  position: fixed; z-index: 9; width: 112px; height: 112px; margin: -56px 0 0 -56px;
  left: calc(84px + env(safe-area-inset-left)); top: calc(100% - 84px - env(safe-area-inset-bottom));
  border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(12,16,32,.22);
  pointer-events: none; opacity: .55; transition: opacity .2s;
}
#joystick.aktiv { opacity: 1; transition: none; background: rgba(12,16,32,.35); }
.joystick-knopf {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  background: rgba(255,255,255,.75); box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
#joystick:not(.aktiv) .joystick-knopf { transition: transform .15s ease-out; }

/* weicher, warmer Rand fuer eine gemuetlichere Stimmung */
#vignette { position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(40,20,5,.38) 100%); }
