:root {
  --night: #0f1b2d;
  --night-2: #1a2b45;
  --grass: #5fb04a;
  --grass-dark: #3d7f2f;
  --dirt: #7a5232;
  --dirt-dark: #5a3a22;
  --stone: #c9ced6;
  --ink: #f2f5f9;
  --muted: #93a3bb;
  --off: #8a93a3;
  --warn: #f2b23c;
  --bad: #e0574f;
  --panel: #162338;
  --line: #2b4062;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px 16px 140px; overflow-x: hidden; position: relative;
}

/* stelle pixel */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(2px 2px at 28% 42%, #fff6 50%, transparent 51%),
    radial-gradient(2px 2px at 47% 12%, #fff9 50%, transparent 51%),
    radial-gradient(2px 2px at 63% 35%, #fff6 50%, transparent 51%),
    radial-gradient(2px 2px at 78% 15%, #fff8 50%, transparent 51%),
    radial-gradient(2px 2px at 90% 48%, #fff5 50%, transparent 51%),
    radial-gradient(2px 2px at 6% 60%, #fff5 50%, transparent 51%);
}

/* terreno: erba + terra a blocchi */
.ground {
  position: fixed; left: 0; right: 0; bottom: 0; height: 112px; pointer-events: none;
  background:
    linear-gradient(var(--grass) 0 16px, var(--grass-dark) 16px 24px, transparent 24px),
    repeating-linear-gradient(90deg, #0003 0 2px, transparent 2px 32px),
    repeating-linear-gradient(0deg, #0003 0 2px, transparent 2px 32px),
    var(--dirt);
}
.ground::after {
  content: ""; position: absolute; inset: 24px 0 0 0;
  background:
    radial-gradient(circle at 20% 40%, var(--dirt-dark) 0 6px, transparent 7px),
    radial-gradient(circle at 55% 70%, var(--dirt-dark) 0 8px, transparent 9px),
    radial-gradient(circle at 85% 35%, var(--dirt-dark) 0 6px, transparent 7px);
}

main { width: 100%; max-width: 460px; position: relative; z-index: 1; }

h1 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(18px, 5vw, 26px);
  line-height: 1.5; text-align: center; margin-bottom: 6px;
  text-shadow: 3px 3px 0 #000a;
}
.sub { text-align: center; color: var(--muted); margin-bottom: 28px; font-size: 15px; }

.card {
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow: 0 0 0 4px #000a, 8px 8px 0 4px #0008;
  padding: 28px 24px 24px;
}

.status {
  display: flex; align-items: center; gap: 14px; margin-bottom: 22px;
}
.led {
  width: 20px; height: 20px; flex: none; background: var(--off);
  box-shadow: inset -3px -3px 0 #0004, inset 3px 3px 0 #fff3;
  transition: background .3s;
}
.status-text { font-family: "Press Start 2P", monospace; font-size: 14px; line-height: 1.4; }
.status small {
  display: block; margin-top: 6px; font-family: "DM Sans", sans-serif;
  font-size: 13px; color: var(--muted);
}

/* stati */
[data-state="chiuso"] .led { background: var(--off); }
[data-state="apertura"] .led { background: var(--warn); animation: blink .7s steps(2) infinite; }
[data-state="aperto"] .led { background: var(--grass); box-shadow: inset -3px -3px 0 #0004, inset 3px 3px 0 #fff3, 0 0 14px var(--grass); }
[data-state="chiusura"] .led { background: var(--bad); animation: blink .7s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* pulsante a blocco */
.btn {
  width: 100%; padding: 20px 16px; cursor: pointer;
  font-family: "Press Start 2P", monospace; font-size: 15px; color: #fff;
  background: var(--grass); border: 0;
  box-shadow: inset -5px -5px 0 #0004, inset 5px 5px 0 #fff3, 0 5px 0 var(--grass-dark), 0 5px 0 4px #000a;
  text-shadow: 2px 2px 0 #0006;
  transition: transform .08s, box-shadow .08s, background .2s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: inset -5px -5px 0 #0004, inset 5px 5px 0 #fff3, 0 1px 0 var(--grass-dark), 0 1px 0 4px #000a;
}
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.btn:disabled { cursor: progress; background: #6b7488; box-shadow: inset -5px -5px 0 #0004, inset 5px 5px 0 #fff2, 0 5px 0 #4c5466, 0 5px 0 4px #000a; }
[data-state="aperto"] .btn { background: var(--bad); box-shadow: inset -5px -5px 0 #0004, inset 5px 5px 0 #fff3, 0 5px 0 #a13a34, 0 5px 0 4px #000a; }
[data-state="aperto"] .btn:active:not(:disabled) { box-shadow: inset -5px -5px 0 #0004, inset 5px 5px 0 #fff3, 0 1px 0 #a13a34, 0 1px 0 4px #000a; }

/* info server */
.info { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 26px; }
.info div { background: #0e1829; border: 2px solid var(--line); padding: 10px 12px; }
.info dt { font-size: 12px; color: var(--muted); }
.info dd { margin: 2px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.info .wide { grid-column: 1 / -1; }
.ip { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.copy {
  background: none; border: 2px solid var(--line); color: var(--ink); cursor: pointer;
  font: inherit; font-size: 12px; padding: 3px 8px;
}
.copy:hover { border-color: var(--stone); }
.copy:focus-visible { outline: 2px solid #fff; }

/* log */
.log {
  margin-top: 18px; background: #080f1b; border: 2px solid var(--line);
  padding: 10px 12px; height: 110px; overflow-y: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 12px; color: #a9b9d0;
}
.log p { margin: 0 0 3px; }
.log time { color: #5f7396; margin-right: 8px; }

@media (prefers-reduced-motion: reduce) {
  .led { animation: none !important; }
  .btn { transition: none; }
}
