html {
  scroll-behavior: smooth;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e7edf4;
  --muted: #8b9cb3;
  --accent: #3d8fd1;
  --error: #e85d6f;
  --ok: #5dce8f;
  --radius: 10px;
  font-family: system-ui, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

body:not(.auth) {
  display: flex;
  flex-direction: column;
}

body.settings-modal-open {
  overflow: hidden;
}

body:not(.auth) > section.grid {
  flex: 1;
}

body.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

h1 { font-size: 1.35rem; margin: 0 0 0.5rem; }

.brand-logo {
  margin: 0;
  line-height: 0;
  flex-shrink: 0;
}

.brand-logo img {
  display: block;
  height: clamp(2rem, 5vw, 2.75rem);
  width: auto;
  max-width: min(280px, 72vw);
  object-fit: contain;
  object-position: left center;
}

.brand-logo--auth {
  margin-bottom: 1.25rem;
}

.brand-logo--auth img {
  height: clamp(3.25rem, 14vw, 5rem);
  max-width: min(400px, 100%);
  margin-left: auto;
  margin-right: auto;
  object-position: center;
}

.card-auth .auth-heading {
  text-align: center;
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
}

.login-form label[for="password"] {
  margin-top: 0.75rem;
}

.login-form label[for="user"] {
  margin-top: 0;
}
h2 { font-size: 1.1rem; margin: 0 0 1rem; }

.muted { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0; }
.hint { font-size: 0.8rem; color: var(--muted); margin: -0.5rem 0 0.75rem; }


.poster-countdown {
  margin: 0.35rem 0 0;
}

.poster-countdown-stale {
  font-size: 0.85rem;
  font-weight: normal;
  color: var(--muted);
}

code {
  font-size: 0.85em;
  background: #0c1016;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.top-poster-inline {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.25;
  max-width: 100%;
}

.top-poster-bit {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  white-space: nowrap;
}

.top-poster-k {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.top-poster-inline strong.status-on,
.top-poster-inline strong.status-off,
.top-poster-inline strong.status-api-missing {
  font-size: 0.78rem;
  font-weight: 600;
}

.top-poster-pid {
  font-size: 0.72rem;
  opacity: 0.9;
}

.top-poster-pid::before {
  content: "·";
  margin-right: 0.2rem;
  opacity: 0.45;
}

.top-poster-btns {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.top-poster-form {
  margin: 0;
}

.top-poster-btn {
  margin-top: 0;
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  line-height: 1.2;
}

.top-poster-btn--stop {
  background: #c44c5c;
  border-color: transparent;
}

.top-poster-btn--stop:hover {
  filter: brightness(1.08);
}

.top-schedule-inline {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.35;
  max-width: min(56vw, 36rem);
  min-width: 0;
}

.top-schedule-body {
  display: inline;
  color: var(--muted);
  word-break: break-word;
}

.top-schedule-body strong {
  color: var(--text);
  font-weight: 600;
}

.top-schedule-inline .poster-countdown-stale {
  font-size: 0.72rem;
  font-weight: normal;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  flex-shrink: 0;
  justify-content: flex-end;
}

.top-actions .top-nav-link {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
}

.top-actions .top-nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

button.icon-btn,
a.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  margin: 0;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button.icon-btn:hover,
a.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--muted);
}

button.icon-btn:focus-visible,
a.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-settings {
  display: block;
  flex-shrink: 0;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  padding: 1.25rem clamp(0.75rem, 2vw, 1.5rem) 2rem;
  max-width: min(1920px, 100%);
  margin: 0 auto;
  flex: 1;
  align-content: start;
}

/* Main panel: posts area width 80% of viewport (centered); caps at same max as .grid */
.grid.grid--posts-only {
  width: min(80vw, 100%);
  max-width: min(1920px, 100%);
  margin-left: auto;
  margin-right: auto;
  padding-top: 1rem;
}

.card-span {
  grid-column: 1 / -1;
  max-width: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  pointer-events: none;
}

.settings-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.settings-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  cursor: pointer;
}

