/* ===== המסך המפוצל — עיצוב כהה, גדול וברור (ידידותי לכל גיל) ===== */

:root {
  --bg: #0c0e12;
  --bg-raised: #14171d;
  --bg-tile: #181c23;
  --border: #2b313d;
  --text: #f1f3f8;
  --text-dim: #9aa3b2;
  --accent: #4da3ff;
  --danger: #e5484d;
  --live: #30c97e;
  --topbar-h: 64px;
  --hintbar-h: 40px;
  --channelbar-h: 84px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Heebo", Arial, sans-serif;
  font-size: 16px;
  overflow: hidden;
}

/* ===== סרגל עליון ===== */

#topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background:
    linear-gradient(45deg, var(--accent) 48%, transparent 48%) 0 0 / 50% 50% no-repeat,
    linear-gradient(45deg, #e63946 48%, transparent 48%) 100% 0 / 50% 50% no-repeat,
    linear-gradient(45deg, #2a9d8f 48%, transparent 48%) 0 100% / 50% 50% no-repeat,
    linear-gradient(45deg, #f4a261 48%, transparent 48%) 100% 100% / 50% 50% no-repeat;
  background-color: #2c3340;
}

#topbar h1 { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: .3px; }

#clock {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text-dim);
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 9px;
}

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

#volume-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-tile);
  padding: 0 13px;
  height: 48px;
}
#volume-icon { font-size: 18px; }
#volume {
  width: 130px;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* כפתורי פעולה — אייקון גדול + תווית טקסט מתחת */
.icon-btn {
  min-width: 64px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-tile);
  color: var(--text);
  cursor: pointer;
  padding: 0 10px;
  transition: background .15s, border-color .15s;
}
.icon-btn .ic { font-size: 19px; line-height: 1; }
.icon-btn .lbl { font-size: 12px; color: var(--text-dim); }
.icon-btn:hover { background: #1f242e; border-color: #3a4150; }
.icon-btn:hover .lbl { color: var(--text); }
.icon-btn.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.icon-btn.active .lbl { color: var(--accent); }

/* ===== פס הנחיה קבוע ===== */

#hintbar {
  height: var(--hintbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #101a2b;
  border-bottom: 1px solid var(--border);
  color: #cfe0f5;
  font-size: 15px;
  padding: 0 14px;
  position: relative;
  z-index: 29;
}
#hintbar[hidden] { display: none; }
#hintbar b { color: #fff; }
#hint-close {
  position: absolute;
  inset-inline-start: 12px;
  border: 0;
  background: transparent;
  color: #7e93b0;
  font-size: 17px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 6px;
}
#hint-close:hover { color: #fff; background: #1c2740; }

/* ===== אזור הגריד ===== */

#stage {
  position: relative;
  height: calc(100% - var(--topbar-h) - var(--hintbar-h) - var(--channelbar-h));
  overflow-y: auto;
  padding: 8px;
}
body.hint-hidden #stage { height: calc(100% - var(--topbar-h) - var(--channelbar-h)); }

#empty-hint[hidden] { display: none; }

#empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}
#empty-hint p { margin: 6px 0; font-size: 24px; color: var(--text); }
#empty-hint .sub { font-size: 17px; color: var(--text-dim); }

/* ===== אריח ערוץ ===== */

.grid-stack-item-content {
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, box-shadow .15s;
}

.grid-stack-item.audio-on .grid-stack-item-content {
  border-color: var(--live);
  box-shadow: 0 0 0 2px var(--live), 0 0 22px rgba(48, 201, 126, .3);
}

.tile-header {
  direction: rtl;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  background: rgba(20, 23, 29, .92);
  cursor: grab;
  user-select: none;
  flex: 0 0 auto;
}
.tile-header:active { cursor: grabbing; }

.tile-dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }

.tile-name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.tile-audio-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--live);
  display: none;
  white-space: nowrap;
}
.grid-stack-item.audio-on .tile-audio-badge { display: inline; }

