@font-face {
  font-family: 'Ark';
  src: url('assets/ark-pixel-10px-zh_hant.woff2') format('woff2');
  font-display: block;
}

:root {
  --ink: #2a1a14;
  --paper: #f7e6c8;
  --wood: #c9a06a;
  --wood2: #8f5d3a;
  --dark: #2f241c;
  --cream: #f7e6c8;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #1b1720;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(circle at 50% 30%, #2b2438 0%, #15121a 70%);
}

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 240px;
  height: 520px;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(1);
  background: #7fc3e3;
  box-shadow: 0 0 0 2px #0d0a10, 0 12px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  font-family: 'Ark', 'PingFang TC', 'Microsoft JhengHei', monospace;
  font-size: 10px;
  color: var(--ink);
}

#cv {
  display: block;
  width: 240px;
  height: 520px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  pointer-events: none;
}
.pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(30, 22, 18, 0.62);
  border: 1px solid rgba(247, 230, 200, 0.25);
  color: var(--cream);
  padding: 2px 6px;
  font-size: 10px;
  line-height: 1;
  height: 22px;
}
.pill b { font-weight: normal; font-size: 11px; }
.pill i { font-style: normal; opacity: 0.5; }
.ico { image-rendering: pixelated; display: block; }

/* ---------- 牧場子頁籤 ---------- */
#subtabs {
  position: absolute;
  left: 50%;
  top: 46px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
}
#subtabs button {
  font-family: inherit;
  font-size: 10px;
  color: var(--cream);
  background: rgba(30, 22, 18, 0.6);
  border: 1px solid rgba(247, 230, 200, 0.28);
  padding: 3px 12px;
  cursor: pointer;
}
#subtabs button.on {
  background: var(--wood);
  color: var(--ink);
  border-color: var(--ink);
}

/* ---------- 工具列 ---------- */
#bar {
  position: absolute;
  left: 0;
  bottom: 58px;
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 6px;
}
.tool {
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 46px;
  height: 40px;
  padding: 1px 0;
  background: rgba(30, 22, 18, 0.72);
  border: 1px solid rgba(247, 230, 200, 0.2);
  border-radius: 0;
  color: var(--cream);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
}
.tool canvas { image-rendering: pixelated; pointer-events: none; }
.tool.on {
  background: var(--wood);
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.tool:active { transform: translateY(1px); }
.tool.wide { width: auto; padding: 0 10px; flex-direction: row; font-size: 10px; height: 40px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(30, 22, 18, 0.72);
  border: 1px solid rgba(247, 230, 200, 0.2);
  color: var(--cream);
  height: 40px;
  padding: 0 8px;
  font-size: 9px;
  line-height: 1.3;
  flex: 0 0 auto;
  white-space: nowrap;
  cursor: pointer;
}
.chip b { font-weight: normal; font-size: 9px; opacity: 0.85; white-space: nowrap; }
.chip i { font-style: normal; font-size: 11px; white-space: nowrap; }
.chip.wide { flex-direction: row; gap: 5px; height: 40px; font-size: 10px; }

/* ---------- 底部導覽 ---------- */
#nav {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 56px;
  display: flex;
  background: var(--dark);
  border-top: 2px solid #14100c;
}
#nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  border-right: 1px solid rgba(247, 230, 200, 0.08);
  color: rgba(247, 230, 200, 0.6);
  font-family: inherit;
  font-size: 9px;
  cursor: pointer;
  padding: 0;
}
#nav button:last-child { border-right: 0; }
#nav button canvas { image-rendering: pixelated; pointer-events: none; opacity: 0.75; }
#nav button.on { color: var(--cream); background: rgba(201, 160, 106, 0.16); }
#nav button.on canvas { opacity: 1; }
#nav button.on::after {
  content: '';
  position: absolute;
  bottom: 52px;
  width: 26px;
  height: 2px;
  background: var(--wood);
}

/* ---------- 提示 ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 112px;
  transform: translateX(-50%) translateY(6px);
  background: rgba(24, 17, 13, 0.92);
  color: var(--cream);
  border: 1px solid rgba(247, 230, 200, 0.3);
  padding: 4px 10px;
  font-size: 10px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.16s, transform 0.16s;
  pointer-events: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 對話框 ---------- */
#sheet {
  position: absolute;
  inset: 0;
  background: rgba(16, 11, 8, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#sheet.hidden { display: none; }
.card {
  width: 212px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
  padding: 9px 10px 10px;
  color: var(--ink);
}
.card h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: normal;
  padding-bottom: 5px;
  border-bottom: 1px dashed rgba(42, 26, 20, 0.35);
}
.row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  padding: 3px 0;
  line-height: 1.4;
}
.row .k { color: rgba(42, 26, 20, 0.65); flex: none; }
.row .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.note {
  margin: 7px 0 2px;
  font-size: 9px;
  line-height: 1.5;
  color: rgba(42, 26, 20, 0.7);
  background: rgba(42, 26, 20, 0.06);
  padding: 5px 6px;
}
#sheetBtns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
#sheetBtns button {
  flex: 1 1 46%;
  font-family: inherit;
  font-size: 10px;
  min-height: 24px;
  padding: 4px 6px;
  color: var(--ink);
  background: var(--wood);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  cursor: pointer;
}
#sheetBtns button:active { transform: translate(1px, 1px); }
#sheetBtns button.danger { background: #c9564a; color: #fff8ec; }
