:root {
  --grass: #a8d08d;
  --cream: #fff8ec;
  --cream-2: #f7ecd8;
  --soil: #c9a36b;
  --ink: #4e3d2c;
  --muted: #93826d;
  --sky: #bfe3f2;
  --accent: #ff8a65;
  --accent-deep: #f4511e;
  --good: #66bb6a;
  --warn: #ffb74d;
  --bad: #ef5350;
  --radius: 14px;
  --shadow: 0 4px 14px rgba(93, 64, 28, 0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(#cde9f6, #dff0cf 40%, #cfe8b9);
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; }

button { font: inherit; cursor: pointer; color: inherit; }
/* 觸控：消除 300ms 延遲與雙擊縮放；快速連點不選字 */
button, .plot, .tab-btn, .tool-btn {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* 粒子特效層 */
#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 260;
  overflow: hidden;
}
.fx-p {
  position: fixed;
  transform: translate(-50%, -50%);
  animation: fx-pop 0.9s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes fx-pop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2); opacity: 0; }
}

.btn {
  border: 2px solid rgba(120, 84, 44, 0.18);
  background: var(--cream);
  border-radius: 999px;
  padding: 8px 18px;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); background: #fffdf6; }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #fff;
  border-color: rgba(180, 60, 20, 0.35);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #ff9d7e, var(--accent-deep)); }
.btn-danger { background: #fde8e6; border-color: rgba(200, 60, 50, 0.3); color: #b3372e; }
.btn-small { padding: 4px 12px; font-size: 0.85rem; box-shadow: none; }

/* ---------- 開始畫面 ---------- */
#start-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.start-card {
  background: var(--cream);
  border-radius: 28px;
  box-shadow: 0 12px 40px rgba(93, 64, 28, 0.22);
  padding: 40px 48px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.start-logo { font-size: 2.6rem; letter-spacing: 6px; }
.start-card h1 { margin: 12px 0 2px; font-size: 2.1rem; }
.start-card .subtitle { margin: 0 0 22px; color: var(--muted); letter-spacing: 2px; }
.start-buttons { display: flex; flex-direction: column; gap: 10px; }
.save-hint { margin-top: 16px; color: var(--muted); font-size: 0.85rem; min-height: 1.2em; }

/* ---------- 主畫面骨架 ---------- */
#app { display: flex; flex-direction: column; height: 100vh; }
#layout {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 12px 14px;
  min-height: 0;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(255, 248, 236, 0.85);
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(93, 64, 28, 0.12);
  flex-wrap: wrap;
}
.hud-title { font-weight: 700; }
.hud-left { margin-right: auto; }
.hud-center { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hud-right { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.hud-chip {
  background: var(--cream-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 600;
  white-space: nowrap;
}
#xp-bar {
  position: relative;
  width: 150px;
  height: 16px;
  background: #e8dcc4;
  border-radius: 999px;
  overflow: hidden;
}
#xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #9ccc65, #66bb6a);
  border-radius: 999px;
  transition: width 0.3s;
}
#xp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #3c4a2e;
}

/* ---------- 工具列 ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 248, 236, 0.9);
  box-shadow: 0 -2px 8px rgba(93, 64, 28, 0.1);
  flex-wrap: wrap;
}
.tool-group { display: flex; gap: 6px; flex-wrap: wrap; }
.tool-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 2px solid transparent;
  background: var(--cream-2);
  border-radius: 12px;
  padding: 7px 10px;
  font-size: 1.05rem;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
}
.tool-btn:hover { transform: translateY(-2px); background: #fff3dc; }
.tool-btn.selected {
  border-color: var(--accent);
  background: #ffe9df;
  box-shadow: 0 0 0 3px rgba(255, 138, 101, 0.25);
}
.tool-name { font-size: 0.82rem; font-weight: 600; }
.tool-count {
  font-size: 0.72rem;
  font-weight: 700;
  background: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  border: 1px solid rgba(120, 84, 44, 0.2);
}
.tool-status { font-size: 0.85rem; color: var(--muted); margin-left: auto; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--cream);
  border-left: 5px solid var(--sky);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 9px 18px;
  font-size: 0.92rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: min(90vw, 480px);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--good); }
.toast-warn { border-left-color: var(--warn); }
.toast-info { border-left-color: var(--sky); }

/* ---------- Modal ---------- */
#modal-root {
  position: fixed;
  inset: 0;
  background: rgba(64, 48, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal-card {
  background: var(--cream);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(40, 28, 10, 0.35);
  padding: 22px 26px;
  max-width: 460px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card h3 { margin: 0 0 12px; }
.modal-body { line-height: 1.7; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.help-body p { margin: 8px 0; line-height: 1.65; font-size: 0.92rem; }
.settings-body { display: flex; flex-direction: column; gap: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

/* ---------- 新手教學 ---------- */
#tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
}
.tut-ring {
  position: fixed;
  border: 3px dashed var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 0 6px rgba(255, 138, 101, 0.2);
  transition: all 0.3s ease;
  animation: tut-blink 1.4s infinite;
}
@keyframes tut-blink {
  0%, 100% { box-shadow: 0 0 0 6px rgba(255, 138, 101, 0.15); }
  50% { box-shadow: 0 0 0 10px rgba(255, 138, 101, 0.35); }
}
.tut-card {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--cream);
  border: 2px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(40, 28, 10, 0.3);
  padding: 14px 20px;
  max-width: min(92vw, 420px);
  pointer-events: auto;
  text-align: center;
}
.tut-step { font-size: 0.75rem; font-weight: 700; color: var(--accent-deep); margin-bottom: 4px; }
.tut-card p { margin: 0 0 10px; line-height: 1.55; }
