/*
 * Share STAU の画面のスタイル。
 * 部品は Basecoat UI（vendor/basecoat.min.css）を使い、色は theme.css で STAU に合わせる。
 * このファイルは、ページの骨組みと、Basecoat にない部品だけを書く。
 * Basecoat は Tailwind の preflight で見出しやリストの既定の見た目を消すので、必要なものはここで戻す。
 */

html {
  /* 画面下のコピー通知に、フォーカスした要素が隠れないようにする。 */
  scroll-padding-bottom: 5rem;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--background);
  color: var(--foreground);
  font-size: 1rem;
  line-height: 1.7;
}

/* 本文のリンクは下線で示す。色だけに頼らない（1.4.1）。 */
main a:not(.btn),
.site-footer a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

main a:not(.btn):hover {
  text-decoration-thickness: 2px;
}

main:focus {
  outline: none;
}

h1 {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

code {
  font-size: 0.9em;
}

/* 利用者が入力した文字列は、空白がなくても折り返す。狭い画面で横スクロールを出さないため。 */
h1,
.created__title,
tbody th,
td,
.alert,
.toast {
  overflow-wrap: anywhere;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -10rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
}

.skip-link:focus {
  top: 0.5rem;
}

/* ヘッダー */
.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
}

.site-name {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  white-space: nowrap;
}

.site-name svg {
  width: 1.25rem;
  height: 1.25rem;
}

.site-nav {
  flex: 1 1 auto;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* 今いるページは、地の色と太字と下線で示す。色だけに頼らない。 */
.site-nav a[aria-current="page"] {
  background: var(--secondary);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.35em;
}

.site-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

/* 本文 */
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.page-head {
  margin-bottom: 1.5rem;
}

.page-head p {
  margin-top: 0.5rem;
  color: var(--muted-foreground);
}

.stack > * + * {
  margin-top: 1.5rem;
}

.prose > * + * {
  margin-top: 1rem;
}

.message-page {
  max-width: 36rem;
  margin: 2rem auto 0;
}

/* カードの中の余白。Basecoat の card は上下の余白だけを持つ。 */
.card > header,
.card > section,
.card > footer {
  padding-inline: 1.5rem;
}

.card > header p {
  margin-top: 0.375rem;
  color: var(--muted-foreground);
}

.card > footer {
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (max-width: 48rem) {
  .card > header,
  .card > section,
  .card > footer {
    padding-inline: 1rem;
  }
}

/* 入力欄 */
.form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 40rem;
}

.field {
  gap: 0.5rem;
}

.field > label {
  font-weight: 600;
}

.field__error {
  display: flex;
  gap: 0.375rem;
  align-items: flex-start;
  color: var(--destructive);
  font-size: 0.875rem;
  font-weight: 600;
}

.field__error svg {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  margin-top: 0.2em;
}

/* エラーの欄は、色に加えて枠の太さでも示す。 */
.input[aria-invalid="true"] {
  border-width: 2px;
  border-color: var(--destructive);
}

.required {
  margin-left: 0.25rem;
}

.formats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}

.formats legend {
  width: 100%;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ラベルまでを押せる範囲にし、24px 以上を確保する（2.5.8）。 */
.formats__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.5rem;
}

