:root {
  --board-bg: #0c0c0f;
  --cell-bg: #17171b;
  --cell-text: #f5c518;
  --seam: rgba(0, 0, 0, 0.65);
  --panel-bg: #1c1c22;
  /* total width (cell + margin) of one split-flap character cell */
  --flap-w: 24px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--board-bg);
  color: #eee;
  font-family: 'Segoe UI', Arial, sans-serif;
}

#start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

#start-overlay button {
  font-size: 1.8rem;
  padding: 1rem 2rem;
  border-radius: 12px;
  border: none;
  background: var(--cell-text);
  color: #111;
  font-weight: 700;
  cursor: pointer;
}

#start-overlay p {
  color: #ccc;
  font-size: 1.1rem;
}

#start-overlay.hidden {
  display: none;
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 2px solid #2a2a30;
}

.board-header h1 {
  font-size: 2rem;
  margin: 0;
  letter-spacing: 0.05em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 1.4rem;
}

#clock {
  font-variant-numeric: tabular-nums;
  color: var(--cell-text);
}

#view-toggle {
  background: none;
  border: 1px solid #444;
  border-radius: 999px;
  color: #ccc;
  font-size: 0.95rem;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}

#view-toggle:hover {
  border-color: var(--cell-text);
  color: var(--cell-text);
}

.status {
  font-size: 1rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
}

.status.online {
  background: #1e5c2f;
  color: #b7f7c4;
}

.status.offline {
  background: #5c1e1e;
  color: #f7b7b7;
}

main {
  padding: 1rem 2rem 2rem;
}

.column-labels {
  display: grid;
  grid-template-columns: calc(8 * var(--flap-w)) calc(10 * var(--flap-w)) calc(16 * var(--flap-w)) 1fr;
  gap: 0.5rem;
  color: #888;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  padding: 0 0.25rem 0.5rem;
  border-bottom: 1px solid #2a2a30;
  margin-bottom: 1rem;
}

#board {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.row {
  display: grid;
  grid-template-columns: calc(8 * var(--flap-w)) calc(10 * var(--flap-w)) calc(16 * var(--flap-w)) 1fr auto;
  gap: 0.5rem;
  align-items: start;
}

/* Read messages dim rather than disappear — reversible, so no scary
   per-message confirmation is needed. "Clear read" removes them in bulk. */
.row.read {
  opacity: 0.35;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  align-self: center;
}

.read-btn,
.ack-btn {
  background: none;
  border: 1px solid #3a3a42;
  border-radius: 8px;
  color: #9a9;
  font-size: 1.2rem;
  min-width: 2.6rem;
  height: 1.9em;
  cursor: pointer;
}

.read-btn:hover {
  border-color: #7de3b8;
  color: #7de3b8;
}

.ack-btn:hover:not(:disabled) {
  border-color: var(--cell-text);
}

.ack-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Scheduled tasks flap in blue; the Mark done button is deliberately the
   loudest control on the board — it's the one an elderly user must find. */
.row.channel-task .flap {
  color: #6db3f2;
}

.task-done-btn {
  background: #6db3f2;
  border: none;
  border-radius: 8px;
  color: #0c0c0f;
  font-weight: 700;
  font-size: 1rem;
  padding: 0 0.9rem;
  height: 1.9em;
  cursor: pointer;
  white-space: nowrap;
}

.task-done-btn:hover:not(:disabled) {
  filter: brightness(1.2);
}

.task-done-label {
  color: #7de3b8;
  font-weight: 700;
  align-self: center;
  white-space: nowrap;
}

.row.task-done {
  opacity: 0.7;
}

#clear-read {
  background: none;
  border: 1px solid #444;
  border-radius: 999px;
  color: #ccc;
  font-size: 0.95rem;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}

#clear-read:hover {
  border-color: #ff5c5c;
  color: #ff5c5c;
}

.flap-group {
  display: flex;
  flex-wrap: wrap;
  row-gap: 2px;
}

.flap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--flap-w) - 2px);
  height: 1.9em;
  margin-right: 2px;
  background: var(--cell-bg);
  color: var(--cell-text);
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 1.3rem;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.85), 0 1px 0 rgba(255, 255, 255, 0.03);
  perspective: 200px;
}

.flap::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--seam);
  z-index: 2;
}

.flap .char {
  display: inline-block;
}

