/* Capsule Garden — cozy capsule-toy aesthetic. Mobile-first portrait. */

:root {
  /* Material palette */
  --leaf:    #5fa463;
  --dew:     #4bb6b0;
  --pollen:  #e8c14a;
  --root:    #c8794a;
  --petal:   #e487b0;
  --crystal: #6aa3e0;

  /* Surface palette */
  --bg-top:    #eaf6ee;
  --bg-bottom: #f7ecf3;
  --card:      #ffffff;
  --card-soft: #f4f8f3;
  --ink:       #2a3a30;
  --ink-soft:  #6a7d70;
  --line:      #e2ece4;
  --accent:    #3f9d6b;
  --accent-deep:#2c7a52;
  --warn:      #c8794a;

  --radius:    20px;
  --radius-sm: 14px;
  --shadow:    0 6px 18px rgba(63, 100, 78, 0.12);
  --shadow-sm: 0 2px 8px rgba(63, 100, 78, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% 0%, var(--bg-top) 0%, var(--bg-bottom) 100%) fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 14px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  padding: 18px 4px 10px;
  text-align: center;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--accent-deep);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: 0.2px;
}
.wordmark-emoji { font-size: 1.5rem; }
.wordmark:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; border-radius: 10px; }
.tagline {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

/* ---------- Language switch ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.lang-switch {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
}
.lang-switch select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--card);
  color: var(--accent-deep);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.lang-switch select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- HUD ---------- */
.hud {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
.hud-level { display: flex; flex-direction: column; min-width: 0; }
.hud-chapter { font-weight: 700; font-size: 0.95rem; color: var(--accent-deep); }
.hud-name { color: var(--ink-soft); font-size: 0.82rem; margin-top: 2px; }
.hud-goal { text-align: right; flex-shrink: 0; }
.hud-goal-label { display: block; font-size: 0.7rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; }
.hud-goal-value { font-weight: 800; font-size: 1.05rem; }
.hud-bar {
  margin-top: 10px;
  height: 9px;
  border-radius: 999px;
  background: var(--card-soft);
  overflow: hidden;
}
.hud-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--leaf), var(--accent));
  transition: width 0.4s ease;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 5px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, color 0.2s ease;
}
.tab.is-active {
  background: linear-gradient(135deg, var(--leaf), var(--accent));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.tab:focus-visible { outline: 3px solid var(--accent-deep); outline-offset: 2px; }

/* ---------- Panels ---------- */
.panel { animation: fade 0.25s ease; }
.panel[hidden] { display: none; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 2px 10px;
}
.section-head h2, .sub-head { font-size: 1.05rem; margin: 0; }
.sub-head { margin: 20px 2px 10px; }
h3.sub-head { font-size: 0.98rem; }
.hint { margin: 0 2px 12px; color: var(--ink-soft); font-size: 0.82rem; }

.link-btn {
  border: none;
  background: var(--card);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 9px 13px;
  min-height: 40px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}
.link-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.demo-tag {
  font-size: 0.62rem;
  background: var(--card-soft);
  color: var(--ink-soft);
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 3px;
  font-weight: 700;
  text-transform: uppercase;
}

/* ---------- Pots ---------- */
.pots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pot {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 8px 10px;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  border: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.2s ease;
  width: 100%;
}
.pot:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.pot:active { transform: scale(0.97); }
.pot.is-empty { border-style: dashed; border-color: var(--line); background: var(--card-soft); }
.pot.is-mature { border-color: var(--pollen); box-shadow: 0 0 0 3px rgba(232,193,74,0.25), var(--shadow-sm); }

.pot-art { position: relative; width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; }
.pot-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.pot-ring-bg { fill: none; stroke: var(--card-soft); stroke-width: 5; }
.pot-ring-fg { fill: none; stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset 0.5s linear; }
.pot-emoji { font-size: 2rem; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.08)); }
.pot.is-empty .pot-emoji { font-size: 1.7rem; opacity: 0.5; }
.pot-empty-plus { font-size: 1.8rem; color: var(--ink-soft); }

.pot-status { font-size: 0.72rem; font-weight: 700; color: var(--ink-soft); margin-top: 4px; min-height: 1.6em; }
.pot-status.ready { color: var(--accent-deep); }
.pot-name { font-size: 0.66rem; color: var(--ink-soft); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.pot-quick {
  margin-top: 6px;
  border: none;
  background: var(--card-soft);
  color: var(--warn);
  font-weight: 700;
  font-size: 0.68rem;
  border-radius: 999px;
  padding: 6px 8px;
  min-height: 32px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.1;
}
.pot-quick:focus-visible { outline: 2px solid var(--warn); outline-offset: 1px; }

.pot-harvest {
  margin-top: 6px;
  border: none;
  background: linear-gradient(135deg, var(--pollen), #d9a93c);
  color: #4a3a10;
  font-weight: 800;
  font-size: 0.74rem;
  border-radius: 999px;
  padding: 7px 12px;
  min-height: 34px;
  cursor: pointer;
  font-family: inherit;
}
.pot-harvest:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 1px; }

/* ---------- Inventory ---------- */
.inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.inv-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--chip, var(--line));
}
.inv-chip .inv-emoji { font-size: 1rem; }
.inv-chip .inv-qty { color: var(--ink-soft); }
.inv-empty { color: var(--ink-soft); font-size: 0.82rem; font-style: italic; }
.inv-group-label { width: 100%; font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }

