/* 归途 · Nostos —— 红绘陶器色盘 + Q 版卡通。所有画面由 canvas 程序化绘制，无图片资源。 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --terra:  #c1512f;   /* 赤陶红（主色） */
  --terra2: #a33f22;
  --clay:   #e8c9a0;   /* 陶土底 */
  --clay-lt:#f5e2c4;
  --ink:    #241f33;   /* 描边（与 towerclash 的 OUTLINE 一致） */
  --ink-2:  #3a3350;
  --sea:    #1b3a5c;
  --wine:   #5b2a3e;   /* 酒色的海 */
  --bronze: #d9a441;
  --olive:  #6b7f4a;
  --bone:   #efe6d2;
  --good:   #4d8c4a;
  --bad:    #b3402c;
  /* 四色牌 */
  --c-bie:    #c1512f;
  --c-metis:  #3f6fa8;
  --c-peitho: #5c8f5a;
  --c-endure: #d9a441;
  --c-comp:   #8a5fa8;
  --c-relic:  #2fa08f;
  --c-wrath:  #4a4458;
}
html, body {
  height: 100%;
  background: #17121c;
  color: var(--ink);
  font-family: 'Noto Serif SC', 'DM Sans', Georgia, serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;            /* 禁 iPad 双击放大，保留点击 */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.screen { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
.grow { flex: 1; }

/* ===== 开始菜单 ===== */
.start {
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 26%, rgba(217,164,65,0.20), transparent 62%),
    linear-gradient(165deg, #2a1a22, #12101a);
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}
.start-card {
  max-width: 660px; text-align: center; color: var(--clay);
  background: rgba(28,20,26,0.58);
  border: 1px solid rgba(217,164,65,0.30);
  border-radius: 18px; padding: 40px 36px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.eyebrow { letter-spacing: .24em; font-size: 12px; color: var(--bronze); margin-bottom: 12px; }
.start-card h1 {
  font-size: 58px; letter-spacing: .22em; color: var(--clay-lt);
  text-shadow: 0 3px 18px rgba(0,0,0,.65);
}
.start-card .sub {
  font-family: 'DM Sans', sans-serif; letter-spacing: .52em;
  color: var(--terra); font-size: 13px; margin: 10px 0 22px; font-weight: 700;
}
.tagline { color: #dcc6a4; line-height: 2.0; font-size: 15px; margin-bottom: 26px; }
.tagline i { color: var(--bronze); }
.start-btns { display: flex; flex-direction: column; gap: 12px; }
.foot { margin-top: 22px; font-size: 12px; color: #8c7a66; font-family: 'DM Sans', sans-serif; }
.foot a { color: var(--bronze); }

.primary-btn, .ghost-btn {
  border-radius: 10px; padding: 11px 20px; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; transition: filter .12s, transform .08s;
}
.primary-btn { background: linear-gradient(to bottom, #c1512f, #8f3620); color: #fdf0dc; border-color: #6b2814; }
.ghost-btn { background: rgba(240,226,189,0.10); color: #e6d6ad; border-color: rgba(217,164,65,0.38); }
.primary-btn:hover, .ghost-btn:hover { filter: brightness(1.12); }
.primary-btn:active, .ghost-btn:active { transform: scale(.97); }
.primary-btn:disabled, .ghost-btn:disabled { opacity: .42; cursor: not-allowed; }
.big { padding: 15px 28px; font-size: 17px; }
.small { padding: 7px 12px; font-size: 13px; }

/* ===== 游戏主界面 ===== */
.game { background: #17121c; overflow: hidden; }
#vn-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 顶部资源条 */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding: max(10px, env(safe-area-inset-top)) 14px 12px;
  background: linear-gradient(to bottom, rgba(23,18,28,.86), rgba(23,18,28,.30) 70%, transparent);
  color: var(--clay-lt); pointer-events: none;
  font-family: 'DM Sans', 'Noto Serif SC', sans-serif;
  padding-right: 210px;      /* 给右上角那排按钮让位，否则窄屏上会叠在一起 */
  max-height: 30vh; overflow: hidden;
}
.hud-title { font-size: 15px; margin-bottom: 3px; }
.hud-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 14.5px; font-weight: 600; }
.hud-chip { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.hud-chip i { font-style: normal; font-size: 11px; }
.hud-chip b { font-weight: 700; }
.hud-ch { color: var(--bronze); letter-spacing: .04em; }
.hud-crew b { color: #9fd8c8; }
.hud-supply b { color: #e8c46a; }
.hud-kleos b { color: #f0d8a0; }
.hud-hubris b { color: #e58a6a; }
.hud-endure b { color: var(--bronze); }
.hud-bar { width: 60px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.18); overflow: hidden; }
.hud-bar i { display: block; height: 100%; background: var(--terra); }

.topbar {
  position: absolute; top: max(8px, env(safe-area-inset-top)); right: 12px; z-index: 7;
  display: flex; gap: 7px;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 11px; font-size: 19px;
  background: rgba(36,31,51,.72); border: 1px solid rgba(217,164,65,.42); color: var(--clay-lt);
  transition: filter .12s, transform .08s;
}
.icon-btn:hover { filter: brightness(1.25); }
.icon-btn:active { transform: scale(.94); }

/* ===== 对话框 ===== */
.vn-box {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  margin: 0 auto; max-width: 1080px;
  max-height: 48vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 26px max(22px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(24,18,26,.97), rgba(30,22,32,.92));
  border-top: 3px solid var(--bronze);
  box-shadow: 0 -14px 46px rgba(0,0,0,.55);
  border-radius: 18px 18px 0 0;
  color: var(--clay-lt);
  animation: boxIn .18s ease-out;
}
@keyframes boxIn { from { transform: translateY(14px); opacity: .4 } to { transform: none; opacity: 1 } }
.vn-name {
  display: inline-block; margin: -34px 0 8px; padding: 6px 18px;
  background: linear-gradient(to bottom, var(--terra), var(--terra2));
  color: #fdf0dc; border-radius: 10px; font-weight: 700; font-size: 16px;
  border: 1px solid rgba(36,31,51,.6);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.vn-text { font-size: 17px; line-height: 2.0; min-height: 4.6em; letter-spacing: .01em; }
.vn-text b { color: var(--bronze); }
.vn-text i { color: #b9a68c; font-style: italic; }
.vn-next { text-align: right; color: var(--bronze); font-size: 15px; animation: blink 1.1s infinite; }
@keyframes blink { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

.vn-choices { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.vn-choice {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  text-align: left; width: 100%;
  background: rgba(240,226,189,.09); color: var(--clay-lt);
  border: 1px solid rgba(217,164,65,.42); border-left: 4px solid var(--terra);
  border-radius: 10px; padding: 12px 16px; font-size: 15.5px; line-height: 1.6;
  transition: background .12s, transform .08s;
}
.vn-choice:hover:not(:disabled) { background: rgba(217,164,65,.20); }
.vn-choice:active:not(:disabled) { transform: scale(.99); }
.vn-choice.endure { border-left-color: var(--bronze); }
.vn-choice.locked { opacity: .45; cursor: not-allowed; border-left-color: #6b6478; }
.vn-choice-label { flex: 1 1 auto; }
.vn-cost { font-size: 12.5px; color: var(--bronze); background: rgba(217,164,65,.16); border-radius: 6px; padding: 3px 8px; }
.vn-hint { font-size: 12.5px; color: #9a8f7e; }
.vn-lock { font-size: 12.5px; color: #c98a6a; }

/* ===== 资源变化演出 ===== */
.fx-layer {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.fx-item {
  font-size: 17px; font-weight: 700; padding: 11px 22px; border-radius: 12px;
  background: rgba(24,18,26,.94); border: 1px solid rgba(217,164,65,.5); color: var(--clay-lt);
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
  animation: fxIn .28s cubic-bezier(.2,1.4,.4,1);
}
.fx-item.good { border-color: rgba(120,200,140,.6); color: #b8e8c0; }
.fx-item.bad  { border-color: rgba(210,110,80,.6);  color: #f0b09a; }
.fx-item.big  { font-size: 19px; padding: 15px 28px; }
@keyframes fxIn { from { transform: scale(.7) translateY(10px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ===== 模态 ===== */
.modal-mask { position: fixed; inset: 0; background: rgba(10,8,14,.68); z-index: 50; }
.modal {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(560px, 92vw); max-height: 88vh; overflow: auto;
  background: linear-gradient(to bottom, #f5e2c4, #e8c9a0);
  color: var(--ink); border: 3px solid var(--ink); border-radius: 16px;
  padding: 22px 24px; box-shadow: 0 26px 70px rgba(0,0,0,.6);
}
.modal.wide { width: min(860px, 94vw); }
.modal h2 { font-size: 21px; margin-bottom: 12px; color: var(--terra2); letter-spacing: .04em; }
.modal-body { font-size: 15px; line-height: 1.95; }
.modal-body b { color: var(--terra2); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 18px; }
.modal .primary-btn { background: linear-gradient(to bottom, #c1512f, #8f3620); }
.modal .ghost-btn { background: rgba(36,31,51,.10); color: var(--ink); border-color: rgba(36,31,51,.35); }

.toast {
  position: fixed; left: 50%; bottom: 12%; transform: translateX(-50%) translateY(10px);
  background: rgba(24,18,26,.95); color: var(--clay-lt); border: 1px solid rgba(217,164,65,.5);
  padding: 11px 20px; border-radius: 11px; font-size: 14.5px; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 侧栏面板 ===== */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(460px, 94vw); overflow-y: auto;
  background: linear-gradient(to bottom, #f5e2c4, #e2c69c);
  border-left: 4px solid var(--ink); color: var(--ink);
  padding: max(16px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  box-shadow: -16px 0 48px rgba(0,0,0,.5);
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: .3 } to { transform: none; opacity: 1 } }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { font-size: 20px; color: var(--terra2); flex: 1; }
.panel h3 { font-size: 15px; margin: 16px 0 8px; color: var(--ink-2); border-bottom: 2px solid rgba(36,31,51,.2); padding-bottom: 5px; }
.panel .muted { color: #7a6f60; font-size: 13px; line-height: 1.8; }

/* 卡牌网格（面板内） */
.card-grid-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 9px; }

/* ===== 卡牌 ===== */
.card {
  position: relative; border-radius: 11px; padding: 9px 10px 10px;
  background: linear-gradient(to bottom, #fbf1dd, #ecd9b6);
  border: 2.5px solid var(--ink); color: var(--ink);
  box-shadow: 0 3px 0 rgba(36,31,51,.35);
  font-size: 12px; line-height: 1.55; text-align: left;
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.card::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  border-radius: 8px 8px 0 0; background: var(--cc, var(--terra));
}
.card.bie    { --cc: var(--c-bie); }
.card.metis  { --cc: var(--c-metis); }
.card.peitho { --cc: var(--c-peitho); }
.card.endure { --cc: var(--c-endure); }
.card.companion { --cc: var(--c-comp); }
.card.relic  { --cc: var(--c-relic); }
.card.wrath  { --cc: var(--c-wrath); background: linear-gradient(to bottom, #4a4458, #332e42); color: #cfc8dc; }
.card.wrath .card-name { color: #e8dcf0; }
.card-top { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.card-cost {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--ink); color: var(--clay-lt);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.card-name { font-weight: 700; font-size: 13px; flex: 1; }
.card-icon { font-size: 16px; }
.card-art { display: block; width: 100%; height: 56px; margin: 6px 0; border-radius: 6px; background: rgba(36,31,51,.06); }
.card-text { font-size: 11.5px; line-height: 1.6; }
.card-text b { color: var(--terra2); }
.card.wrath .card-text b { color: #f0b09a; }
.card-count { position: absolute; right: 7px; bottom: 6px; font-size: 11px; color: #8a7c68; font-weight: 700; }

/* ===== 战斗 ===== */
.battle { background: #17121c; overflow: hidden; }
#battle-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.battle-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(23,18,28,.86), transparent);
  color: var(--clay-lt); font-family: 'DM Sans','Noto Serif SC',sans-serif; font-size: 14px;
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.hand {
  position: absolute; left: 0; right: 0; bottom: 76px; z-index: 8;
  display: flex; gap: 8px; align-items: flex-end;
  /* safe center：牌少时居中，牌多到装不下时退回左对齐并横向滚动，
     不然在手机竖屏上最左边那张牌会滚不到 */
  justify-content: safe center;
  padding: 16px 12px 0; min-height: 168px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.hand::-webkit-scrollbar { display: none; }
.hand .card {
  width: 132px; flex: 0 0 auto; cursor: pointer;
  transform-origin: bottom center;
}
.hand .card:hover:not(.unplayable) { transform: translateY(-10px) scale(1.04); box-shadow: 0 10px 22px rgba(0,0,0,.5); z-index: 3; }
.hand .card.unaffordable { filter: grayscale(.6) brightness(.8); }
.hand .card.unplayable { cursor: not-allowed; }
.battle-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 9;
  display: flex; gap: 10px; align-items: center; justify-content: center;
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(23,18,28,.95), transparent);
}
.thumos { display: flex; gap: 5px; align-items: center; color: var(--clay-lt); font-weight: 700; }
.thumos-pip { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--bronze); }
.thumos-pip.on { background: var(--bronze); box-shadow: 0 0 9px rgba(217,164,65,.8); }
.pile-btn { color: #c9b894; font-size: 13px; background: none; border: none; }

/* ===== 谜题 ===== */
.puzzle {
  background: linear-gradient(160deg, #2a1f26, #16121c);
  display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}
.puz-head {
  display: flex; align-items: center; gap: 12px; color: var(--clay-lt);
  font-size: 17px; font-weight: 700; padding: 6px 4px 12px;
  border-bottom: 2px solid rgba(217,164,65,.35); margin-bottom: 12px;
}
.puz-body { flex: 1; overflow-y: auto; color: var(--clay-lt); }
.puz-foot { padding-top: 12px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.puz-intro { max-width: 780px; margin: 0 auto 16px; line-height: 1.95; font-size: 15px; color: #dcc6a4; }
.puz-intro b { color: var(--bronze); }

/* 通用谜题控件 */
.tile-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.tile {
  min-width: 54px; height: 62px; padding: 0 12px; border-radius: 10px;
  background: linear-gradient(to bottom, #f5e2c4, #e0c398); color: var(--ink);
  border: 2.5px solid var(--ink); font-size: 22px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 3px 0 rgba(36,31,51,.4);
  transition: transform .1s, filter .1s;
}
.tile:hover { filter: brightness(1.08); }
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(36,31,51,.4); }
.tile.on { background: linear-gradient(to bottom, #d9a441, #b8843a); }
.tile.slot { background: rgba(240,226,189,.10); color: var(--clay-lt); border-style: dashed; }
.tile.ok { background: linear-gradient(to bottom, #7cc24a, #4d8c4a); color: #fff; }
.tile.no { background: linear-gradient(to bottom, #d06a4a, #a33f22); color: #fff; }
.tile.sm { min-width: 42px; height: 46px; font-size: 16px; }

.puz-card {
  max-width: 820px; margin: 0 auto; background: rgba(240,226,189,.07);
  border: 1px solid rgba(217,164,65,.30); border-radius: 14px; padding: 18px 20px;
}
.puz-list { display: flex; flex-direction: column; gap: 9px; }
.puz-opt {
  text-align: left; background: rgba(240,226,189,.09); color: var(--clay-lt);
  border: 1px solid rgba(217,164,65,.38); border-left: 4px solid var(--terra);
  border-radius: 10px; padding: 12px 16px; font-size: 15px; line-height: 1.65;
}
.puz-opt:hover { background: rgba(217,164,65,.18); }
.puz-opt.on { background: rgba(217,164,65,.28); border-left-color: var(--bronze); }
.puz-note { text-align: center; color: #b9a68c; font-size: 13.5px; margin-top: 10px; line-height: 1.8; }

/* ===== 通用小件 ===== */
.stat-line { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 14px; border-bottom: 1px dashed rgba(36,31,51,.18); }
.stat-line b { color: var(--terra2); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: rgba(36,31,51,.10); }
.tag.dead { background: rgba(36,31,51,.7); color: #d8cfe0; }
.tag.alive { background: rgba(77,140,74,.22); color: #2f6d3f; }

/* 矮屏：对话框不能吃掉整个画面，否则立绘完全看不见 */
@media (max-height: 780px) {
  .vn-text { font-size: 15.5px; line-height: 1.85; min-height: 3.6em; }
  .vn-box { max-height: 42vh; padding: 16px 22px max(16px, env(safe-area-inset-bottom)); }
  .vn-name { margin-top: -30px; font-size: 15px; padding: 5px 15px; }
  .vn-choice { padding: 10px 14px; font-size: 14.5px; }
  .hud-title { font-size: 13.5px; }
  .hud-row.small { font-size: 12.5px; }
}

/* 窄屏：顶栏按钮更小，HUD 的让位也要跟着收，否则资源条会挤成四行 */
@media (max-width: 640px) {
  .hud { padding-right: 168px; }
  .hud-row { gap: 8px; }
  .hud-row.small { font-size: 11.5px; }
  .hud-bar { width: 42px; }
}

/* 窄屏 */
@media (max-width: 640px) {
  .start-card h1 { font-size: 42px; }
  .vn-text { font-size: 15.5px; line-height: 1.95; min-height: 7em; }
  .vn-box { padding: 18px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 14px 14px 0 0; }
  .hud-row { font-size: 12.5px; gap: 9px; }
  .icon-btn { width: 37px; height: 37px; font-size: 17px; }
  .hand .card { width: 112px; }
  .hand { min-height: 150px; bottom: 70px; padding-top: 10px; }
  .hand .card .card-text { font-size: 11px; line-height: 1.5; }
  .hand .card .card-name { font-size: 12px; }
  .hand .card:hover:not(.unplayable) { transform: none; }   /* 触屏没有 hover，抬起来反而挡住下一张 */
  .battle-top { font-size: 12.5px; gap: 8px; }
  .bstat { font-size: 12px; padding: 2px 7px; }
}

/* 战斗顶栏细节 */
.battle-top b { font-size: 16px; color: var(--clay-lt); }
.bstat { font-size: 13.5px; color: #cdbb9c; background: rgba(36,31,51,.55); border-radius: 7px; padding: 3px 9px; }
.ib {
  font-size: 13.5px; font-weight: 700; color: #f0d8a0;
  background: rgba(193,81,47,.42); border: 1px solid rgba(217,164,65,.55);
  border-radius: 7px; padding: 3px 10px;
}
.ib.open { background: rgba(217,164,65,.42); color: #fff2cc; animation: blink 1s infinite; }
.bmsg {
  flex-basis: 100%; margin-top: 6px; font-size: 13.5px; color: #e8d4b0;
  background: rgba(36,31,51,.62); border-left: 3px solid var(--bronze);
  border-radius: 0 8px 8px 0; padding: 7px 12px; line-height: 1.7;
}
.bmsg b { color: var(--bronze); }

/* 结算 / 图鉴里的紧凑卡组 */
.deck-line { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed rgba(36,31,51,.16); font-size: 13.5px; }
.deck-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.deck-line .grow { flex: 1; }
.pill-row { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0; }