.flap.flip .char {
  animation: flapFlip 0.22s ease-in;
}

@keyframes flapFlip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(-90deg); }
  51% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

.row.new {
  animation: rowIn 0.4s ease-out;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

#idle-view {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 6rem);
  gap: 2rem;
}

#idle-view[hidden] {
  display: none;
}

.idle-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6rem;
  padding: 3rem 0.5rem;
}

.idle-clock {
  font-family: 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 5rem;
  font-weight: 700;
  color: var(--cell-text);
  letter-spacing: 0.05em;
}

.idle-weather {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--cell-text);
  font-size: 1.2rem;
}

.idle-weather-icon {
  font-size: 3.5rem;
  line-height: 1;
}

.idle-weather-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.idle-weather-temp {
  font-family: 'Courier New', monospace;
  font-size: 2.2rem;
  font-weight: 700;
}

.idle-weather-desc {
  font-size: 1.2rem;
  color: #ccc;
}

.idle-weather-tip {
  font-size: 1.1rem;
  color: #ccc;
  font-style: italic;
  max-width: 32ch;
}

.idle-events {
  align-self: center;
  min-width: 340px;
  max-width: 700px;
  background: var(--panel-bg);
  border: 1px solid #2a2a30;
  border-radius: 12px;
  padding: 1.25rem 1.75rem;
}

.idle-events-title {
  color: #7de3b8;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
}

.idle-event {
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  padding: 0.35rem 0;
  font-size: 1.35rem;
}

.idle-event-time {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  color: #7de3b8;
  min-width: 5.5ch;
}

.idle-event-title {
  color: #eee;
}

.idle-event-empty {
  color: #888;
  font-style: italic;
}

/* Broadcast notices (warden/office messages to many boards) flap in a soft
   violet — distinct from personal amber messages and green reminders. */
.row.channel-broadcast .flap {
  color: #c9a6f5;
}

/* Calendar reminders flap in green so they stand out from amber messages. */
.row.channel-calendar .flap {
  color: #7de3b8;
}

/* Alerts (# prefix or a device reporting level "alert") flap in red and
   pulse briefly. Declared after the channel colours so alert wins. */
.row.alert .flap {
  color: #ff5c5c;
}

.row.alert.new {
  animation: rowIn 0.4s ease-out, alertPulse 1.2s ease-in-out 3;
}

@keyframes alertPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.6); }
}

.idle-news {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 2rem;
  padding: 1rem 0.5rem;
  border-top: 2px solid #2a2a30;
  color: var(--cell-text);
}

.idle-news-item {
  font-size: 1.2rem;
  background: none;
  border: none;
  color: var(--cell-text);
  font-family: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.idle-news-item:hover {
  text-decoration: underline;
}

.idle-news-item:not(:last-child)::after {
  content: '•';
  margin-left: 2rem;
  color: #555;
  text-decoration: none;
  display: inline-block;
}

#story-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#story-overlay[hidden] {
  display: none;
}

#story-card {
  background: var(--panel-bg);
  border: 2px solid #3a3a42;
  border-radius: 14px;
  max-width: 700px;
  width: 100%;
  padding: 2rem 2.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
  animation: storyIn 0.25s ease-out;
}

@keyframes storyIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#story-kicker {
  color: #c33;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
}

#story-title {
  margin: 0 0 1rem;
  font-size: 1.8rem;
  line-height: 1.25;
  color: var(--cell-text);
}

#story-description {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
  line-height: 1.5;
  color: #ddd;
}

#story-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#story-link {
  color: var(--cell-text);
  font-size: 1.05rem;
}

#story-close {
  font-size: 1.1rem;
  padding: 0.6rem 1.6rem;
  border-radius: 8px;
  border: none;
  background: var(--cell-text);
  color: #111;
  font-weight: 700;
  cursor: pointer;
}

#test-panel {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  max-width: 320px;
}

/* #test-toggle {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
} */

#test-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

#test-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: #aaa;
  gap: 0.2rem;
}

#test-form input,
#test-form select {
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #111;
  color: #eee;
}

#test-form button {
  padding: 0.5rem;
  border-radius: 6px;
  border: none;
  background: var(--cell-text);
  color: #111;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 700px) {
  :root {
    --flap-w: 16px;
  }
  .flap {
    height: 1.5em;
    font-size: 1rem;
  }
}
