:root {
  --ink: #1a2420;
  --muted: #5d6b64;
  --paper: rgba(247, 243, 234, 0.78);
  --paper-solid: #f7f3ea;
  --line: rgba(26, 36, 32, 0.12);
  --amber: #d97706;
  --amber-soft: #fde68a;
  --forest: #1f6b4a;
  --forest-deep: #0f3d2c;
  --danger: #9a3412;
  --shadow: 0 18px 50px rgba(15, 30, 24, 0.18);
  --radius: 22px;
  --font: "Instrument Sans", "Segoe UI", sans-serif;
  --display: "Newsreader", Georgia, serif;
}

* {
  box-sizing: border-box;
}

/* Any display utility (flex, grid) would otherwise override the hidden
   attribute; this guarantees [hidden] always hides its element. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: #0d1a14;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 55% at 15% 10%, rgba(250, 204, 21, 0.22), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 0%, rgba(34, 120, 80, 0.35), transparent 50%),
    linear-gradient(165deg, #12261c 0%, #1a3328 42%, #0c1612 100%);
}

.shell {
  width: min(980px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.25rem 0 3.5rem;
}

.top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #d9e7df;
  opacity: 0.8;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  line-height: 0.95;
  color: #f6f1e6;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 0.55rem;
}

.top-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta {
  margin: 0;
  color: #c9d8cf;
  font-size: 0.88rem;
}

.status {
  min-height: 1.25rem;
  margin: 0 0 1.5rem;
  color: #e7d7a8;
  font-size: 0.92rem;
}

.section {
  margin-bottom: 1.75rem;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.section-head-copy {
  min-width: 0;
}

.section-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  color: #f4eee3;
}

.section-head p {
  margin: 0.25rem 0 0;
  color: #b7c7be;
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem;
}

.watch-over-status {
  margin-top: 2.5rem;
  color: #c9d8cf;
}

.watch-over-status h3 {
  margin: 0 0 0.55rem;
  color: #e7d7a8;
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.watch-over-status ul {
  display: grid;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.watch-over-status li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.55rem;
  color: #c9d8cf;
  font-size: 0.84rem;
}

.watch-over-status li strong {
  color: #f4eee3;
}

.watch-over-status li.watch-over-tracked span {
  color: #bef264;
}

.card {
  background: var(--paper);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem 1.15rem;
  box-shadow: var(--shadow);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.card.is-open {
  border-color: rgba(22, 163, 74, 0.6);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16), var(--shadow);
}

.card.is-closed {
  border-color: rgba(220, 38, 38, 0.58);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15), var(--shadow);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 55px rgba(15, 30, 24, 0.22);
}

.card.is-open:hover {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2), 0 22px 55px rgba(15, 30, 24, 0.22);
}

.card.is-closed:hover {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2), 0 22px 55px rgba(15, 30, 24, 0.22);
}

.card.is-busy {
  opacity: 0.72;
  pointer-events: none;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
  margin-bottom: 0.95rem;
}

.card h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.badge {
  flex: none;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(26, 36, 32, 0.08);
  color: var(--muted);
}

.badge.on {
  background: rgba(217, 119, 6, 0.18);
  color: #92400e;
}

.badge.open {
  background: #dcfce7;
  border: 1px solid #4ade80;
  color: #166534;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.2);
}

.badge.closed {
  background: #fee2e2;
  border: 1px solid #f87171;
  color: #991b1b;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.2);
}

.badge.open,
.badge.closed {
  padding: 0.38rem 0.72rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.badge.moving {
  background: rgba(37, 99, 235, 0.14);
  color: #1e3a8a;
}

.position {
  margin: 0 0 0.95rem;
}

.position-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.position-label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.position-value {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  text-align: right;
}

.position-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(26, 36, 32, 0.1);
  overflow: hidden;
}

.position-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f8f63, #1f6b4a 55%, #334155);
  transition: width 280ms ease;
}

.position-hint {
  display: flex;
  justify-content: space-between;
  margin-top: 0.28rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.dimmer-range {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2f8f63, #b98a2e);
  cursor: pointer;
  outline: none;
}

.dimmer-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f6f1e6;
  border: 2px solid #1f6b4a;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.dimmer-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f6f1e6;
  border: 2px solid #1f6b4a;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.dimmer.is-off .dimmer-range {
  background: rgba(26, 36, 32, 0.12);
}

.dimmer.is-off .dimmer-range::-webkit-slider-thumb,
.dimmer.is-off .dimmer-range::-moz-range-thumb {
  background: #cbd5d1;
  border-color: #94a3b8;
}

.dimmer.is-off .position-value {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
}

.ghost {
  background: rgba(246, 241, 230, 0.12);
  color: #f6f1e6;
  border: 1px solid rgba(246, 241, 230, 0.22);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.86rem;
  font-weight: 500;
}

.ghost:hover {
  background: rgba(246, 241, 230, 0.2);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.icon-button.is-active {
  color: #102d20;
  background: #d9f99d;
  border-color: #bef264;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.58rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  background: var(--forest);
  transition: filter 120ms ease, transform 120ms ease;
}

.btn svg {
  flex: none;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:active {
  transform: scale(0.98);
}

.btn.off {
  background: #4b5563;
}

.btn.open {
  background: var(--forest);
}

.btn.reload {
  background: #4b5563;
}

.btn.close {
  background: #334155;
}

.btn.stop {
  background: var(--danger);
}

.btn.light-on {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #1f1305;
}

.empty {
  grid-column: 1 / -1;
  color: #c9d8cf;
  padding: 0.5rem 0.1rem;
}

/* --- layout editing --- */
.layout-section[draggable="true"] .section-head {
  cursor: grab;
}

