/* ===========================================================================
   style.css — STEP 6 ベースライン (デザイン仕上げは STEP 9 で行う想定)
   配色: ベージュ系背景 + 紺/深緑アクセント (黒板/木製机のイメージ)
   ========================================================================= */

:root {
  --bg:        #faf6ec;
  --surface:   #ffffff;
  --text:      #2a3038;
  --muted:     #6b7280;
  --border:    #e5dccb;
  --accent:    #1f4d3a;          /* 深緑 */
  --accent-2:  #1f3a5f;          /* 紺 */
  --terra:     #b56848;          /* テラコッタ (コード言語ラベル) */
  --code-bg:   #1f2730;
  --code-fg:   #e6e1d3;
  --shadow:    0 1px 2px rgba(40, 30, 20, .05), 0 4px 12px rgba(40, 30, 20, .04);
  --radius:    14px;
  --radius-sm: 8px;
  --container: 1200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #1a1f2e;
    --surface: #232a3c;
    --text:    #e6e1d3;
    --muted:   #9ba3b3;
    --border:  #353d52;
    --accent:  #6db89a;
    --accent-2:#8aa9d8;
    --terra:   #d68a6a;
    --code-bg: #11151e;
    --code-fg: #e6e1d3;
    --shadow:  0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
}

img { max-width: 100%; }

/* ----- ヘッダ ----- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: var(--container);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.site-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.site-title a { color: var(--accent); }
.site-title a:hover { text-decoration: none; }
.auth-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.auth-link {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text);
  font-size: .9rem;
}
.auth-cta {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.auth-cta:hover { text-decoration: none; opacity: .9; }
.auth-logout { color: var(--muted); }
.auth-user {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .9rem;
  color: var(--muted);
}
.auth-user-name {
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}
.auth-placeholder {
  font-size: .85rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
}

/* ----- メインコンテナ ----- */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ----- フィルタバー ----- */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 24px;
}
.filter-bar form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 768px) {
  .filter-bar form {
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    align-items: center;
  }
}
.filter-bar input,
.filter-bar select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.filter-bar button {
  padding: 8px 18px;
  background: var(--accent-2);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
}
.filter-bar button:hover { opacity: .9; }

