:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --c-frei: #1f9d63;
  --c-beschaeftigt: #f0b429;
  --c-fokus: #d64535;
  --c-weg: #6b7280;

  --bg: #f4f4f1;
  --surface: #ffffff;
  --text: #1b1c1f;
  --muted: #6b6e76;
  --line: #e3e3de;
  --accent: #1b1c1f;
  --accent-text: #ffffff;
  --drift: translate(0, 0);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1c1d21;
    --text: #f1f1ee;
    --muted: #9a9ca3;
    --line: #2c2e33;
    --accent: #f1f1ee;
    --accent-text: #121316;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* =========================================================================
   ANZEIGE (Tür)
   ========================================================================= */

body.display {
  --tone: #16181d;
  --ink: #f5f5f2;
  --soft: rgba(255, 255, 255, .72);
  background: var(--tone);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  cursor: none;
}
/* Farbwechsel erst nach dem ersten Laden animieren. */
body.display.ready { transition: background-color .6s ease, color .6s ease; }
body.display[data-status="frei"]         { --tone: #17845a; --glow: #2fbf83; }
body.display[data-status="beschaeftigt"] { --tone: #e9a91c; --glow: #ffd36b; --ink: #2a1f00; --soft: rgba(42, 31, 0, .72); }
body.display[data-status="fokus"]        { --tone: #b8352a; --glow: #ef6a58; }
body.display[data-status="weg"]          { --tone: #3a3f4a; --glow: #5d6575; --soft: rgba(255, 255, 255, .62); }

body.display::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 90% 70% at 50% 28%, var(--glow, transparent) 0%, transparent 70%);
  opacity: .45;
  transition: opacity .6s ease;
  pointer-events: none;
}

.board {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0;
  padding: max(6vmin, env(safe-area-inset-top)) 7vmin max(12vmin, env(safe-area-inset-bottom));
  transform: var(--drift);
  transition: transform 4s ease;
}

.orb {
  width: 22vmin;
  height: 22vmin;
  border-radius: 50%;
  background: var(--ink);
  opacity: .92;
  margin-bottom: 6vmin;
  box-shadow: 0 0 0 2.4vmin color-mix(in srgb, var(--ink) 18%, transparent);
}
body.display[data-status="fokus"] .orb { animation: breathe 4s ease-in-out infinite; }
body.display[data-status="laden"] .orb { opacity: .15; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 2.4vmin color-mix(in srgb, var(--ink) 18%, transparent); }
  50%      { box-shadow: 0 0 0 4.2vmin color-mix(in srgb, var(--ink) 8%, transparent); }
}

.title {
  margin: 0;
  font-size: clamp(2.6rem, 13vmin, 9rem);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.sub {
  margin: 2.4vmin 0 0;
  font-size: clamp(1.1rem, 4.4vmin, 2.6rem);
  font-weight: 500;
  color: var(--soft);
}
.when {
  margin: 6vmin 0 0;
  padding: 1.6vmin 4vmin;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
  font-size: clamp(1.4rem, 7vmin, 4.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.reason {
  margin: 3.6vmin 0 0;
  max-width: 22ch;
  font-size: clamp(1.2rem, 5.4vmin, 3.2rem);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.next {
  margin: 5vmin 0 0;
  font-size: clamp(1rem, 3.6vmin, 2rem);
  font-weight: 600;
  color: var(--soft);
}

.display-foot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(3vmin, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.4vmin;
  font-size: clamp(.9rem, 3vmin, 1.6rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--soft);
  transform: var(--drift);
  transition: transform 4s ease;
}

.conn {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  opacity: .35;
}
.conn[data-state="ok"] { opacity: 0; }
.conn[data-state="off"], .conn[data-state="auth"] { background: #ff4d3d; opacity: 1; box-shadow: 0 0 0 3px rgba(255, 255, 255, .7); }
.control .conn[data-state="ok"] { background: var(--c-frei); opacity: 1; }

/* =========================================================================
   LOGIN (beide Seiten)
   ========================================================================= */

.login {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(92vw, 380px);
  height: fit-content;
  padding: 28px 24px;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  cursor: auto;
  user-select: auto;
  -webkit-user-select: auto;
}
.login h2 { margin: 0; font-size: 1.4rem; }
.login p { margin: 0; color: var(--muted); font-size: .95rem; line-height: 1.4; }

input[type="text"], input[type="password"], input[type="time"] {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
}
input:focus { outline: 2px solid var(--text); outline-offset: 1px; }

button { font: inherit; cursor: pointer; }
.login button, .primary {
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.05rem;
  font-weight: 700;
}
.primary:disabled { opacity: .5; }
.error { color: var(--c-fokus) !important; }

/* =========================================================================
   STEUERUNG
   ========================================================================= */

body.control { background: var(--bg); color: var(--text); }

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.head { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 0; }
.head h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }

.now {
  --c: var(--muted);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.now[data-status="frei"] { --c: var(--c-frei); }
.now[data-status="beschaeftigt"] { --c: var(--c-beschaeftigt); }
.now[data-status="fokus"] { --c: var(--c-fokus); }
.now[data-status="weg"] { --c: var(--c-weg); }
.now-dot { width: 40px; height: 40px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 20%, transparent); }
.now-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.now-title { font-size: 1.25rem; font-weight: 750; margin-top: 2px; }
.now-detail { font-size: .92rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.free-now {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 650;
  white-space: nowrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0; margin-bottom: 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.opt { text-transform: none; letter-spacing: 0; font-weight: 500; }

.statuses { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.statuses legend { grid-column: 1 / -1; }
.st {
  --c: var(--muted);
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--bg);
  font-weight: 650;
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.st[data-status="frei"] { --c: var(--c-frei); }
.st[data-status="beschaeftigt"] { --c: var(--c-beschaeftigt); }
.st[data-status="fokus"] { --c: var(--c-fokus); }
.st[data-status="weg"] { --c: var(--c-weg); }
.st input { position: absolute; opacity: 0; pointer-events: none; }
.st-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--c); flex: none; }
.st.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--surface)); }
.st:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; }

.details { display: flex; flex-direction: column; gap: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: .92rem;
  font-weight: 600;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.times label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 600; }
.times small { color: var(--muted); font-weight: 500; font-size: .8rem; }

.msg { margin: -6px 0 0; min-height: 1.2em; text-align: center; font-size: .92rem; color: var(--c-frei); font-weight: 600; }

.devices { gap: 10px; }
.devices summary { cursor: pointer; font-weight: 650; }
.devices p { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.45; }
.devices code { font-size: .88em; }
.link { align-self: flex-start; border: 0; background: none; padding: 0; color: var(--c-fokus); font-weight: 600; }
.times label, .statuses .st, .now > div { min-width: 0; }

/* =========================================================================
   VOLLBILD-HINWEIS & GEDRÜCKT-HALTEN (Türschild)
   ========================================================================= */

.hint {
  position: fixed;
  left: 50%;
  top: max(4vmin, env(safe-area-inset-top));
  transform: translateX(-50%);
  max-width: min(90vw, 520px);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: clamp(.85rem, 2.6vmin, 1.1rem);
  font-weight: 600;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: hint-in .4s ease;
  pointer-events: none;
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, -8px); } }

