:root {
  --brand: #c00;
  --brand-dark: #900;
  --bg: #f5f5f5;
  --card: #fff;
  --text: #222;
  --muted: #666;
  --border: #ddd;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* ---- App chrome ---------------------------------------------------------- */
#appHeader {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--brand);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 0.7em) 1em 0.7em;
  text-align: center;
}
#appHeader h1 { margin: 0; font-size: 1.2em; font-weight: 600; }

#view {
  /* leave room for the fixed bottom tab bar + the iOS home indicator */
  padding: 1em 1em calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1.5em);
  max-width: 640px;
  margin: 0 auto;
}

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 0.5em 0;
  min-height: var(--tabbar-h);
  font-size: 0.7em;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab .tab-icon { font-size: 1.5rem; line-height: 1; }
.tab.active { color: var(--brand); font-weight: 600; }

/* ---- Generic content ----------------------------------------------------- */
h2 { font-size: 1.05em; margin: 1.4em 0 0.5em; }
h2:first-child { margin-top: 0; }
ul { padding-left: 1.2em; margin: 0.5em 0; }
li { margin-bottom: 0.6em; word-break: break-word; }
code { background: #ececec; padding: 0.1em 0.3em; border-radius: 3px; font-size: 0.85em; }
.muted { color: var(--muted); }
.error { color: var(--brand); margin-top: 0.5em; }
.success { color: #080; margin-top: 0.5em; }

label { display: block; margin-top: 1em; font-weight: 600; }
/* 16px keeps iOS from zooming the page when an input is focused */
input[type="text"], input[type="date"] {
  width: 100%;
  font-size: 16px;
  padding: 0.6em;
  margin-top: 0.3em;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
}
form { margin-bottom: 1.5em; }

button {
  font-size: 1em;
  padding: 0.7em 1.4em;
  min-height: 44px;
  border: 1px solid #888;
  border-radius: 6px;
  background: #f0f0f0;
  cursor: pointer;
  margin-top: 1em;
}
button:active { background: #e0e0e0; }

.delete-link {
  display: inline-block;
  color: var(--brand);
  cursor: pointer;
  margin-left: 0.5em;
  padding: 0.2em 0.4em;
  text-decoration: underline;
}

/* ---- Control / Now Playing ----------------------------------------------- */
#pauseBtn {
  background: var(--brand);
  color: #fff;
  font-size: 1.2em;
  padding: 0.9em 2em;
  width: 100%;
  border: none;
  border-radius: 8px;
  margin-top: 0;
}
#pauseBtn:active { background: var(--brand-dark); }
#pauseBtn:disabled { opacity: 0.6; }
#pauseMsg { display: block; margin: 0.6em 0; font-weight: bold; min-height: 1.2em; }

.finish-lock-toggle { display: flex; align-items: center; gap: 0.4em; margin: 0.6em 0; font-weight: 400; }
.finish-lock-toggle input { width: auto; margin: 0; }

.preset-buttons { display: flex; flex-wrap: wrap; gap: 0.6em; margin-top: 0.6em; }
.preset-btn {
  margin-top: 0;
  background: #fff;
  border: 1px solid var(--brand);
  color: var(--brand);
  font-size: 0.95em;
  padding: 0.6em 1em;
}
.preset-btn:active { background: #fdecea; }

#customMsgInput {
  width: 100%;
  font-size: 16px;
  padding: 0.6em;
  margin-top: 0.3em;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
  resize: vertical;
}
#sendCustomMsgBtn {
  background: var(--brand);
  color: #fff;
  font-size: 1.1em;
  padding: 0.8em 1.6em;
  width: 100%;
  border: none;
  border-radius: 8px;
}
#sendCustomMsgBtn:active { background: var(--brand-dark); }
#sendCustomMsgBtn:disabled { opacity: 0.6; }
#pauseMsgMsg { display: block; margin: 0.6em 0; font-weight: bold; min-height: 1.2em; }

#presetManager { margin-top: 1.6em; }
#presetManager summary { cursor: pointer; font-weight: 600; padding: 0.4em 0; }
#presetManager #presetList { margin-top: 0.6em; }

.status-card {
  margin-top: 0.4em;
  padding: 1em;
  border-radius: 10px;
  font-size: 1.15em;
  font-weight: 600;
  border: 1px solid transparent;
}
.status-card .status-sub {
  display: block;
  font-size: 0.8em;
  font-weight: 400;
  margin-top: 0.35em;
  color: #555;
  word-break: break-word;
}
.status-playing { background: #fdecea; border-color: #f5b5ae; color: #b71c1c; }
.status-paused  { background: #e8f5e9; border-color: #a5d6a7; color: #1b5e20; }
.status-idle    { background: #f2f2f2; border-color: #ddd; color: #666; }

.np-label { font-size: 1.1em; }
.np-media { display: flex; gap: 0.7em; margin-top: 0.7em; align-items: flex-start; }
.np-thumb {
  width: 120px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: rgba(0,0,0,0.08);
  flex: none;
}
.np-meta { min-width: 0; }
.np-title {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.np-channel { font-size: 0.85em; font-weight: 400; color: var(--muted); margin-top: 0.25em; }
.np-progress {
  margin-top: 0.8em;
  height: 6px;
  border-radius: 3px;
  background: rgba(0,0,0,0.12);
  overflow: hidden;
}
.np-progress-fill { height: 100%; background: currentColor; border-radius: 3px; transition: width 0.4s ease; }
.np-progress-label { margin-top: 0.35em; font-size: 0.8em; font-weight: 400; color: #555; }

/* ---- History ------------------------------------------------------------- */
.date-selector { display: flex; gap: 0.6em; flex-wrap: wrap; align-items: flex-end; }
.date-selector input[type="date"] { flex: 1; min-width: 150px; margin-top: 0; }
.date-selector button { margin-top: 0; }
.history-stats {
  display: flex;
  gap: 1.5em;
  margin: 1em 0;
  padding: 0.8em 1em;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stat-label { font-size: 0.75em; color: var(--muted); }
.stat-value { font-size: 1.3em; font-weight: 600; }

.history-list { display: grid; grid-template-columns: 1fr; gap: 1em; margin-top: 1em; }
.history-item {
  display: flex;
  gap: 0.8em;
  background: var(--card);
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}
.history-item img { width: 120px; height: 68px; object-fit: cover; background: #eee; flex: none; }
.history-meta { padding: 0.5em 0.5em 0.5em 0; min-width: 0; }
.history-title {
  font-size: 0.9em; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-sub { font-size: 0.8em; color: var(--muted); margin-top: 0.2em; }
.history-time { font-size: 0.75em; color: #909090; margin-top: 0.3em; }
.empty-state { text-align: center; color: var(--muted); padding: 2.5em 1em; }

/* ---- Logs / diagnostics -------------------------------------------------- */
.logs-toolbar { display: flex; align-items: center; gap: 1em; }
.logs-toolbar button { margin-top: 0; }
.logs-auto { display: flex; align-items: center; gap: 0.4em; margin: 0; font-weight: 400; }
.logs-auto input { width: auto; margin: 0; }
.log-list { margin-top: 1em; display: flex; flex-direction: column; gap: 0.4em; }
.log-row {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 0.5em 0.7em;
  background: #fff;
}
.log-row.log-err  { border-left-color: #c00; }
.log-row.log-ok   { border-left-color: #2e7d32; }
.log-row.log-info { border-left-color: #bbb; }
.log-head { display: flex; justify-content: space-between; gap: 0.6em; align-items: baseline; }
.log-event { font-weight: 600; font-size: 0.9em; }
.log-err .log-event { color: #c00; }
.log-ok .log-event { color: #2e7d32; }
.log-when { font-size: 0.75em; color: var(--muted); white-space: nowrap; }
.log-detail {
  margin-top: 0.3em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78em;
  color: #444;
  word-break: break-word;
}
