/* ===========================================================
   GF STORY ARCHIVE — iOS PWA 版
   The Division 风格 + iPhone 单栏触控布局
   =========================================================== */

:root {
  --bg:        #0d0f0e;
  --bg-2:      #141715;
  --bg-3:      #1b1f1c;
  --panel:     #171a17;
  --line:      #2e352f;
  --line-2:    #454e44;
  --text:      #d8dcd5;
  --text-dim:  #8b928a;
  --text-mute: #5d645d;
  --accent:    #f29b1d;
  --accent-2:  #ffc04d;
  --accent-dim:#8a5c14;
  --font: -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --fs: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: var(--fs); -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-image:
    linear-gradient(rgba(255,255,255,.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.014) 1px, transparent 1px),
    radial-gradient(ellipse at 50% 0%, #1a1e1a 0%, #0d0f0e 62%);
  background-size: 40px 40px, 40px 40px, 100% 100%;
}

/* 扫描线 */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 9998;
  background: repeating-linear-gradient(0deg,
    rgba(0,0,0,.09) 0px, rgba(0,0,0,.09) 1px,
    transparent 1px, transparent 3px);
  opacity: .4;
}

/* ---------------- 顶部栏 ---------------- */
#topbar {
  height: calc(52px + var(--safe-t));
  padding: var(--safe-t) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, #171b17 0%, #101310 100%);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 100;
}
#topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .55;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: flex; gap: 3px; align-items: flex-end; height: 20px; }
.brand-mark span {
  width: 3px; background: var(--accent);
  box-shadow: 0 0 7px rgba(242,155,29,.8);
  animation: bars 2.4s ease-in-out infinite;
}
.brand-mark span:nth-child(1) { height: 9px; }
.brand-mark span:nth-child(2) { height: 18px; animation-delay: .25s; }
.brand-mark span:nth-child(3) { height: 12px; animation-delay: .5s; }
@keyframes bars { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.brand-text b {
  display: block; font-size: .84rem; letter-spacing: .14em;
  font-weight: 700; color: #eef0ea;
}
.brand-text i {
  display: block; font-size: .56rem; letter-spacing: .26em;
  color: var(--accent); font-style: normal; margin-top: 1px;
}

.tb-right { display: flex; align-items: center; gap: 8px; }

button.ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line-2);
  min-height: 34px; padding: 6px 12px;
  font-size: .72rem; letter-spacing: .1em;
  font-family: var(--font); cursor: pointer;
  transition: all .15s ease;
  clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
}
button.ghost:active {
  color: #fff; border-color: var(--accent);
  background: rgba(242,155,29,.18);
  transform: scale(.96);
}
button.ghost:disabled { opacity: .28; }
#btn-font span { color: var(--accent); font-weight: 700; }
#btn-home { font-size: .62rem; min-width: 34px; }

/* ---------------- 视图容器 ---------------- */
#stage {
  height: calc(100dvh - 52px - var(--safe-t));
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
#stage::-webkit-scrollbar { width: 0; display: none; }

.view { display: none; padding: 20px 16px calc(30px + var(--safe-b)); }
.view.active { display: block; animation: fade .24s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- 标题区 ---------------- */
.page-head { text-align: center; margin: 16px 0 26px; }
.page-head.left { text-align: left; margin: 6px 0 18px; }
.ph-line {
  width: 40px; height: 2px; background: var(--accent); margin: 0 auto 12px;
  box-shadow: 0 0 10px rgba(242,155,29,.7);
}
.page-head.left .ph-line { margin: 0 0 10px; }
.page-head h1 {
  font-size: 1.06rem; letter-spacing: .26em; font-weight: 300;
  color: #f2f4ee; text-transform: uppercase;
}
.page-head p { font-size: .7rem; letter-spacing: .1em; color: var(--text-mute); margin-top: 8px; }

.crumb {
  font-family: var(--mono); font-size: .64rem; color: var(--text-mute);
  letter-spacing: .06em; margin-bottom: 14px; line-height: 1.6;
  word-break: break-all;
}
.crumb b { color: var(--accent); font-weight: 500; }
.crumb .sep { margin: 0 5px; color: var(--line-2); }

.hint { text-align: center; margin-top: 24px; font-size: .62rem; color: var(--text-mute); letter-spacing: .1em; }

/* 离线缓存控制 */
.offline-box { margin-top: 22px; text-align: center; }
.offline-box button { width: 100%; min-height: 42px; font-size: .74rem; }
.offline-box button.done {
  border-color: #4a7a33; color: #8fd14f; background: rgba(143,209,79,.10);
}
.warm-status {
  margin-top: 9px; font-family: var(--mono); font-size: .6rem;
  color: var(--text-mute); letter-spacing: .06em; line-height: 1.7;
}
.warm-status b { color: var(--accent); }

/* ---------------- 屏1：作品卡片 ---------------- */
.part-grid { display: flex; flex-direction: column; gap: 14px; }

.part-card {
  position: relative; background: linear-gradient(150deg, #1c211c 0%, #12150f 100%);
  border: 1px solid var(--line);
  padding: 24px 20px 20px; cursor: pointer;
  transition: transform .15s ease; overflow: hidden;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px));
}
.part-card:active { transform: scale(.982); border-color: var(--accent-dim); }
.part-card::before {
  content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: .65;
}