.layout-section[draggable="true"] .section-head:active,
.card[draggable="true"]:active {
  cursor: grabbing;
}

.section-move-controls {
  display: none;
  flex: none;
  gap: 0.3rem;
}

.shell.is-editing .section-move-controls {
  display: flex;
}

.layout-move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(217, 231, 223, 0.42);
  border-radius: 9px;
  background: rgba(246, 241, 230, 0.1);
  color: #f6f1e6;
  font-size: 1.2rem;
  line-height: 1;
}

.layout-move:hover:not(:disabled) {
  background: rgba(190, 242, 100, 0.24);
  border-color: #bef264;
}

.layout-move:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.shell.is-editing .layout-section {
  padding: 0.85rem;
  border: 1px dashed rgba(217, 231, 223, 0.55);
  border-radius: 18px;
  background: rgba(246, 241, 230, 0.06);
}

.card[draggable="true"] {
  cursor: grab;
}

.is-dragging {
  opacity: 0.38;
}

.layout-section.is-drag-over {
  border-color: #bef264;
  background: rgba(190, 242, 100, 0.12);
}

.grid.is-drag-over {
  outline: 2px dashed #bef264;
  outline-offset: 0.35rem;
  border-radius: 12px;
}

/* --- confirmation modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 20, 16, 0.6);
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(430px, 100%);
  background: var(--paper-solid);
  color: var(--ink);
  border: 1px solid rgba(26, 36, 32, 0.08);
  border-radius: var(--radius);
  padding: 1.6rem 1.7rem 1.4rem;
  box-shadow: var(--shadow);
  animation: modal-in 180ms ease;
}

.modal-title {
  margin: 0 0 0.55rem;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.45rem;
  color: var(--forest-deep);
}

.modal-text {
  margin: 0 0 1.5rem;
  font-size: 0.97rem;
  line-height: 1.55;
  color: #374151;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 640px) {
  .top {
    flex-direction: column;
    align-items: start;
  }

  .top-actions {
    align-items: start;
  }
}

/* --- login --- */
.login {
  width: min(430px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3rem 0;
}

.login-card {
  background: var(--paper-solid);
  color: var(--ink);
  border: 1px solid rgba(26, 36, 32, 0.08);
  border-radius: var(--radius);
  padding: 2rem 2rem 1.5rem;
  box-shadow: var(--shadow);
  animation: modal-in 180ms ease;
}

.login-title {
  margin: 0 0 0.75rem;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.8rem;
  color: var(--forest-deep);
}

.login-note {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #374151;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#codeForm {
  margin-top: 1.75rem;
}

.login-form label {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.login-form input {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(26, 36, 32, 0.18);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  outline: none;
}

.login-form input:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(31, 107, 74, 0.18);
}

.login-form button[type="submit"] {
  margin-top: 0.5rem;
  justify-content: center;
}

.login-status {
  min-height: 1.25rem;
  margin: 1rem 0 0;
  font-size: 0.9rem;
  color: var(--forest-deep);
}
