  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg: #291532;
    --surface: #472755;
    --accent: #765386;
    --text: #f6f1f9;
    --muted: #ad9ab6;
    --gold: #fcb900;
    --gold-dim: rgba(252, 185, 0, 0.15);
    --red: #e53935;
    --en-blue: #4fc3f7;
    --header-h: auto;
  }

  html { scroll-behavior: smooth; }

  body {
    font-family: 'Lato', sans-serif;
    font-size: 14px;
    color: var(--text);
    background-color: var(--bg);
    background-image:
      radial-gradient(ellipse 120% 60% at 50% -10%, rgba(118, 83, 134, 0.45) 0%, transparent 70%),
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='12' cy='8' r='1' fill='%23fcb900' opacity='.2'/%3E%3Ccircle cx='45' cy='22' r='.8' fill='%23fcb900' opacity='.2'/%3E%3Ccircle cx='28' cy='48' r='1.2' fill='%23fcb900' opacity='.2'/%3E%3Ccircle cx='55' cy='52' r='.6' fill='%23fcb900' opacity='.2'/%3E%3Ccircle cx='8' cy='38' r='.7' fill='%23fcb900' opacity='.2'/%3E%3C/svg%3E");
    min-height: 100vh;
    line-height: 1.45;
  }

  /* Header */
  .header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(41, 21, 50, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(118, 83, 134, 0.4);
    padding: 12px 16px 10px;
  }

  .header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 16px;
    margin-bottom: 10px;
  }

  .header h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.04em;
  }

  .counters {
    font-size: 0.85rem;
    color: var(--muted);
  }

  .counters strong { color: var(--text); }

  .filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .filters input[type="search"],
  .filters select {
    background: var(--surface);
    border: 1px solid rgba(118, 83, 134, 0.5);
    color: var(--text);
    border-radius: 6px;
    padding: 6px 10px;
    font-family: 'Lato', sans-serif;
    font-size: 0.85rem;
    outline: none;
  }

  .filters input[type="search"] { flex: 1 1 180px; min-width: 140px; }
  .filters input[type="search"]:focus,
  .filters select:focus { border-color: var(--gold); }

  .filters select { cursor: pointer; }

  .day-chips {
    display: flex;
    gap: 4px;
  }

  .chip {
    background: var(--surface);
    border: 1px solid rgba(118, 83, 134, 0.5);
    color: var(--muted);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: 'Lato', sans-serif;
    transition: all 0.15s;
  }

  .chip:hover { border-color: var(--gold); color: var(--text); }
  .chip.active {
    background: var(--gold-dim);
    border-color: var(--gold);
    color: var(--gold);
  }

  .toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--muted);
    user-select: none;
    white-space: nowrap;
  }

  .toggle input { accent-color: var(--gold); cursor: pointer; }
  .toggle.active { color: var(--gold); }

  /* Offline badge */
  .offline-badge {
    display: none;
    background: var(--gold);
    color: var(--bg);
    text-align: center;
    padding: 6px 16px;
    font-size: 0.8rem;
    font-weight: 700;
  }

  .offline-badge.visible { display: block; }

  /* Loading / Error */
  .status-msg {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
  }

  .status-msg.error { color: #ff8a80; }

  .spinner {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid rgba(252, 185, 0, 0.2);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  /* Main list */
  main { padding: 12px 16px 80px; max-width: 2200px; margin: 0 auto; }

  .time-group { margin-bottom: 18px; }

  .time-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 9px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(118, 83, 134, 0.3);
  }

  .time-group-header .time {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold);
  }

  .time-group-header .day-label {
    font-size: 0.8rem;
    color: var(--muted);
  }

  .time-group-header .count {
    font-size: 0.75rem;
    color: var(--muted);
    background: rgba(118, 83, 134, 0.3);
    padding: 1px 7px;
    border-radius: 10px;
  }

  .live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    animation: pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
  }

  .live-label {
    font-size: 0.7rem;
    color: var(--red);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* Cards grid */
  .cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 9px;
  }

  .card {
    position: relative;
    display: flex;
    background: linear-gradient(135deg, rgba(71, 39, 85, 0.7) 0%, rgba(41, 21, 50, 0.88) 100%);
    border: 1px solid rgba(118, 83, 134, 0.35);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  }

  .card:hover {
    transform: translateY(-2px);
    border-color: var(--gold);
    box-shadow: 0 4px 16px rgba(252, 185, 0, 0.12);
  }

  .card-bar {
    width: 3px;
    flex-shrink: 0;
  }

  .card-body {
    padding: 10px 12px 10px 10px;
    flex: 1;
    min-width: 0;
  }

  .badge-now {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--red);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.06em;
  }

  .card-row1 {
    display: flex;
    gap: 8px;
    align-items: baseline;
    margin-bottom: 4px;
    padding-right: 48px;
  }

  .card-time {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    color: var(--gold);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .card-title {
    font-weight: 700;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .card-row2 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .hall-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .card-row2 .hall { font-weight: 700; color: var(--text); }
  .card-row2 .room { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .card-row3 {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .tag {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .tag-cat { background: rgba(118, 83, 134, 0.5); color: var(--text); }
  .tag-en { background: rgba(79, 195, 247, 0.2); color: var(--en-blue); }
  .tag-level { background: rgba(252, 185, 0, 0.12); color: var(--gold); }
  .tag-reg { background: rgba(173, 154, 182, 0.2); color: var(--muted); }

  /* Modal */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(20, 10, 25, 0.82);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 16px;
  }

  .modal-overlay.open { display: flex; }

  .modal {
    background: var(--bg);
    border: 1px solid rgba(118, 83, 134, 0.5);
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
  }

  .modal-top-bar { height: 4px; border-radius: 12px 12px 0 0; }

  .modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    z-index: 1;
    padding: 4px;
  }

  .modal-close:hover { color: var(--gold); }

  .modal-content { padding: 20px 24px 24px; }

  .modal-eyebrow {
    font-family: 'Cinzel', serif;
    color: var(--gold);
    font-size: 0.85rem;
    margin-bottom: 8px;
  }

  .modal-title {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 16px;
    line-height: 1.3;
    padding-right: 24px;
  }

  .modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    margin-bottom: 16px;
    font-size: 0.85rem;
  }

  .modal-grid dt {
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .modal-grid dd { font-weight: 700; }

  .modal-desc {
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 16px;
    white-space: pre-wrap;
  }

  .modal-tags { display: flex; flex-wrap: wrap; gap: 5px; }

  /* Scroll to top */
  .scroll-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 90;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--gold);
    color: var(--gold);
    font-size: 1.2rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  }

  .scroll-top.visible { display: flex; }
  .scroll-top:hover { background: var(--gold-dim); transform: translateY(-2px); }

  /* TV */
  @media (min-width: 1400px) {
    .cards-grid { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
  }

  @media (min-width: 1800px) {
    body { font-size: 16px; }
    .cards-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
    .header h1 { font-size: 1.6rem; }
  }

  @media (max-width: 600px) {
    .modal-grid { grid-template-columns: 1fr; }
  }

  /* Kiosk */
  body.kiosk { font-size: 15px; }

  body.kiosk .header h1 { font-size: 1.35rem; }

  body.kiosk .page-subtitle {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 4px;
  }

  body.kiosk-index .header { display: none; }

  .loc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
  }

  .loc-card {
    display: block;
    padding: 20px 22px;
    background: var(--surface);
    border: 1px solid rgba(252, 185, 0, 0.25);
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, transform 0.15s, background 0.15s;
  }

  .loc-card:hover {
    border-color: var(--gold);
    background: rgba(71, 39, 85, 0.85);
    transform: translateY(-2px);
  }

  .loc-card h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.05rem;
    color: var(--gold);
    margin-bottom: 8px;
  }

  .loc-card p {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.45;
  }

  .kiosk-index-header {
    text-align: center;
    padding: 32px 24px 8px;
  }

  .kiosk-index-header h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    color: var(--gold);
    margin-bottom: 8px;
  }

  .kiosk-index-header p { color: var(--muted); }

  @media (min-width: 1800px) {
    body.kiosk { font-size: 17px; }
    body.kiosk .header h1 { font-size: 1.75rem; }
    body.kiosk .card-title { font-size: 1.05rem; }
  }

  /* Status */
  body.status-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 20px 48px;
  }

  .status-panel {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 1px solid rgba(252, 185, 0, 0.3);
    border-radius: 12px;
    padding: 28px 32px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  }

  .status-panel h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: 6px;
  }

  .status-panel .lead {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
  }

  .status-rows { display: grid; gap: 14px; }

  .status-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.92rem;
  }

  .status-row:last-child { border-bottom: none; padding-bottom: 0; }

  .status-row dt { color: var(--muted); flex-shrink: 0; }

  .status-row dd {
    text-align: right;
    font-weight: 700;
    word-break: break-word;
  }

  .status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .status-badge.ok {
    background: rgba(32, 137, 0, 0.25);
    color: #7dffb0;
  }

  .status-badge.warn {
    background: rgba(252, 185, 0, 0.2);
    color: var(--gold);
  }

  .status-badge.bad {
    background: rgba(229, 57, 53, 0.2);
    color: #ff8a80;
  }

  .status-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
  }

  .status-btn {
    flex: 1;
    min-width: 140px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--gold);
    background: transparent;
    color: var(--gold);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s;
  }

  .status-btn:hover { background: var(--gold-dim); }

  .status-btn.primary {
    background: var(--gold);
    color: var(--bg);
    border-color: var(--gold);
  }

  .status-btn.primary:hover { filter: brightness(1.05); }

  .status-msg-inline {
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--muted);
    min-height: 1.2em;
  }

  .status-msg-inline.error { color: #ff8a80; }
  .status-msg-inline.ok { color: #7dffb0; }

  .status-panel-wide { max-width: 1100px; }

  .status-summary {
    font-size: 0.92rem;
    color: var(--muted);
    margin-bottom: 20px;
  }

  .status-summary strong { color: var(--text); }

  .summary-ok { color: #7dffb0; }
  .summary-warn { color: var(--gold); }
  .summary-bad { color: #ff8a80; }

  .device-table-wrap {
    overflow-x: auto;
    margin-bottom: 8px;
  }

  .device-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
  }

  .device-table th,
  .device-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }

  .device-table th {
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
  }

  .device-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

  .device-empty {
    text-align: center;
    color: var(--muted);
    padding: 32px 16px !important;
  }

  .device-link {
    color: var(--gold);
    text-decoration: none;
    font-weight: 700;
  }

  .device-link:hover { text-decoration: underline; }

  .device-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
  }

  .device-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 11px;
    border-radius: 999px;
    border: 1px solid rgba(252, 185, 0, 0.35);
    background: rgba(41, 21, 50, 0.55);
    color: var(--gold);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.12s, box-shadow 0.15s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  }

  .device-action:hover {
    background: var(--gold-dim);
    border-color: var(--gold);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  }

  .device-action:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
  }

  .device-action-open {
    background: linear-gradient(180deg, #fdd040 0%, var(--gold) 100%);
    color: var(--bg);
    border-color: #fdd040;
  }

  .device-action-open:hover {
    background: linear-gradient(180deg, #ffe082 0%, #fdd040 100%);
    border-color: #ffe082;
    filter: none;
  }

  .device-action-add {
    border-color: rgba(125, 255, 176, 0.45);
    color: #9effc4;
    background: rgba(32, 137, 0, 0.12);
  }

  .device-action-add:hover {
    background: rgba(32, 137, 0, 0.28);
    border-color: #7dffb0;
  }

  .device-action-danger {
    border-color: rgba(255, 138, 128, 0.4);
    color: #ffab9e;
    background: rgba(229, 57, 53, 0.1);
  }

  .device-action-danger:hover {
    background: rgba(229, 57, 53, 0.22);
    border-color: #ff8a80;
  }

  .device-action:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  .device-table td:last-child {
    white-space: nowrap;
    width: 1%;
  }
