:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #eef3f5;
  --text: #171b1f;
  --muted: #65717c;
  --line: #d8e0e6;
  --accent: #087f8c;
  --accent-dark: #06606a;
  --danger: #a93636;
  --danger-bg: #fff0f0;
  --shadow: 0 12px 34px rgba(22, 30, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 48px;
}

.search-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.diagnostic-panel {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.diagnostic-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.diagnostic-result {
  margin-top: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.diagnostic-result.success {
  color: var(--accent-dark);
  font-weight: 700;
}

.diagnostic-result.error {
  color: var(--danger);
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  letter-spacing: 0;
}

.status-badge {
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.loading {
  background: #e9f7f8;
  color: var(--accent-dark);
}

.status-badge.error {
  background: var(--danger-bg);
  color: var(--danger);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 120px 170px 150px 130px;
  gap: 14px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.toggle span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(8, 127, 140, 0.14);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.meta {
  min-height: 24px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.error-box {
  margin-top: 12px;
  border: 1px solid #f0b8b8;
  border-radius: 7px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 12px;
  white-space: pre-wrap;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 18px 0;
}

.toolbar button {
  background: #26343f;
}

.toolbar button:hover:not(:disabled) {
  background: #11181f;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.post-card {
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(22, 30, 40, 0.06);
  overflow: hidden;
}

.post-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 0;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--panel-soft);
  object-fit: cover;
}

.author-block {
  min-width: 0;
}

.author-line {
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
}

.author-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.username,
time {
  color: var(--muted);
  font-size: 0.86rem;
}

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

.open-link,
.publish-open-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 800;
  min-height: 38px;
  padding: 8px 10px;
  text-decoration: none;
}

.open-link {
  color: var(--accent-dark);
  background: #fff;
}

.publish-open-button {
  background: var(--accent);
  color: #fff;
}

.post-text {
  margin: 0;
  padding: 0 14px;
  color: #27313a;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 2px;
  background: var(--line);
}

.media-item {
  position: relative;
  min-height: 220px;
  background: #101820;
  cursor: zoom-in;
}

.media-item img,
.media-item video {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 220px;
  object-fit: cover;
}

.media-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 30, 0.82);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 5px 8px;
  pointer-events: none;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 220px;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.16);
  color: #fff;
  font-size: 0;
  padding: 0;
}

.play-overlay::before {
  content: "";
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(12, 20, 28, 0.82);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.play-overlay::after {
  content: "";
  position: absolute;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-left: 22px solid #fff;
  transform: translateX(3px);
}

.play-overlay:hover {
  background: rgba(0, 0, 0, 0.24);
}

.play-overlay[hidden] {
  display: none;
}

.media-modal {
  width: min(96vw, 1180px);
  max-width: none;
  height: min(92dvh, 860px);
  max-height: none;
  border: 0;
  border-radius: 8px;
  background: #071016;
  color: #fff;
  padding: 0;
  overflow: hidden;
}

.media-modal::backdrop {
  background: rgba(4, 8, 12, 0.78);
}

.modal-stage {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  max-height: min(92dvh, 860px);
  min-height: 360px;
}

.modal-content {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background: #071016;
}

.modal-media {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: min(92dvh, 860px);
  object-fit: contain;
}

.modal-image {
  object-fit: contain;
}

.modal-video {
  object-fit: contain;
  background: #000;
}

.modal-close {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  width: 42px;
  height: 42px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(8, 14, 20, 0.82);
  color: #fff;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-close:hover {
  background: rgba(22, 31, 40, 0.95);
}

.modal-play {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  min-width: 92px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(8, 14, 20, 0.86);
  color: #fff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.modal-play:hover {
  background: rgba(22, 31, 40, 0.96);
}

.modal-play[hidden] {
  display: none;
}

.publish-modal {
  width: min(94vw, 720px);
  max-width: none;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0;
}

.publish-modal::backdrop {
  background: rgba(4, 8, 12, 0.54);
}

.publish-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.publish-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.publish-head h2 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0;
}

.publish-close {
  position: static;
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--line);
}

.publish-close:hover {
  background: var(--line);
}

.publish-field {
  display: grid;
  gap: 8px;
}

.publish-field span,
.publish-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.publish-field textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  color: var(--text);
}

.publish-media-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.publish-media-option {
  position: relative;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}

.publish-media-option input {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.publish-media-option img {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: #101820;
  object-fit: cover;
}

.publish-media-option span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.publish-feedback {
  min-height: 22px;
  color: var(--muted);
  white-space: pre-wrap;
}

.publish-feedback.error {
  color: var(--danger);
}

.publish-feedback.success {
  color: var(--accent-dark);
  font-weight: 800;
}

.publish-actions {
  display: flex;
  justify-content: flex-end;
}

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 10px 14px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 26px;
  text-align: center;
}

@media (max-width: 860px) {
  .search-form {
    grid-template-columns: 1fr 1fr;
  }

  .field-wide {
    grid-column: 1 / -1;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    margin-top: 10px;
  }

  .search-panel {
    padding: 16px;
  }

  .title-row,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .diagnostic-form {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .results {
    grid-template-columns: 1fr;
  }
}
