/**
 * X First Post Finder - Tool Specific Scoped Stylesheet
 * Copyright (c) 2026 kixking. All rights reserved.
 *
 * CSS分離アーキテクチャ（B案）準拠: 固有スタイルは xfp-* プレフィックスで当ファイルに独立管理。
 * Mobile-first: touch targets >= 44px, inputs >= 16px (no iOS zoom), sticky action bar in thumb zone.
 */

body.xfp-body {
  --xfp-radius: 12px;
  --xfp-tap: 44px;

  & .site-container {
    max-width: 760px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
  }

  & .profile-header {
    max-width: 100%;
  }

  /* Keep the footer reachable above the sticky bar */
  &.xfp-has-actionbar .site-container {
    padding-bottom: calc(7rem + env(safe-area-inset-bottom));
  }
}

.xfp-card,
.xfp-block,
.xfp-output,
.xfp-notes {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--xfp-radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Zero specificity: beats UA styles only, never component font choices */
:where(body.xfp-body) :where(button, input) {
  font-family: inherit;
}

:is(.xfp-card, .xfp-result) :is(a, button, summary):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ---------- Input card ---------- */

.xfp-card {
  padding: 1.1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
}

.xfp-label {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.xfp-optional {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.xfp-hint {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 0.4rem 0 0;
}

.xfp-error {
  font-size: 0.78rem;
  color: var(--accent-ink);
  margin: 0.4rem 0 0;
}

.xfp-join-preview {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);

  &.is-error {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--accent-ink);
  }
}

.xfp-input-wrap {
  display: flex;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--border-medium);
  border-radius: 10px;
  background: var(--bg-surface);
  transition: border-color 0.2s ease;

  &:focus-within {
    border-color: var(--border-focus);
  }
}

.xfp-handle-prefix {
  padding-left: 0.9rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--text-muted);
}

.xfp-input {
  flex: 1;
  width: 0;
  min-width: 0;
  align-self: stretch;
  font-family: var(--font-mono);
  font-size: max(16px, 1.05rem);
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  padding: 0 0.5rem 0 0.3rem;

  &::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
  }
}

.xfp-input-join {
  font-family: var(--font-sans);
  padding-left: 0.9rem;
}

.xfp-icon-btn,
.xfp-paste-btn {
  flex-shrink: 0;
  min-width: var(--xfp-tap);
  height: var(--xfp-tap);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.xfp-icon-btn {
  font-size: 0.85rem;

  &:hover {
    color: var(--text-primary);
  }
}

.xfp-paste-btn {
  margin-right: 0.35rem;
  padding: 0 0.7rem;
  height: 34px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-medium);
  border-radius: 8px;

  &:hover {
    color: var(--text-primary);
    border-color: var(--border-focus);
  }
}

/* Options (collapsed by default to keep the first screen short) */
.xfp-options {
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.25rem;

  &[open] .xfp-options-summary::after {
    transform: translateY(4px) rotate(225deg);
  }
}

.xfp-options-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--xfp-tap);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;

  &::-webkit-details-marker {
    display: none;
  }

  &::after {
    content: "";
    width: 7px;
    height: 7px;
    margin: 0 0.3rem 0.2rem auto;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
  }
}

.xfp-options-state {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
}

.xfp-field-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem 0;

  & + & {
    border-top: 1px solid var(--border-subtle);
  }
}

.xfp-field-row-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

/* Shared .toggle-slider references undefined --border-color; scope a fix here */
.xfp-options .toggle-slider {
  background-color: var(--border-medium);
}

.xfp-options .toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-ink);
}

.xfp-options .toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.xfp-mode-group {
  display: flex;
  border: 1px solid var(--border-medium);
  border-radius: 10px;
  overflow: hidden;
}

.xfp-mode-btn {
  flex: 1;
  min-height: var(--xfp-tap);
  font-size: 0.82rem;
  padding: 0 0.9rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: none;
  cursor: pointer;

  & + & {
    border-left: 1px solid var(--border-medium);
  }

  &[aria-pressed="true"] {
    color: var(--bg-page);
    background: var(--text-primary);
  }
}

/* ---------- Result ---------- */

.xfp-result {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.25rem;
}