.settings-modal-sheet {
  position: relative;
  z-index: 1;
  width: min(640px, calc(100vw - 2rem));
  max-height: min(90vh, 920px);
  margin-top: 2vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.settings-modal-close-x {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  margin: 0;
  font-size: 1.5rem;
  line-height: 1;
  font-weight: 400;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.settings-modal-close-x:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.settings-modal-body {
  padding: 1rem 1.35rem 1.35rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  max-width: 520px;
  width: 100%;
}

body:not(.auth) .card { max-width: none; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.timing-delay-block {
  margin-top: 1.35rem;
}

.timing-delay-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.4rem;
  line-height: 1.4;
}

.timing-delay-desc {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.timing-delay-desc code {
  font-size: 0.88em;
}

.timing-delay-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 0.25rem;
}

.timing-delay-pair label {
  margin-top: 0;
}

input, textarea, select, button {
  font: inherit;
  color: var(--text);
  background: #0c1016;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}

textarea {
  resize: vertical;
  min-height: 4rem;
}

.posts-editor {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 14rem);
}

/* Wide editor: ~92vw max, not full screen; centered in the grid column */
@media (min-width: 700px) {
  article.posts-editor {
    width: min(92vw, 100%);
    margin-left: auto;
    margin-right: auto;
  }
}

.posts-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0.5rem;
}

.posts-form label {
  margin-top: 0;
}

.posts-textarea {
  flex: 1;
  width: 100%;
  min-height: min(70vh, 900px);
  resize: vertical;
  line-height: 1.5;
  tab-size: 4;
}

.posts-textarea::placeholder {
  color: var(--muted);
  opacity: 0.9;
  white-space: pre-wrap;
}

.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.88rem; }

.config-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.75rem;
}

.config-form-actions button {
  margin-top: 0;
}

button {
  background: var(--accent);
  border-color: transparent;
  cursor: pointer;
  font-weight: 600;
  margin-top: 0.75rem;
  padding: 0.55rem 1rem;
}

button:hover { filter: brightness(1.08); }

button.secondary {
  background: transparent;
  border-color: var(--border);
  margin-top: 0;
}

form.inline { margin: 0; }

.error {
  color: var(--error);
  font-weight: 600;
}

.banner {
  margin: 0 1.5rem 0;
  max-width: min(1920px, 100%);
  margin-left: auto;
  margin-right: auto;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
}

p.error.banner { background: rgba(232, 93, 111, 0.12); border: 1px solid rgba(232, 93, 111, 0.35); }
p.ok.banner { background: rgba(93, 206, 143, 0.12); border: 1px solid rgba(93, 206, 143, 0.35); color: var(--ok); }

/* After saving settings: modal closes; toast sits above the page (not behind the dialog) */
p.ok.banner.banner--toast {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, 0);
  z-index: 1100;
  margin: 0;
  max-width: min(28rem, calc(100vw - 2rem));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: banner-toast-in 0.35s ease;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

p.ok.banner.banner--toast.banner--toast-hiding {
  opacity: 0;
  transform: translate(-50%, -0.5rem);
  pointer-events: none;
}

@keyframes banner-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -0.6rem);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

p.notice.banner {
  background: rgba(61, 143, 209, 0.12);
  border: 1px solid rgba(61, 143, 209, 0.35);
  color: var(--muted);
}

.status-on { color: var(--ok); }
.status-off { color: var(--error); }
.status-api-missing { color: #f0a84a; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}

a.log-back {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
}

a.log-back:hover {
  background: rgba(255, 255, 255, 0.06);
}

.log-page {
  padding: 1rem 1.5rem 2rem;
  max-width: min(1920px, 100%);
  margin: 0 auto;
}

.log-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

p.log-trunc {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}

pre.log-body {
  background: #0c1016;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: auto;
  max-height: min(78vh, 920px);
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.history-page .history-tz-note {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  overflow: hidden;
}

.history-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.history-time {
  white-space: nowrap;
  font-size: 0.85rem;
}

.history-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.history-card-preview {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  font-size: 0.88rem;
  color: var(--text);
}

button.danger {
  background: #c44c5c;
}

button.danger:hover { filter: brightness(1.08); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