/* ---------- Craft / recipes ---------- */
.recipes { display: grid; grid-template-columns: 1fr; gap: 10px; }
.recipe {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.recipe.is-locked { opacity: 0.66; }
.recipe-emoji { font-size: 1.8rem; flex-shrink: 0; width: 40px; text-align: center; }
.recipe-main { flex: 1; min-width: 0; }
.recipe-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 6px; }
.recipe-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.recipe-chip {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--card-soft);
  color: var(--ink-soft);
  border-left: 3px solid var(--chip, var(--line));
}
.recipe-chip.ok { color: var(--accent-deep); }
.recipe-chip.short { color: var(--warn); }
.recipe-tag {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--card-soft);
  color: var(--ink-soft);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.recipe-tag.done { color: var(--accent-deep); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 800;
  font-size: 0.86rem;
  cursor: pointer;
  font-family: inherit;
  background: linear-gradient(135deg, var(--leaf), var(--accent));
  color: #fff;
  flex-shrink: 0;
  white-space: nowrap;
}
.btn:disabled { background: var(--card-soft); color: var(--ink-soft); cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--accent-deep); outline-offset: 2px; }
.btn.ghost { background: var(--card-soft); color: var(--accent-deep); }

/* ---------- Tray ---------- */
.tray { display: flex; flex-wrap: wrap; gap: 8px; min-height: 56px; }
.tray-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  font-family: inherit;
  color: inherit;
  min-height: 44px;
}
.tray-item .tray-emoji { font-size: 1.3rem; }
.tray-item.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63,157,107,0.2); }
.tray-item:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tray-empty { color: var(--ink-soft); font-size: 0.82rem; font-style: italic; align-self: center; }

/* ---------- Decoration grid ---------- */
.deco-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: linear-gradient(135deg, #e9f4ec, #f3ecf2);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: inset 0 1px 4px rgba(63,100,78,0.08);
}
.deco-cell {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.55);
  border: 2px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.deco-cell.filled { border-style: solid; border-color: transparent; background: #fff; box-shadow: var(--shadow-sm); }
.deco-cell.placeable { border-color: var(--accent); background: rgba(63,157,107,0.12); }
.deco-cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.deco-cell .cell-empty-dot { font-size: 1rem; color: var(--line); }

/* ---------- Collection book ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.book-cell {
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 10px 4px 8px;
  text-align: center;
}
.book-cell.locked { background: var(--card-soft); }
.book-emoji { font-size: 1.7rem; line-height: 1.2; }
.book-cell.locked .book-emoji { filter: grayscale(1) brightness(1.4); opacity: 0.45; }
.book-label { font-size: 0.62rem; color: var(--ink-soft); margin-top: 3px; line-height: 1.1; }
.book-state { font-size: 0.58rem; margin-top: 2px; font-weight: 700; }
.book-cell.found .book-state { color: var(--accent-deep); }
.book-cell.locked .book-state { color: var(--ink-soft); }
.collection-count { font-size: 0.82rem; font-weight: 700; color: var(--accent-deep); }

/* ---------- Footer ---------- */
.app-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.save-note { font-size: 0.74rem; color: var(--ink-soft); }
.restart-btn {
  border: none;
  background: transparent;
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 10px;
  min-height: 40px;
  border-radius: 999px;
  font-family: inherit;
}
.restart-btn:hover { text-decoration: underline; }
.restart-btn:focus-visible { outline: 2px solid var(--warn); outline-offset: 2px; }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(40, 58, 48, 0.4);
  z-index: 40;
  animation: fade 0.2s ease;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  margin: 0 auto;
  max-width: 480px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 28px rgba(40,58,48,0.22);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 78vh;
  overflow-y: auto;
  animation: slideUp 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet[hidden] { display: none; }
.sheet-handle { width: 44px; height: 5px; border-radius: 999px; background: var(--line); margin: 6px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0 8px; }
.sheet-title { font-size: 1.1rem; margin: 0; }
.sheet-close {
  border: none; background: var(--card-soft); color: var(--ink-soft);
  width: 36px; height: 36px; border-radius: 999px; font-size: 1rem; cursor: pointer; font-family: inherit;
}
.sheet-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet-body { display: flex; flex-direction: column; gap: 9px; }

.seed-option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-soft);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
  min-height: 56px;
}
.seed-option:disabled { opacity: 0.5; cursor: not-allowed; }
.seed-option:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.seed-option .seed-emoji { font-size: 1.8rem; flex-shrink: 0; }
.seed-info { flex: 1; min-width: 0; }
.seed-name { font-weight: 700; font-size: 0.92rem; }
.seed-meta { font-size: 0.74rem; color: var(--ink-soft); margin-top: 2px; }
.seed-count { font-size: 0.8rem; font-weight: 800; color: var(--accent-deep); flex-shrink: 0; }
.sheet-empty { color: var(--ink-soft); font-size: 0.86rem; text-align: center; padding: 16px 0; }
.menu-btn {
  width: 100%;
  text-align: center;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  min-height: 52px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  font-family: inherit;
  background: var(--card-soft);
  color: var(--accent-deep);
}
.menu-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.menu-btn.danger { color: var(--warn); }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  left: 0; right: 0; bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: rgba(42, 58, 48, 0.96);
  color: #fff;
  border-radius: 14px;
  padding: 11px 16px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  max-width: 460px;
  text-align: center;
  animation: toastIn 0.3s ease;
}
.toast.celebrate { background: linear-gradient(135deg, var(--accent-deep), var(--accent)); }
.toast .toast-em { margin-right: 4px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  *, .panel, .sheet, .toast, .sheet-backdrop { animation: none !important; transition: none !important; }
  .pot:active { transform: none; }
}