.xfp-result-lead {
  margin: 0;
  padding: 0 0.25rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.xfp-block {
  padding: 1.1rem;
}

.xfp-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.xfp-block-title,
.xfp-notes-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.xfp-text-btn {
  min-height: 36px;
  padding: 0 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.xfp-window-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.xfp-window-link,
.xfp-month-link,
.xfp-year-btn {
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.xfp-window-link,
.xfp-month-link {
  display: flex;
  text-decoration: none;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;

  &:hover {
    border-color: var(--accent-ink);
  }

  &:active {
    background: var(--accent-tint);
  }
}

.xfp-window-link {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 52px;
  padding: 0.6rem 2.2rem 0.6rem 1rem;

  &::after {
    content: "↗";
    position: absolute;
    right: 0.9rem;
    color: var(--text-muted);
  }
}

.xfp-link-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.xfp-link-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Opened periods */
:is(.xfp-window-link, .xfp-month-link, .xfp-year-btn).is-checked {
  color: var(--text-muted);
  background: transparent;
  border-style: dashed;

  &::before {
    content: "✓";
    position: absolute;
    top: 2px;
    left: 5px;
    font-size: 0.62rem;
    color: var(--accent-ink);
  }
}

.xfp-year-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.xfp-year-btn {
  min-height: var(--xfp-tap);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;

  &:hover {
    border-color: var(--border-medium);
    color: var(--text-primary);
  }

  &[aria-pressed="true"] {
    color: var(--bg-page);
    background: var(--text-primary);
    border: 1px solid var(--text-primary);
  }
}

.xfp-month-panel {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-medium);
  scroll-margin-bottom: calc(6rem + env(safe-area-inset-bottom));
}

.xfp-month-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}

.xfp-month-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
}

.xfp-month-year-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  font-size: 0.8rem;
  color: var(--accent-ink);
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

.xfp-month-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
}

.xfp-month-link {
  align-items: center;
  justify-content: center;
  min-height: var(--xfp-tap);
  font-size: 0.88rem;
}

.xfp-output {
  padding: 0.9rem 1.1rem;
}

.xfp-output-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.xfp-output-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.xfp-output-actions {
  display: flex;
  gap: 0.4rem;
}

.xfp-output .btn-code-action {
  min-height: 36px;
}

.xfp-query {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
  word-break: break-all;
}

/* ---------- Notes ---------- */

.xfp-notes {
  margin-top: 1.25rem;
  padding: 0 1.1rem;

  & > summary {
    display: flex;
    align-items: center;
    min-height: 52px;
    font-size: 1rem;
    cursor: pointer;
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }

    &::after {
      content: "";
      width: 7px;
      height: 7px;
      margin: 0 0.3rem 0.2rem auto;
      border-right: 1.5px solid var(--text-muted);
      border-bottom: 1.5px solid var(--text-muted);
      transform: rotate(45deg);
      transition: transform 0.2s ease;
    }
  }

  &[open] > summary::after {
    transform: translateY(4px) rotate(225deg);
  }

  & ul {
    margin: 0 0 1rem;
    padding-left: 1.1rem;
    font-size: 0.8rem;
    line-height: 1.75;
    color: var(--text-secondary);
  }

  & strong {
    color: var(--text-primary);
  }
}

/* ---------- Sticky action bar (thumb zone) ---------- */

.xfp-actionbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 50;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg-page) 65%, transparent);
  pointer-events: none;

  &[hidden] {
    display: none;
  }
}

.xfp-actionbar-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 728px;
  min-height: 56px;
  margin: 0 auto;
  padding: 0.55rem 1.1rem;
  color: var(--bg-page);
  background: var(--text-primary);
  border-radius: 14px;
  text-decoration: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;

  &:active {
    transform: scale(0.98);
  }

  &:focus-visible {
    outline: 2px solid var(--accent-ink);
    outline-offset: 3px;
  }
}

.xfp-actionbar-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.xfp-actionbar-kicker {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.xfp-actionbar-label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xfp-actionbar-arrow {
  margin-left: auto;
  font-size: 1.1rem;
}

/* ---------- Wider screens ---------- */

@media (min-width: 600px) {
  body.xfp-body .site-container {
    padding: 2.5rem 1.5rem 5rem;
  }

  .xfp-card,
  .xfp-block {
    padding: 1.5rem;
  }

  .xfp-notes {
    padding: 0 1.5rem;
  }

  .xfp-field-row:not(.xfp-field-row-inline) {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;

    & .xfp-mode-group {
      flex-shrink: 0;
    }

    & .xfp-mode-btn {
      flex: none;
    }
  }

  .xfp-window-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .xfp-window-link {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0.2rem;
  }

  .xfp-year-grid {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  }

  .xfp-month-list {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (hover: hover) {
  .xfp-window-link:hover,
  .xfp-month-link:hover {
    background: var(--accent-tint);
  }
}

@media (prefers-reduced-motion: reduce) {
  .xfp-actionbar-btn,
  .xfp-options-summary::after,
  .xfp-notes > summary::after {
    transition: none;
  }
}
