/* ==========================================================================
   曲奇小镇 · 全站样式表 (style.css)
   主题：温暖烘焙 × Minecraft —— 奶油底 / 可可深色页眉 / 焦糖主色 / 草绿点缀
   说明：配色与尺寸集中在 :root 设计令牌，换肤只需改变量，无需动结构样式。
   ========================================================================== */

/* ---------- 1. 设计令牌 ---------- */
:root {
    /* 背景与表面 */
    --bg: #f6f1e7;
    --bg-grad: radial-gradient(1100px 520px at 50% -8%, #fff8ec 0%, rgba(255, 248, 236, 0) 62%);
    --surface: #fffdf9;
    --surface-2: #f5eee1;
    --surface-3: #ece0cd;
    --border: #e6dac7;
    --border-strong: #d6c5aa;

    /* 文本 */
    --text: #3b3027;
    --text-soft: #6f6152;
    --text-muted: #96856f;

    /* 主色（焦糖） */
    --primary: #c1743c;
    --primary-dark: #a45e2c;
    --primary-soft: #f7e8d8;
    --on-primary: #fffaf3;

    /* 点缀（草绿，呼应 Minecraft / 成功态） */
    --accent: #6a8f3c;
    --accent-soft: #eaf1dd;

    /* 危险 */
    --danger: #c0453b;
    --danger-dark: #a8382f;
    --danger-soft: #f8e5e2;

    /* 权限着色：管理员紫 / 成员绿 / 访客蓝 / 被标记红 */
    --perm-admin: #6c3fa0;
    --perm-common: #4f7a28;
    --perm-visitor: #2f6fb0;
    --perm-marked: #c0392b;

    /* 页眉（可可深色渐变） */
    --header-1: #4a3728;
    --header-2: #6d4e32;
    --header-text: #f7efe2;

    /* 尺寸 */
    --radius: 14px;
    --radius-sm: 9px;
    --radius-pill: 999px;
    --gap: 16px;
    --container: 1160px;

    /* 阴影 */
    --shadow-sm: 0 1px 3px rgba(74, 55, 40, .08);
    --shadow: 0 4px 16px rgba(74, 55, 40, .10);
    --shadow-lg: 0 14px 40px rgba(74, 55, 40, .16);
    --ring: 0 0 0 3px rgba(193, 116, 60, .28);

    /* 字体 */
    --font: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ---------- 2. 重置与基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    background-image: var(--bg-grad);
    background-attachment: fixed;
    background-repeat: no-repeat;
}

img { max-width: 100%; display: block; }

a { color: var(--primary-dark); }

::selection { background: var(--primary-soft); color: var(--primary-dark); }

/* 键盘可达性：仅 :focus-visible 描边（输入框另有聚焦光环） */
a:focus-visible,
button:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------- 3. 页眉 / 页脚 / 布局 ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem 1rem;
    flex-wrap: wrap;
    padding: .7rem 1.25rem;
    color: var(--header-text);
    background: linear-gradient(135deg, var(--header-1), var(--header-2));
    box-shadow: 0 2px 14px rgba(50, 35, 22, .28);
}

.site-title {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: .5px;
}

.site-title a {
    color: var(--header-text);
    text-decoration: none;
}

.site-title a:hover { opacity: .88; }

.auth-nav {
    display: flex;
    align-items: center;
    gap: .35rem .55rem;
    flex-wrap: wrap;
}

.auth-nav a {
    display: inline-block;
    padding: .34rem .72rem;
    color: var(--header-text);
    text-decoration: none;
    font-size: .88rem;
    border-radius: var(--radius-pill);
    opacity: .92;
    transition: background .15s ease, opacity .15s ease;
}

.auth-nav a:hover { background: rgba(255, 255, 255, .14); opacity: 1; }

main {
    flex: 1 0 auto;
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 1.6rem 1.25rem 3rem;
}

.list-section,
.form-section,
.module-nav,
.detail-section { margin-bottom: 2.1rem; }

section > h2 {
    display: flex;
    align-items: center;
    gap: .55rem;
    margin: 0 0 1.05rem;
    padding-bottom: .55rem;
    font-size: 1.28rem;
    color: var(--text);
    border-bottom: 2px solid var(--border);
}

section > h2::before {
    content: "";
    width: 6px;
    height: 1.05em;
    border-radius: 3px;
    background: linear-gradient(var(--primary), var(--accent));
}

.site-footer {
    flex-shrink: 0;
    padding: 1.2rem 1rem;
    text-align: center;
    font-size: .84rem;
    color: var(--text-muted);
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.site-footer p { margin: 0; }

.site-footer p + p { margin-top: .35rem; }

/* ICP 备案号：工信部要求可点击跳转至备案查询系统 */
.icp-beian a {
    color: var(--text-muted);
    text-decoration: none;
}

.icp-beian a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* ---------- 4. 会话状态区 ---------- */
.session-status {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .88rem;
    color: var(--header-text);
}

.session-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, .5);
}