.hold {
  position: fixed;
  left: 0;
  bottom: 0;
  height: 6px;
  width: 0;
  background: var(--ink);
  opacity: .6;
  pointer-events: none;
}
.hold.on { width: 100%; transition: width 3s linear; }

/* =========================================================================
   STARTSEITE
   ========================================================================= */

.head-right { display: inline-flex; align-items: center; gap: 14px; }
.head-link { color: var(--text); font-weight: 650; font-size: .92rem; text-decoration: none; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }

.start { min-height: 100%; justify-content: center; gap: 14px; }
.start h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
.start-lead { margin: 0 0 8px; color: var(--muted); font-size: 1.05rem; }
.choice {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.choice:active { transform: scale(.99); }
.choice strong { display: block; font-size: 1.15rem; }
.choice small { display: block; margin-top: 4px; color: var(--muted); font-size: .92rem; line-height: 1.35; }
.choice-icon { flex: none; width: 52px; height: 52px; border-radius: 14px; position: relative; }
.choice-control { background: color-mix(in srgb, var(--c-frei) 16%, var(--bg)); }
.choice-control::before, .choice-control::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; top: 19px; }
.choice-control::before { left: 10px; background: var(--c-frei); }
.choice-control::after { right: 10px; background: var(--c-fokus); }
.choice-display { background: var(--c-fokus); }
.choice-display::after { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: #fff; opacity: .92; }