.pc-tag {
  font-family: var(--mono); font-size: .56rem; letter-spacing: .18em;
  color: var(--accent); margin-bottom: 12px; display: flex; align-items: center; gap: 7px;
}
.pc-tag::before {
  content: ""; width: 6px; height: 6px; background: var(--accent);
  box-shadow: 0 0 8px var(--accent); animation: pulse 1.8s infinite;
  border-radius: 50%;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.part-card h2 {
  font-size: 1.16rem; font-weight: 600; letter-spacing: .02em;
  color: #f4f6f0; margin-bottom: 6px; line-height: 1.35;
}
.part-card .pc-en {
  font-family: var(--mono); font-size: .58rem; color: var(--text-mute);
  letter-spacing: .1em; margin-bottom: 16px; line-height: 1.5;
}
.pc-stats { display: flex; gap: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.pc-stat b {
  display: block; font-family: var(--mono); font-size: 1.02rem;
  color: var(--accent-2); font-weight: 600;
}
.pc-stat i { display: block; font-size: .56rem; color: var(--text-mute); letter-spacing: .1em; font-style: normal; margin-top: 2px; }

/* ---------------- 屏2：分类 ---------------- */
.cat-grid { display: flex; flex-direction: column; gap: 10px; }
.cat-card {
  background: var(--panel); border: 1px solid var(--line);
  padding: 16px 16px; cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 54px;
  transition: transform .12s ease;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%);
}
.cat-card:active { background: #1d221d; transform: scale(.985); border-color: var(--accent-dim); }
.cat-card b { font-size: .94rem; color: #eef0ea; letter-spacing: .04em; font-weight: 500; }
.cat-card .cc-right { display: flex; align-items: center; gap: 10px; }
.cat-card .cc-meta { font-family: var(--mono); font-size: .6rem; color: var(--text-mute); }
.cat-card .cc-arrow { color: var(--accent); font-size: .9rem; }

/* ---------------- 屏3：文档列表 ---------------- */
.col-head {
  padding: 10px 4px; font-family: var(--mono); font-size: .6rem;
  letter-spacing: .15em; color: var(--text-mute);
  display: flex; justify-content: space-between;
  border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.col-head em { color: var(--accent); font-style: normal; }

.book-item {
  padding: 15px 4px; cursor: pointer; border-bottom: 1px solid #1a1e1a;
  border-left: 2px solid transparent; padding-left: 12px;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  min-height: 52px;
}
.book-item:active { background: #1a1f1a; border-left-color: var(--accent); }
.book-item .bi-title { font-size: .88rem; color: var(--text); line-height: 1.42; }
.book-item .bi-n { font-family: var(--mono); font-size: .62rem; color: var(--text-mute); flex-shrink: 0; }

/* ---------------- 屏4：章节列表 ---------------- */
.back-row { margin-bottom: 14px; }
.back-row .ghost { width: 100%; text-align: left; padding-left: 12px; }

.book-head {
  padding: 14px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.book-head h2 {
  font-size: 1.06rem; font-weight: 600; color: #f4f6f0;
  letter-spacing: .02em; margin-bottom: 8px; line-height: 1.4;
}
.book-meta {
  font-family: var(--mono); font-size: .58rem; color: var(--text-mute);
  letter-spacing: .04em; line-height: 1.7; word-break: break-all;
}
.book-meta span { color: var(--accent); }

.chapter-item {
  padding: 15px 4px; cursor: pointer; display: flex; gap: 12px;
  align-items: baseline; border-bottom: 1px solid #171b17;
  border-left: 2px solid transparent; padding-left: 12px;
  min-height: 50px;
}
.chapter-item:active { background: #1a1f1a; border-left-color: var(--accent); }
.chapter-item .ci-n {
  font-family: var(--mono); font-size: .64rem; color: var(--text-mute);
  min-width: 28px; flex-shrink: 0;
}
.chapter-item .ci-t { font-size: .86rem; color: var(--text-dim); line-height: 1.45; }

/* ---------------- 屏5：阅读 ---------------- */
#view-read { padding: 0 0 calc(76px + var(--safe-b)); }

.doc-wrap { padding: 18px 12px 0; }
.doc {
  background: linear-gradient(180deg, #161a16 0%, #12150f 100%);
  border: 1px solid var(--line);
  padding: 26px 20px 30px;
  position: relative;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px));
}
.doc::before {
  content: ""; position: absolute; top: 0; left: 0; width: 120px; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}

#doc-title {
  font-size: 1.12rem; font-weight: 600; color: #f6f8f2;
  letter-spacing: .02em; line-height: 1.5; margin-bottom: 10px;
}
.doc-meta {
  font-family: var(--mono); font-size: .58rem; color: var(--text-mute);
  letter-spacing: .04em; padding-bottom: 14px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line); line-height: 1.7; word-break: break-all;
}
.doc-meta em { color: var(--accent); font-style: normal; }

.doc-body p {
  font-size: 1rem; line-height: 1.95; margin-bottom: 14px;
  color: var(--text); word-break: break-word;
  white-space: pre-wrap;
}
.doc-body p.sp .who {
  color: var(--accent-2); font-weight: 600; margin-right: 6px;
}
.doc-body p.narr {
  color: #9aa298; font-style: italic;
  padding-left: 11px; border-left: 2px solid #2c332c;
}
.doc-end {
  margin-top: 34px; text-align: center;
  font-family: var(--mono); font-size: .56rem; letter-spacing: .26em;
  color: var(--text-mute); opacity: .6;
}

/* 底部浮动翻页栏 */
.read-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px calc(10px + var(--safe-b));
  background: rgba(13,16,13,.97);
  border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.read-nav button { flex: 1; min-height: 42px; }
#read-pos {
  font-family: var(--mono); font-size: .64rem; color: var(--text-mute);
  letter-spacing: .06em; min-width: 66px; text-align: center;
}

/* ---------------- 载入层 ---------------- */
#loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  transition: opacity .4s;
}
#loader.hide { opacity: 0; pointer-events: none; }
#loader p { font-family: var(--mono); font-size: .64rem; letter-spacing: .18em; color: var(--text-mute); }
.ld { display: flex; gap: 5px; align-items: flex-end; height: 28px; }
.ld span { width: 4px; background: var(--accent); box-shadow: 0 0 10px rgba(242,155,29,.8); animation: ldbar 1.1s ease-in-out infinite; }
.ld span:nth-child(1) { height: 11px; }
.ld span:nth-child(2) { height: 24px; animation-delay: .16s; }
.ld span:nth-child(3) { height: 16px; animation-delay: .32s; }
@keyframes ldbar { 0%,100% { transform: scaleY(.45); opacity: .45; } 50% { transform: scaleY(1); opacity: 1; } }

/* ---------------- 大屏（iPad）微调 ---------------- */
@media (min-width: 700px) {
  .view { padding: 28px 40px calc(40px + var(--safe-b)); }
  .part-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
  .cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .doc-wrap { padding: 26px 24px 0; }
  .doc { padding: 36px 40px 44px; max-width: 720px; margin: 0 auto; }
  .read-nav { max-width: 720px; margin: 0 auto; }
}