.session-name { font-weight: 600; }

.session-logout {
    padding: .3rem .7rem;
    font: inherit;
    font-size: .78rem;
    color: var(--header-text);
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background .15s ease;
}

.session-logout:hover { background: rgba(255, 255, 255, .24); }

/* ---------- 5. 按钮（.tile-action 家族） ---------- */
.tile-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem 1rem;
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--on-primary);
    text-decoration: none;
    background: var(--primary);
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: background .15s ease, transform .06s ease, box-shadow .15s ease, opacity .15s ease;
}

.tile-action:hover { background: var(--primary-dark); }

.tile-action:active { transform: translateY(1px); }

.tile-action:disabled,
.tile-action.disabled {
    opacity: .5;
    cursor: not-allowed;
    box-shadow: none;
}

.tile-action-danger { background: var(--danger); }
.tile-action-danger:hover { background: var(--danger-dark); }

.tile-action-secondary {
    color: var(--text-soft);
    background: transparent;
    border-color: var(--border-strong);
    box-shadow: none;
}

.tile-action-secondary:hover { background: var(--surface-2); color: var(--text); }

.tile-detail-link {
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-color: #ecd6bd;
}

.tile-detail-link:hover { background: #f1dcc6; }

/* ---------- 6. 磁贴卡片（.tile / .tile-item） ---------- */
.tile {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    min-width: 0;
    padding: 1rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}

.tile-row {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    line-height: 1.5;
}

.tile-key {
    flex: 0 0 auto;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.tile-val {
    flex: 1 1 auto;
    min-width: 0;
    font-size: .92rem;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* 磁贴内的操作行：与内容用虚线分隔 */
.tile-item > .tile-actions {
    margin-top: .55rem;
    padding-top: .65rem;
    border-top: 1px dashed var(--border);
}

/* ---------- 6b. 用户磁贴头部：头像 + 用户名 + 内联标签 + 权限徽章 +「我」标识 ---------- */
.user-head {
    display: flex;
    align-items: center;
    gap: .7rem;
}

.user-head-text { flex: 1 1 auto; min-width: 0; }

.user-name-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .4rem;
}

.user-name {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text);
    overflow-wrap: anywhere;
}

.tile-avatar {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    border: 2px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
}

/* 权限 -> --perm 变量（权限徽章与磁贴左边框共用同一着色） */
.perm-admin { --perm: var(--perm-admin); }
.perm-common { --perm: var(--perm-common); }
.perm-visitor { --perm: var(--perm-visitor); }
.perm-marked { --perm: var(--perm-marked); }

/* 权限徽章 */
.perm-badge {
    display: inline-flex;
    align-items: center;
    padding: .06rem .5rem;
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.7;
    white-space: nowrap;
    color: var(--perm, var(--text-muted));
    background: color-mix(in srgb, var(--perm, #9a8b78) 13%, #fff);
    border: 1px solid color-mix(in srgb, var(--perm, #9a8b78) 42%, #fff);
    border-radius: var(--radius-pill);
}

/* 磁贴按权限着左边框 */
.tile-item.perm-admin,
.tile-item.perm-common,
.tile-item.perm-visitor,
.tile-item.perm-marked {
    border-left: 4px solid var(--perm);
}

/* 内联用户标签（直接跟在用户名后，标签不会很长） */
.user-tag {
    display: inline-flex;
    align-items: center;
    padding: .04rem .45rem;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-soft);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

/*「我」标识 + 当前登录用户高亮描边 */
.me-badge {
    display: inline-flex;
    align-items: center;
    padding: .04rem .45rem;
    font-size: .7rem;
    font-weight: 800;
    white-space: nowrap;
    color: var(--on-primary);
    background: var(--primary);
    border-radius: var(--radius-pill);
}

.tile-item.is-me { box-shadow: 0 0 0 2px var(--primary), var(--shadow); }

/* 面板内嵌套的用户 chip：头像更小 */
.tile-panel-list .tile-avatar { width: 38px; height: 38px; }

/* 图片行：缩略图 + 移除按钮 */
.tile-picture {
    flex-direction: row;
    align-items: center;
    gap: .8rem;
}

.tile-picture a { flex: 0 0 auto; line-height: 0; }

.picture-thumb {
    width: 108px;
    height: 80px;
    object-fit: cover;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: transform .18s ease, box-shadow .18s ease;
}

.tile-picture a:hover .picture-thumb {
    transform: scale(1.03);
    box-shadow: var(--shadow);
}

/* ---------- 7. 网格 / 列表 / 分页 ---------- */
/* 首页导航：.tile-grid 直接容纳 <a class="tile"> */
.tile-grid {
    display: grid;
    gap: var(--gap);
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

/* 列表页：.tile-grid[data-endpoint] 容纳 .tile-list-items + .tile-pager，纵向堆叠 */
.tile-grid[data-endpoint] { display: block; }

.tile-list-items {
    display: grid;
    gap: var(--gap);
    align-items: start;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.module-nav a.tile {
    position: relative;
    overflow: hidden;
    padding: 1.25rem 1.2rem 1.15rem;
    text-decoration: none;
    color: inherit;
}

.module-nav a.tile::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.module-nav a.tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--border-strong);
}

.module-nav a.tile h3 {
    margin: 0;
    font-size: 1.14rem;
    color: var(--primary-dark);
}

.module-nav a.tile p {
    margin: .3rem 0 0;
    font-size: .88rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.tile-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-top: 1.1rem;
}

.pager-info { font-size: .84rem; color: var(--text-muted); }

.pager-btn { padding: .42rem .9rem; font-size: .82rem; }

/* ---------- 8. 表单 ---------- */
.tile-form {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

.tile-field {
    display: flex;
    flex-direction: column;
    gap: .32rem;
}

.tile-field > label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-soft);
}

.tile-field input,
.tile-field select,
.tile-field textarea,
.tile-upload input[type="file"] {
    width: 100%;
    padding: .55rem .7rem;
    font: inherit;
    font-size: .9rem;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.tile-field textarea { resize: vertical; min-height: 76px; }

.tile-field input[type="file"] {
    padding: .4rem;
    background: var(--surface-2);
    border-style: dashed;
    cursor: pointer;
}

.tile-field input:focus,
.tile-field select:focus,
.tile-field textarea:focus,
.tile-upload input[type="file"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

.field-hint { font-size: .74rem; color: var(--text-muted); }

.form-message {
    margin: .15rem 0 0;
    font-size: .83rem;
    color: var(--text-soft);
}

.form-message:empty { display: none; }
.form-message.error { color: var(--danger); }
.form-message.success { color: var(--accent); }

/* 权限不足时的禁用态 */
.tile-form.disabled { opacity: .72; }

.tile-form.disabled .tile-field input,
.tile-form.disabled .tile-field textarea,
.tile-form.disabled .tile-field select { background: var(--surface-2); }

/* 上传控件 */
.tile-upload {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .55rem;
}

.tile-upload input[type="file"] { width: 100%; }

/* ---------- 9. 折叠面板（details / summary） ---------- */
summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }

/* 9a. 大面板 .tile-panel：成员 / 建造者 / 坐标 / 图片 / 评论 / 回复 … */
.tile-panel {
    margin-top: .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.tile-panel > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .6rem .85rem;
    font-size: .9rem;
    font-weight: 700;
    color: var(--text-soft);
    background: var(--surface-2);
    user-select: none;
    transition: background .15s ease, color .15s ease;
}

.tile-panel > summary:hover { background: var(--surface-3); color: var(--text); }

.tile-panel > summary::after {
    content: "▸";
    font-size: .78rem;
    color: var(--text-muted);
    transition: transform .18s ease;
}

.tile-panel[open] > summary { border-bottom: 1px solid var(--border); }
.tile-panel[open] > summary::after { transform: rotate(90deg); }

.tile-panel > .tile-panel-list { padding: .75rem .85rem; }
.tile-panel > .tile-panel-forms { padding: .5rem .85rem .85rem; }
.tile-panel-forms:empty { display: none; }

.tile-panel-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

/* 面板内嵌套的子磁贴：更轻的背景以体现层级 */
.tile-panel-list .tile-item {
    padding: .6rem .75rem;
    background: var(--surface-2);
    border-color: var(--border);
    border-radius: var(--radius-sm);
    box-shadow: none;
}

.tile-panel-forms {
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

/* 9b. 子表单 .tile-subform：编辑 / 改状态 / 添加 / 移除 / 发表回复 …
      summary 做成次级按钮；混排在 .tile-actions 里时，展开后独占整行以容纳表单。 */
.tile-subform > summary {
    display: inline-flex;
    align-items: center;
    gap: .38rem;
    padding: .45rem .85rem;
    font-size: .84rem;
    font-weight: 600;
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    user-select: none;
    transition: background .15s ease;
}

.tile-subform > summary:hover { background: #f0dcc5; }

.tile-subform > summary::after {
    content: "▸";
    font-size: .72rem;
    color: var(--primary);
    transition: transform .18s ease;
}

.tile-subform[open] > summary::after { transform: rotate(90deg); }

.tile-subform > .tile-form,
.tile-subform > .tile-upload {
    margin-top: .5rem;
    padding: .8rem .85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* 操作行：按钮与折叠子表单混排，自动换行 */
.tile-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: .35rem;
}

.tile-actions > .tile-subform { flex: 0 0 auto; }
.tile-actions > .tile-subform[open] { flex: 1 1 100%; }

/* 9c. 创建面板 .create-panel —— 固定于视口右下角的浮动操作按钮（FAB）
      收起时是一枚药丸按钮；展开后成为定宽浮层卡片，表单区内部可滚动。
      这样「创建小镇 / 提交地标 / 发布公告 / 发表留言…」无需滚到页底即可随时触达。 */
.form-section:has(.create-panel) { margin-bottom: 0; }

/* 预留底部空间，避免浮动按钮遮挡列表最后一条 / 分页器 */
main:has(.create-panel) { padding-bottom: 5.5rem; }

.create-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 60;
    width: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* 收起：紧凑药丸 FAB */
.create-panel > summary.create-toggle {
    width: auto;
    padding: .82rem 1.35rem;
    font-size: .95rem;
    border-radius: var(--radius-pill);
    box-shadow: none;
}

/* 展开：定宽卡片 */
.create-panel[open] {
    width: min(400px, calc(100vw - 32px));
    border-radius: var(--radius);
}

.create-panel[open] > summary.create-toggle {
    display: flex;
    width: 100%;
    justify-content: center;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
}

.create-panel .tile-form {
    padding: 1.05rem 1.15rem;
    max-height: min(70vh, 540px);
    overflow-y: auto;
}

/* 认证页（登录/注册）无 create-panel，表单直接置于 form-section：包成居中卡片 */
.form-section > .tile-form {
    max-width: 460px;
    margin: 0 auto;
    padding: 1.4rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---------- 10. 状态提示 ---------- */
.empty-hint {
    padding: .6rem .2rem;
    font-size: .9rem;
    font-style: italic;
    color: var(--text-muted);
}

.empty-hint.error { color: var(--danger); font-style: normal; }

/* ---------- 11. 地标详情页 ---------- */
.detail-section { max-width: 900px; }

.landmark-detail > .tile-item,
.user-detail > .tile-item {
    padding: 1.3rem 1.45rem;
    box-shadow: var(--shadow);
}

.landmark-detail > .tile-item > .tile-row:first-of-type .tile-val {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* ---------- 12. 响应式 ---------- */
@media (max-width: 720px) {
    body { font-size: 14.5px; }

    .site-header { padding: .6rem .9rem; }
    .site-title { font-size: 1.22rem; }

    main { padding: 1.15rem .9rem 2.5rem; }

    section > h2 { font-size: 1.15rem; }

    .tile-grid,
    .tile-list-items { grid-template-columns: 1fr; }

    .detail-section { max-width: none; }

    /* 浮动创建按钮：移动端收窄边距 */
    .create-panel { right: 16px; bottom: 16px; }
    .create-panel > summary.create-toggle { padding: .75rem 1.15rem; font-size: .9rem; }
}

@media (max-width: 420px) {
    .auth-nav { gap: .3rem .4rem; }
    .auth-nav a { padding: .3rem .55rem; font-size: .82rem; }
    .tile { padding: .85rem .9rem; }
    .tile-action { padding: .45rem .8rem; font-size: .82rem; }
}

/* 首页主镇轮播图 */
.main-town-carousel {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    margin-bottom: 24px;
}
.carousel-viewport {
    display: flex;
    transition: transform .4s ease;
}
.carousel-slide {
    width: 100%;
    flex-shrink: 0;
    height: 320px;
    object-fit: cover;
    display: block;
}
.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    background: rgba(0, 0, 0, .35);
    color: #fff;
}
.carousel-prev { left: 12px; }
.carousel-next { right: 12px; }
.carousel-dots {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
}
.carousel-dot {
    width: 10px;
    height: 10px;
    border: none;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    background: rgba(255, 255, 255, .5);
}
.carousel-dot.active { background: #fff; }

/* 首页主镇简介 */
.main-town-intro { margin-bottom: 24px; }

.comment-block { border-top: 1px solid #e5e0d8; padding: 10px 0; }
.comment-item { padding: 4px 0; }
.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: #8a8578; }
.comment-author { font-weight: 600; color: #5b8def; }
.comment-replyto { color: #b04a4a; }
.comment-content { margin: 4px 0; white-space: pre-wrap; }
.comment-actions { display: flex; gap: 8px; align-items: center; }
.comment-replies { margin-left: 24px; border-left: 2px solid #ece7dd; padding-left: 12px; }
.reply-form { display: flex; gap: 8px; margin: 6px 0; }
.reply-form textarea { flex: 1; }

.comment-replies {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 2px solid #e3e5e7;
}
.reply-toggle {
    margin-top: 4px;
}