.tile-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 7px;
  line-height: 1;
}
.tile-btn:hover { color: var(--text); background: #2a303c; }
.tile-btn.close:hover { color: #fff; background: var(--danger); }

.tile-body { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }

.tile-body video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: pointer;
}

/* רמז שמע על אריח שאינו משמיע כרגע */
.tap-hint {
  position: absolute;
  inset-block-end: 10px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  background: rgba(12, 14, 18, .82);
  color: #dfe6f1;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.grid-stack-item.audio-on .tap-hint { display: none; }
body.audio-learned .tap-hint { display: none; }
/* פינוי מקום לסרגל ההרצה אחורה כשהוא על המסך */
.tile-body:hover .tap-hint,
.tile-dvr:not([hidden]):not(.at-live) ~ .tap-hint { display: none; }
@media (hover: none) { .tile-dvr:not([hidden]) ~ .tap-hint { display: none; } }

/* ===== בקרת הרצה אחורה בשידור החי (DVR) ===== */

.tile-dvr {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  direction: ltr;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(8, 10, 14, .94), rgba(8, 10, 14, .55) 75%, transparent);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .15s, transform .15s;
  pointer-events: none; /* רווחים שקופים מעבירים לחיצה לוידאו (= בחירת שמע) */
  z-index: 4;
}
.tile-dvr[hidden] { display: none; }
/* מציגים בריחוף, במיקוד מקלדת, או כשנמצאים מאחורי החי (כדי שיהיה ברור איך לחזור) */
.tile-body:hover .tile-dvr,
.tile-body:focus-within .tile-dvr,
.tile-dvr:not(.at-live) { opacity: 1; transform: none; }
@media (hover: none) { .tile-dvr { opacity: 1; transform: none; } } /* מגע — תמיד גלוי */

.tile-dvr .dvr-btn,
.tile-dvr .dvr-live,
.tile-dvr .dvr-seek { pointer-events: auto; }

.dvr-btn, .dvr-live {
  flex: 0 0 auto;
  border: 0;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.dvr-btn:hover, .dvr-live:hover { background: rgba(255, 255, 255, .26); }

.dvr-seek {
  flex: 1 1 auto;
  min-width: 30px;
  height: 5px;
  accent-color: var(--accent);
  cursor: pointer;
}

.dvr-offset {
  flex: 0 0 auto;
  min-width: 34px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #cfe0f5;
  font-variant-numeric: tabular-nums;
}

.dvr-live { display: inline-flex; align-items: center; gap: 6px; }
.dvr-live .dvr-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #8a93a4; flex: 0 0 auto;
}
/* כשצופים בחי — נקודה אדומה פועמת; הכפתור רק מאשר את המצב */
.tile-dvr.at-live .dvr-live { background: rgba(229, 72, 77, .2); }
.tile-dvr.at-live .dvr-live .dvr-dot {
  background: var(--danger);
  box-shadow: 0 0 7px var(--danger);
  animation: live-pulse 2s ease-in-out infinite;
}
/* כשמאחורי החי — הכפתור הופך לקריאה לפעולה (חזרה לחי) */
.tile-dvr:not(.at-live) .dvr-live { background: var(--accent); color: #0a1018; }

@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* שכבת שגיאה / טעינה */

.tile-status {
  position: absolute;
  inset: 0;
  z-index: 6; /* מעל סרגל ה-DVR */
  direction: rtl;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(10, 12, 16, .85);
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
  padding: 12px;
}
.tile-status.show { display: flex; }
.tile-status .spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.tile-status.error .spinner { display: none; }
.tile-status .retry-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--bg-tile);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tile-status.error .retry-btn { display: inline-block; }
.tile-status.error::before { content: "⚠"; font-size: 30px; color: var(--danger); }

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

/* ===== סרגל ערוצים תחתון ===== */

#channelbar {
  height: var(--channelbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  z-index: 30;
  scrollbar-width: thin;
}

.chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 2px solid var(--border);
  background: var(--bg-tile);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: #3a4150; }
.chip .dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.chip.on {
  color: #0a1018;
  border-color: var(--accent);
  background: var(--accent);
}
.chip.on .dot { box-shadow: 0 0 0 2px rgba(255,255,255,.5); }

/* כפתור מחיקה על ערוץ שהמשתמש הוסיף */
.chip .chip-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  margin-inline-start: 2px;
  border-radius: 50%;
  background: rgba(229, 72, 77, .15);
  color: #ff9aa0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.chip.on .chip-del { background: rgba(10,16,24,.18); color: #0a1018; }
.chip .chip-del:hover { background: var(--danger); color: #fff; }

.chip.add-chip {
  border-style: dashed;
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}
.chip.add-chip:hover { background: rgba(77, 163, 255, .12); }

/* ===== כיבוי אור ===== */

#lights-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: .9;
  z-index: 20;
  pointer-events: none;
}
body.lights-off #topbar,
body.lights-off #hintbar,
body.lights-off #channelbar { opacity: .25; }
body.lights-off #topbar:hover,
body.lights-off #channelbar:hover { opacity: 1; }
body.lights-off #stage { position: relative; z-index: 25; }

/* ===== חלונות (עזרה / הוספה) ===== */

#help-modal, #add-modal {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 30px;
  max-width: 500px;
  width: calc(100vw - 36px);
}
#help-modal::backdrop, #add-modal::backdrop { background: rgba(0, 0, 0, .65); }
#help-modal h2, #add-modal h2 { margin-top: 0; font-size: 24px; }
#help-modal h3 { font-size: 16px; color: var(--text-dim); margin-bottom: 6px; }
#help-modal .big-steps { list-style: none; padding: 0; margin: 0 0 18px; }
#help-modal .big-steps li {
  display: flex; align-items: center; gap: 12px;
  font-size: 17px; line-height: 1.5; margin-bottom: 12px;
}
#help-modal .big-steps .emoji { font-size: 26px; flex: 0 0 auto; }
#help-modal li { margin-bottom: 7px; }
#help-modal kbd {
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 13px;
}
.kbd-list { list-style: none; padding-right: 0; font-size: 14px; color: var(--text-dim); }
.kbd-list li { margin-bottom: 5px; }
#help-modal details { margin-top: 6px; }
#help-modal summary { cursor: pointer; color: var(--text-dim); font-size: 14px; }

