/* ============================================
   a cup of coffee —— 小虎鲸 hana 的实验室
   深褐背景 + 浅色路径，突出可走区域
   ============================================ */

* { box-sizing: border-box; }

:root {
  --cell-size: 64px;
  --bg: #2e2117;          /* 深褐背景 */
  --wall: #19110b;        /* 墙（近黑褐） */
  --floor: #f2e8d7;       /* 地板浅米色路径 */
  --text: #f5ede1;
  --text-dim: #b9a48a;
  --accent: #d9a05b;
}

body {
  margin: 0;
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* 触屏优化：防止双击缩放 / 长按误选 */
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app { min-height: 100vh; }

/* ---- 屏幕切换 ---- */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  text-align: center;
}
.screen.active { display: flex; }

/* ---- 通用按钮 ---- */
button {
  font-family: inherit;
  font-size: 16px;
  padding: 10px 24px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: #6b4f3a;   /* 默认兜底（编辑器等未带类的按钮） */
  color: #fff;
  transition: filter 0.15s, transform 0.1s;
}
button:hover { filter: brightness(1.12); }
button:active { transform: scale(0.97); }

.primary-btn {
  background: var(--accent);
  color: #2a1c10;
  font-weight: 700;
}
.ghost-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ---- 标题界面 ---- */
#screen-title { gap: 8px; }

.title-hana {
  width: 150px;
  height: auto;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5));
  animation: bob 2s ease-in-out infinite;
}

.game-title {
  font-size: 44px;
  margin: 16px 0 4px;
  letter-spacing: 2px;
}

.tagline {
  color: var(--text-dim);
  margin: 0 0 24px;
}

.editor-link {
  margin-top: 14px;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
}
.editor-link:hover { color: var(--text); }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ---- 关卡选择界面 ---- */
.screen-heading {
  font-size: 28px;
  margin: 0 0 24px;
}

.level-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 580px;
  margin-bottom: 24px;
}

.level-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
}
.level-card:hover { background: rgba(255, 255, 255, 0.12); }

.level-num {
  font-size: 12px;
  color: var(--accent);
  background: rgba(217, 160, 91, 0.15);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
}
.level-name { font-size: 15px; }

/* 分享关卡卡片的小徽标 */
.shared-badge {
  font-size: 11px;
  color: var(--accent);
  background: rgba(217, 160, 91, 0.18);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ---- 关卡过渡界面 ---- */
.intro-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 36px 48px;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.intro-index {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0;
}
#intro-name { font-size: 30px; margin: 0; }

.intro-hint {
  color: var(--text-dim);
  font-style: italic;
  margin: 0 0 8px;
  min-height: 1.4em;
}

.intro-tip {
  color: var(--text-dim);
  font-size: 12px;
  margin: 0;
}

/* ---- 游戏界面（极简：基本只显示格子） ---- */
#screen-game {
  gap: 14px;
  justify-content: flex-start;
  padding-top: 36px;
}

.hud {
  font-size: 16px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 8px 20px;
  margin-bottom: 20px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* HUD 手持物品图标：必须用 .hud 提升特异性，
   否则会被后定义的 .item-icon{width:100%} 覆盖（特异性相同，靠后胜出） */
.hud .hand-icon {
  display: inline-flex;
  width: 26px;
  height: 26px;
  vertical-align: middle;
}
.hud .hand-icon img { width: 100%; height: 100%; object-fit: contain; }

/* 重置多次后 hana 在底部冒出的台词 */
.hana-tip {
  font-style: italic;
  color: var(--accent);
  font-size: 15px;
  min-height: 1.4em;
  margin: 0;
  max-width: 480px;
}

/* 包裹棋盘，用于右上角 UI 相对定位 */
#game-wrap {
  position: relative;
  display: inline-block;
}
/* 右上角 UI：右边缘对齐棋盘右边缘，与手持 HUD 同高度 */
#top-right-ui {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.control-tip {
  color: var(--text-dim);
  font-size: 13px;
}

/* 棋盘：深褐背景上浮出浅色路径块 */
#board {
  display: grid;
  gap: 5px;
  justify-content: center;
  width: fit-content;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-radius: 8px;
}

.cell.floor {
  background: var(--floor);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}

.cell.wall {
  background: var(--wall);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

/* 压力板：浅色地板 + 底部中央的圆形按钮 */
.cell.plate {
  background: var(--floor);
  box-shadow: inset 0 0 0 3px rgba(217, 160, 91, 0.55);
}
.cell.plate .plate-dot {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}

/* 机关门：默认关闭（像墙），被压力板触发后打开（像地板） */
.cell.door {
  background: var(--wall);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}
.cell.door.open {
  background: var(--floor);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}
.cell.door .door-icon {
  font-size: 24px;
}

/* 检查门：需要手持指定物品才能通过 */
.cell.gate {
  background: #4a3a2a;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}
.cell.gate .gate-require {
  width: 60%;
  height: 60%;
}
.cell.gate .gate-lock {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 13px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
}
/* 手持匹配物品时：门变浅色（接近地板）、标注变透明 */
.cell.gate.ok {
  background: var(--floor);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}
.cell.gate.ok .gate-require,
.cell.gate.ok .gate-lock {
  opacity: 0.35;
}

/* 物品与玩家 */
.item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  user-select: none;
  z-index: 1;
}

.item-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.item-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 地面上的普通物品缩到约 2/3（手持 / HUD 不受影响） */
.item .item-icon { width: 66%; height: 66%; }

/* 地面上的 tag 物品：放大到 0.8 并斜放 20° */
.item .tag-icon { width: 80%; height: 80%; transform: rotate(20deg); }

.player {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4));
  animation: bob 1.2s ease-in-out infinite;
  user-select: none;
  pointer-events: none;
}
.player img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 素材朝右，向左移动时翻转 */
.player.facing-left img { transform: scaleX(-1); }

/* 手持物品时右上角的小图标 */
.held-item {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.held-item .item-icon { font-size: 9px; }

/* ---- 过关浮层 ---- */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 10;
}

#win-overlay p {
  font-size: 24px;
  margin: 0;
}

/* ---- 分享弹窗 ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
.modal-card {
  background: #3a2b1e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 20px; }
.modal-sub { margin: 0; color: var(--text-dim); font-size: 13px; }

#share-input {
  width: 100%;
  min-height: 84px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  resize: vertical;
  box-sizing: border-box;
}
#share-input:focus { outline: none; border-color: var(--accent); }

.share-error { margin: 0; color: #ff9c9c; font-size: 13px; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- 触屏虚拟按键 ---- */
.touch-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  margin-top: auto;
  padding: 0 6px 6px;
  gap: 16px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 6px;
}
.t-up   { grid-area: up; }
.t-left { grid-area: left; }
.t-down { grid-area: down; }
.t-right{ grid-area: right; }

.actions {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px;
}

.tbtn {
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tbtn:active {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(0.96);
}
.actions .tbtn {
  width: 74px;
  height: 46px;
  font-size: 14px;
  font-weight: 600;
}

.hidden { display: none !important; }