/* ----- 投稿カード一覧 ----- */
.post-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 768px) {
  .post-list { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1280px) {
  .post-list { grid-template-columns: 1fr 1fr 1fr; }
}
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.post-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(40,30,20,.08), 0 8px 24px rgba(40,30,20,.07);
}
.post-card-link {
  display: block;
  padding: 16px;
  color: inherit;
}
.post-card-link:hover { text-decoration: none; }

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: .8rem;
  margin-bottom: 8px;
}
.post-lang {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--terra);
  color: #fff;
  font-weight: 600;
  letter-spacing: .04em;
}
.post-lang-gas { background: var(--accent); }
.post-genre, .post-cat {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.post-title {
  margin: 8px 0 12px;
  font-size: 1.1rem;
  line-height: 1.4;
  color: var(--text);
}
.badge {
  display: inline-block;
  font-size: .75rem;
  padding: 1px 8px;
  border-radius: 999px;
}
.badge-draft { background: #fff3cd; color: #715000; border: 1px solid #f0d674; }

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.tag {
  font-size: .8rem;
  color: var(--accent-2);
  background: rgba(31, 58, 95, .06);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 1px 8px;
}
@media (prefers-color-scheme: dark) {
  .tag { background: rgba(138, 169, 216, .12); }
}

.post-author {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: .8rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.post-author .avatar { width: 20px; height: 20px; }
.post-stats { margin-left: auto; }

/* ----- ページネーション ----- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
  font-size: .9rem;
}
.pagination a, .pagination .disabled {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.pagination a { background: var(--surface); color: var(--text); }
.pagination .disabled { color: var(--muted); opacity: .5; }
.page-info { color: var(--muted); }

/* ----- 空・エラー ----- */
.empty, .error, .loading {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

/* ===========================================================================
   投稿詳細ページ (post.html)
   ========================================================================= */

.post-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
@media (min-width: 768px) {
  .post-detail { padding: 32px; }
}

.post-detail .post-title {
  font-size: 1.6rem;
  margin: 8px 0 16px;
}

.post-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.btn {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn-edit { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.btn-delete { background: transparent; color: #b94a48; border-color: #e5b8b6; }

.post-description {
  margin: 24px 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.8;
}

.post-code-section {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.06);
  color: var(--code-fg);
  font-size: .85rem;
}
.code-lang { font-weight: 600; letter-spacing: .04em; opacity: .85; }
.btn-copy {
  background: rgba(255,255,255,.08);
  color: var(--code-fg);
  border: 1px solid rgba(255,255,255,.15);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
}
.btn-copy:hover { background: rgba(255,255,255,.14); }
.btn-copy.copied { background: var(--accent); border-color: var(--accent); }

.post-code {
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: var(--code-fg);
  font-family: "SF Mono", "Cascadia Mono", "Consolas", "Menlo", monospace;
  font-size: .9rem;
  line-height: 1.55;
  tab-size: 2;
}
.post-code code { font: inherit; color: inherit; white-space: pre; }

/* ===========================================================================
   シンタックスハイライト (highlight.js が出力する <span class="tok-..."> 用)
   コードブロックは常に暗背景 (--code-bg) なので、そこに映える配色にする。
   ========================================================================= */
.post-code .tok-comment   { color: #7a8a7e; font-style: italic; }
.post-code .tok-string    { color: #d4a079; }
.post-code .tok-number    { color: #c897e0; }
.post-code .tok-keyword   { color: #7fb3d5; font-weight: 500; }
.post-code .tok-builtin   { color: #b6cf8a; }
.post-code .tok-property  { color: #d4b87a; }
.post-code .tok-function  { color: #f0d674; }
.post-code .tok-tag       { color: #7fc6a4; }
.post-code .tok-attr      { color: #b6cf8a; }
.post-code .tok-doctype   { color: #7a8a7e; }
.post-code .tok-entity    { color: #c897e0; }
.post-code .tok-punct     { color: #9aa3b5; }

/* ===========================================================================
   STEP 9: 仕上げ (ロゴ・ヒーロー・人気タグ・フッタ・focus-visible)
   ========================================================================= */

/* ロゴ -------------------------------------------------------------------- */
.site-title a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.site-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.05));
}

/* ヒーロー ---------------------------------------------------------------- */
.hero {
  background: linear-gradient(135deg, rgba(31, 77, 58, .08), rgba(181, 104, 72, .06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.hero h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  line-height: 1.55;
  color: var(--text);
}
.hero p {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}
.hero .hl-html { color: var(--terra);  font-weight: 700; letter-spacing: .02em; }
.hero .hl-gas  { color: var(--accent); font-weight: 700; letter-spacing: .02em; }

/* 人気タグウィジェット ----------------------------------------------------- */
.popular-tags-widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
}
.widget-title {
  margin: 0 0 10px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: none;
}
.popular-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-link {
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.tag-link small {
  margin-left: 4px;
  opacity: .65;
  font-size: .75rem;
}
.tag-link:hover {
  text-decoration: none;
  background: var(--accent-2);
  color: #fff;
  transform: translateY(-1px);
}

/* フッタ ------------------------------------------------------------------ */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 22px 20px;
  margin-top: 48px;
}
.footer-inner {
  max-width: var(--container);
  margin: 0 auto;
  text-align: center;
}
.footer-text {
  margin: 0;
  font-size: .9rem;
  color: var(--muted);
}
.footer-meta {
  margin: 4px 0 0;
  font-size: .78rem;
  color: var(--muted);
  opacity: .7;
}

/* container 下の余白はフッタに任せる */
.container { padding-bottom: 32px; }

/* キーボード操作のフォーカス枠 (マウスクリック時は出ない) -------------------- */
:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
  border-radius: 3px;
}
.btn:focus-visible,
.auth-link:focus-visible {
  outline-offset: 3px;
}

/* 共通トランジション ----------------------------------------------------- */
.btn,
.auth-link,
.tag,
.post-card {
  transition:
    background-color .15s ease,
    border-color     .15s ease,
    color            .15s ease,
    transform        .15s ease,
    box-shadow       .15s ease,
    opacity          .15s ease;
}

/* モーション控えめユーザーには動かさない */
@media (prefers-reduced-motion: reduce) {
  .post-card:hover { transform: none; }
  .tag-link:hover  { transform: none; }
}

/* ===========================================================================
   ログインボタン (GIS) スロット
   ========================================================================= */
.auth-gis-btn { display: inline-block; }
.auth-gis-btn iframe { vertical-align: middle; }

/* ===========================================================================
   投稿フォーム (new.html / edit.html)
   ========================================================================= */
.page-title { font-size: 1.4rem; margin: 8px 0 20px; }

.post-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (min-width: 768px) {
  .post-form { padding: 28px 32px; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  border: none;
  padding: 0;
  min-width: 0;          /* fieldset の overflow 抑止 */
}
.form-group legend {
  padding: 0;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-label {
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
}
.form-label small {
  font-weight: 400;
  margin-left: 6px;
  color: var(--muted);
  opacity: .85;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 480px) {
  .form-row { grid-template-columns: 1fr 1.4fr; }
}
.post-form input[type="text"],
.post-form input[type="search"],
.post-form select,
.post-form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}
.post-form select:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.post-form textarea {
  resize: vertical;
}
.code-textarea {
  font-family: "SF Mono", "Cascadia Mono", "Consolas", "Menlo", monospace;
  font-size: .9rem;
  tab-size: 2;
  background: var(--code-bg) !important;
  color: var(--code-fg) !important;
  border-color: rgba(255,255,255,.12) !important;
  min-height: 380px;
}
.lang-radios {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.lang-radios label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.form-error {
  margin: 0;
  color: #b94a48;
  min-height: 1.4em;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { opacity: .9; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* ===========================================================================
   タグ入力 UI (チップ + テキスト + 補完候補)
   ========================================================================= */
.tag-input {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 6px 8px;
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.tag-input:focus-within {
  outline: 2px solid var(--accent-2);
  outline-offset: 0;
  border-color: transparent;
}
.tag-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: contents;        /* チップを直接 flex 子要素として配置 */
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  background: rgba(31, 58, 95, .08);
  color: var(--accent-2);
  border-radius: 999px;
  font-size: .85rem;
}
@media (prefers-color-scheme: dark) {
  .tag-chip { background: rgba(138, 169, 216, .15); }
}
.tag-chip button {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
  border-radius: 999px;
  opacity: .6;
}
.tag-chip button:hover { opacity: 1; }

.tag-input [data-tag-text] {
  flex: 1;
  min-width: 8em;
  border: none;
  background: transparent;
  outline: none;
  padding: 4px 4px;
  color: var(--text);
  font: inherit;
}

.tag-suggestions {
  position: absolute;
  list-style: none;
  margin: 0;
  padding: 4px;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 5;
  max-height: 240px;
  overflow: auto;
}
.tag-suggestions[hidden] { display: none; }
.tag-sug {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .9rem;
}
.tag-sug:hover { background: var(--bg); }
.tag-sug-count {
  color: var(--muted);
  font-size: .75rem;
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 8px;
}

/* ===========================================================================
   マイページ
   ========================================================================= */
.my-summary { margin-bottom: 24px; }
.my-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
}
.my-card-body { min-width: 0; }
.my-name {
  font-weight: 600;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.my-email {
  color: var(--muted);
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar-lg {
  width: 56px;
  height: 56px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