button.primary {
  border: 0;
  background: var(--accent);
  color: #0a1018;
  font-weight: 800;
  border-radius: 10px;
  padding: 13px 26px;
  font-size: 16px;
  cursor: pointer;
}
button.ghost {
  border: 1px solid var(--border);
  background: var(--bg-tile);
  color: var(--text);
  border-radius: 10px;
  padding: 13px 26px;
  font-size: 16px;
  cursor: pointer;
}

/* ===== חלון הוספת ערוץ ===== */

.add-hint { font-size: 15px; color: var(--text-dim); line-height: 1.6; }
.add-hint code { background: var(--bg-tile); padding: 1px 6px; border-radius: 4px; }

/* חיפוש ערוץ לפי שם */
.search-row { display: flex; gap: 8px; margin-top: 4px; }
.search-row input {
  flex: 1 1 auto;
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 17px;
}
.search-row input:focus { outline: none; border-color: var(--accent); }
.search-row button { white-space: nowrap; }

#find-status { font-size: 15px; color: var(--text-dim); margin-top: 12px; min-height: 0; }
#find-status .spin {
  display: inline-block; width: 16px; height: 16px; vertical-align: -3px; margin-inline-end: 7px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 1s linear infinite;
}

#find-results { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.find-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border);
  background: var(--bg-tile);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.find-row:hover { border-color: var(--accent); background: #1b2230; }
.find-row .fr-info { flex: 1 1 auto; min-width: 0; }
.find-row .fr-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.find-row .fr-sub { font-size: 13px; color: var(--text-dim); }
.find-row .fr-add {
  flex: 0 0 auto;
  background: var(--accent); color: #0a1018; font-weight: 800;
  border: 0; border-radius: 999px; padding: 8px 18px; font-size: 15px; cursor: pointer;
}
.find-row.added .fr-add { background: var(--live); }

#advanced { margin-top: 18px; }
#advanced > summary { cursor: pointer; color: var(--text-dim); font-size: 14px; padding: 6px 0; }
#advanced label { display: block; font-size: 14px; color: var(--text); margin-top: 12px; }
#add-modal label {
  display: block;
  font-size: 15px;
  color: var(--text);
  margin-top: 14px;
}
#add-modal input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 13px;
  color: var(--text);
  font-size: 16px;
}
#add-modal input:focus { outline: none; border-color: var(--accent); }
.add-error {
  color: var(--danger);
  font-size: 15px;
  margin: 12px 0 0;
}
.add-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
#custom-list:not(:empty) {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.custom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  padding: 7px 0;
}
.custom-row .cr-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-row .cr-del {
  border: 1px solid var(--border);
  background: var(--bg-tile);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.custom-row .cr-del:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

/* גריד-סטאק — ריווח בין אריחים */
.grid-stack > .grid-stack-item > .grid-stack-item-content {
  inset: 4px;
}
.grid-stack-placeholder > .placeholder-content {
  background: rgba(77, 163, 255, .08) !important;
  border: 2px dashed var(--accent) !important;
  border-radius: 12px;
}

/* ===== מסכים קטנים ===== */

@media (max-width: 768px) {
  :root { --channelbar-h: 76px; --hintbar-h: 0px; }
  #hintbar { display: none; }
  #topbar { padding: 0 12px; }
  #topbar h1 { font-size: 18px; }
  #clock { display: none; }
  #volume { width: 84px; }
  .icon-btn { min-width: 50px; }
  .icon-btn .lbl { display: none; }
  .chip { padding: 11px 17px; font-size: 15px; }
}