.formats__item .label {
  font-weight: 400;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* お知らせ */
.alert {
  margin-bottom: 1.5rem;
}

.alert:focus {
  outline: none;
}

.alert[data-variant="destructive"] {
  border-color: var(--destructive);
}

/* 発行した直後の結果。目立つように枠を濃くする。 */
.created {
  --tw-ring-color: var(--primary);
}

.created__url {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.created__url .field {
  flex: 1 1 18rem;
  width: auto;
}

.created__title {
  font-weight: 600;
}

/* 一覧 */
.search {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.search .field {
  flex: 0 1 auto;
  width: auto;
}

.search .field:first-child {
  flex: 1 1 16rem;
  max-width: 32rem;
}

.search__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.count {
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.table-scroll {
  overflow-x: auto;
}

/* 表のセルの余白と揃え。 */
.table th,
.table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  vertical-align: middle;
}

.table thead th {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}

.table tr {
  border-color: var(--border);
}

.table tbody tr:hover {
  background: color-mix(in oklab, var(--foreground) 4%, transparent);
}

.table tbody th {
  /* Basecoat は見出しのセルの高さを固定する。まとめを開いたときに行が伸びるよう、戻す。 */
  height: auto;
  font-weight: 600;
  white-space: normal;
}

.table td {
  white-space: nowrap;
}

.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 一覧の日時と作成者。長い名前は省かずに折り返す。日時は途中で折り返さない。 */
.cell-text {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.table time.cell-text {
  white-space: nowrap;
}

.cell-sub {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  font-weight: 400;
}

/* 表の文字は 14px なので、リンクの押せる範囲を 24px 以上に広げる（2.5.8）。 */
.table a:not(.btn) {
  display: inline-block;
  min-height: 1.5rem;
  padding-block: 0.125rem;
}

/* まとめの中身のリンクはブロックにする。折り返しても、番号が1行目に並ぶため。 */
.table .bundle-details li a {
  display: block;
}

/* タイトルは省かずに折り返す。全文を誰でも読めるようにするため。 */
.row-title__text {
  display: block;
  overflow-wrap: anywhere;
}

/* タイトルの下の「短縮 URL → 転送先」の行。広い画面では1行に収め、長い転送先は末尾を省く。
   転送先の全文は、リンクの title と、狭い画面での折り返しで読める。 */
.row-sub {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 400;
  white-space: nowrap;
}

.row-sub__arrow {
  flex-shrink: 0;
  color: var(--muted-foreground);
}

.row-sub__target {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted-foreground);
}

.table a.row-sub__target {
  text-decoration-style: dotted;
}

.table a.row-sub__target:hover {
  text-decoration-style: solid;
}

.row-sub .bundle-details {
  min-width: 0;
  white-space: normal;
}

/* コピーは一覧で一番よく使う操作なので、文字付きのボタンにする。押した後はアイコンをチェックに替える。 */
.copy-btn .lucide-check,
.copy-btn.is-copied .lucide-copy {
  display: none;
}

.copy-btn.is-copied .lucide-check {
  display: block;
}

.slug {
  display: inline-block;
  flex-shrink: 0;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.8125rem;
}

/* 短縮 URL の一覧は列の幅を決め、タイトルの列に残りを渡す。 */
.links-table {
  table-layout: fixed;
  min-width: 46rem;
}

.links-table col.c-clicks { width: 5.5rem; }
.links-table col.c-created { width: 10rem; }
.links-table col.c-actions { width: 9.5rem; }

/* ログインしている人の頭文字の丸。Basecoat の .avatar とは別の部品なので、名前を分ける。 */
.user-avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  cursor: default;
}

.user-avatar__initials {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* タイトルの前の状態のアイコン。有効は緑の丸、無効は斜線の丸。 */
.row-title {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  gap: 0.625rem;
  align-items: start;
}

.row-title__body {
  min-width: 0;
}

.row-state {
  display: flex;
  padding-top: 0.2rem;
  color: var(--success);
}

.row-state svg {
  width: 1rem;
  height: 1rem;
}

.row-state[data-state="off"] {
  color: var(--muted-foreground);
}

.table td.actions > * + * {
  margin-left: 0.25rem;
}

.table td.actions,
.links-table thead th:last-child,
.links-table thead th:nth-child(3) {
  text-align: right;
}

.table td.actions > .btn {
  vertical-align: middle;
}

.table tr.is-disabled th,
.table tr.is-disabled td {
  color: var(--muted-foreground);
}

/* 行の「…」のメニュー。ポップオーバーは画面の最前面に出るので、表のスクロールで切れない。 */
.row-menu {
  min-width: 11rem;
  text-align: left;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}

/* 押したボタンのすぐ下に出す。位置を合わせられないブラウザでは、画面の中央に出る。 */
@supports (anchor-scope: --a) and (position-area: bottom) {
  .table tbody tr {
    anchor-scope: --row-menu;
  }

  .row-menu-trigger {
    anchor-name: --row-menu;
  }

  .row-menu {
    position-anchor: --row-menu;
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-block;
    inset: auto;
    margin: 0.25rem 0;
  }
}

.row-menu__label {
  max-width: 16rem;
  padding: 0.375rem 0.625rem 0.25rem;
  overflow: hidden;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-menu__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 2rem;
  padding: 0.375rem 0.625rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

.row-menu__item:hover {
  background: var(--accent);
}

.row-menu__item[data-variant="destructive"] {
  color: var(--destructive);
}

.row-menu__item svg {
  width: 1rem;
  height: 1rem;
}

/* 狭い画面では、1件ずつカードの形に並べる。列の見出しは各項目の前に出す。 */
@media (max-width: 48rem) {
  .table,
  .table tbody,
  .table tr,
  .table th,
  .table td {
    display: block;
  }

  /* 列の見出しは見た目だけ隠す。読み上げでは表の見出しとして使われる。 */
  .table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .table tbody tr {
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .table tbody tr:last-child {
    border-width: 1px;
  }

  .table tbody th,
  .table td {
    min-width: 0;
    max-width: none;
    padding: 0.25rem 0;
  }

  .table tbody th {
    margin-bottom: 0.5rem;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
  }

  .table td.num {
    text-align: left;
  }

  .links-table {
    min-width: 0;
  }

  .table td {
    white-space: normal;
  }

  /* カードでは、作成日時と作成者を続けて並べる。 */
  .table td .cell-text {
    display: inline;
  }

  .table td .cell-sub {
    margin-left: 0.5rem;
  }

  /* 狭い画面では転送先も折り返し、全文を見せる。 */
  .row-sub {
    flex-wrap: wrap;
    white-space: normal;
  }

  .row-sub__target {
    overflow: visible;
    overflow-wrap: anywhere;
  }

  /* 見出しの文字は読み上げない。表の見出しと重なるため。 */
  .table td::before {
    /* 読み上げを抑える書き方に対応していないブラウザでも、見出しを表示する。 */
    content: attr(data-label);
    content: attr(data-label) / "";
    display: inline-block;
    min-width: 5.5em;
    margin-right: 0.5rem;
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    font-weight: 600;
  }

  .table td.actions > * + * {
    margin-left: 0;
  }

  .table td.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.5rem;
    text-align: left;
  }

  .table td.actions::before {
    display: none;
  }

}

.muted {
  color: var(--muted-foreground);
  font-weight: 400;
}

pre.code {
  overflow-x: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* 管理画面の一覧で、まとめの中身を開いて見る。 */
.bundle-details summary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 1.5rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.bundle-details summary svg {
  width: 1rem;
  height: 1rem;
}

.bundle-details ol {
  margin-top: 0.5rem;
  padding-left: 1.5em;
  list-style: decimal;
}

/* まとめのページ。クライアントが開く。 */
.bundle-page {
  max-width: 48rem;
  margin: 0 auto;
}

.bundle__count {
  margin-top: 0.5rem;
  color: var(--muted-foreground);
}

.bundle__actions {
  margin: 1.5rem 0;
}

.bundle__actions .alert {
  margin: 1rem 0 0;
}

.bundle {
  counter-reset: bundle;
}

.bundle__item {
  counter-increment: bundle;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.125rem 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.bundle__item:first-child {
  border-top: 0;
}

/* 番号は見た目だけ。順序は ol で読み上げられる。 */
.bundle__item::before {
  content: counter(bundle) / "";
  grid-row: span 2;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
  line-height: 1.75rem;
}

.bundle__link {
  /* 押せる範囲の高さを 24px 以上にする（2.5.8）。 */
  display: inline-block;
  min-height: 1.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.bundle__link svg {
  display: inline;
  width: 1rem;
  height: 1rem;
  margin-left: 0.25rem;
  vertical-align: -0.125em;
}

.bundle__url {
  grid-column: 2;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}

.site-footer {
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.site-footer p {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}

/* コピーの通知。画面の下に出す。 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.2);
}

/* 空のときは見えなくするだけにする。display: none にすると読み上げの領域ごと消え、後から入れた文字が読み上げられないことがあるため。 */
.toast:empty {
  padding: 0;
  background: none;
  box-shadow: none;
}

@media (forced-colors: active) {
  .btn,
  .toast:not(:empty) {
    border: 1px solid CanvasText;
  }
}

/* トップページのカバー。画面の全面に敷き、ヘッダーはその上に重ねる。 */
.cover {
  position: fixed;
  inset: 0;
  z-index: 0;
  /* 指でなぞっても画面が動かないようにする。このページはスクロールしない。
     2本の指での拡大は残す。拡大して見る人の妨げにならないため。対応しないブラウザでは none になる。
     拡大した後に1本の指で画面を動かせるのは、ヘッダーの上だけになる。 */
  touch-action: none;
  touch-action: pinch-zoom;
  /* JavaScript が動かないときに見せる横線。カンバスが描くと、その下に隠れる。間隔はカンバスと同じ 50px で、位置は合わせていない。 */
  background: repeating-linear-gradient(to bottom, transparent 0 49px, var(--border) 49px 50px);
}

.cover__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

body:has(.cover) .site-header {
  position: relative;
  z-index: 1;
  background: var(--background);
}

/* カンバスが描けたら、ヘッダーの境界線は、カバーの1本目の線が代わりに務める。その線も切れる。 */
body:has(.cover[data-ready]) .site-header {
  border-bottom: 0;
}

.cover-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 動きを止める項目は、止めているときは再開のアイコンに替える。 */
.cover-toggle .lucide-play,
.cover-toggle[data-paused="true"] .lucide-pause {
  display: none;
}

.cover-toggle[data-paused="true"] .lucide-play {
  display: block;
}

/* ヘッダーの「⋮」のメニューは、ボタンのすぐ下に右揃えで出す。位置を合わせられないブラウザでは、画面の中央に出る。 */
@supports (position-area: bottom) {
  .cover-menu-trigger {
    anchor-name: --cover-menu;
  }

  .cover-menu {
    position-anchor: --cover-menu;
    position-area: block-end span-inline-start;
    inset: auto;
    margin: 0.25rem 0;
  }
}

body:has(.cover) .site-header__inner {
  justify-content: space-between;
}
