:root {
  --paddy: #1f4d36;
  --leaf: #2f7d4f;
  --leaf-soft: #e3efe4;
  --clay: #b85a26;
  --clay-soft: #f6e6d8;
  --paper: #f5f2e8;
  --card: #fffdf7;
  --ink: #1c2a21;
  --muted: #6b766c;
  --line: #e0dccc;
  --danger: #b3362b;
  --radius: 14px;
  --font: system-ui, -apple-system, "PingFang SC", "Noto Sans SC", "Noto Sans Thai", "Sarabun", "Thonburi", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.6 var(--font); }
a { color: var(--leaf); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); font-size: .85rem; }

/* shell */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: var(--paddy); color: #fff; }
.top h1 { flex: 1; font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { font-size: 1.3rem; }
.icon-btn { color: #fff; font-size: 1.3rem; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.12); }
.lang-btn { border: 1px solid rgba(255,255,255,.45); background: transparent; color: #fff; border-radius: 999px; padding: 4px 14px; font-size: .9rem; min-height: 34px; }
.lang-btn.dark { color: var(--paddy); border-color: var(--paddy); margin-top: 28px; }
main { max-width: 720px; margin: 0 auto; padding: 16px 14px calc(env(safe-area-inset-bottom) + 96px); }
section { margin-bottom: 26px; }
section > h2 { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 650; margin-bottom: 10px; }

.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom a { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 8px 2px 9px; color: var(--muted); font-size: .72rem; line-height: 1.3; text-align: center; }
.bottom a b { font-size: 1.25rem; font-weight: 500; line-height: 1.2; }
.bottom a.on { color: var(--paddy); font-weight: 650; }
.bottom a:nth-child(2) b { color: var(--leaf); }
.bottom a:nth-child(3) b { color: var(--clay); }

/* crops */
.crop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.crop { display: flex; flex-direction: column; gap: 1px; padding: 12px 10px 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink); text-align: left; min-height: 118px; }
.crop:active { transform: scale(.98); }
.crop-emoji { font-size: 1.6rem; line-height: 1.2; }
.crop strong { font-size: .98rem; line-height: 1.35; }
.crop small { color: var(--muted); font-size: .76rem; line-height: 1.35; }
.crop-counts { margin-top: auto; padding-top: 6px; display: flex; align-items: center; gap: 4px; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.trial { background: var(--leaf); }
.dot.shop { background: var(--clay); margin-left: 8px; }
.crop.add { border-style: dashed; background: transparent; color: var(--muted); align-items: center; justify-content: center; text-align: center; }

/* cards */
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; color: var(--ink); }
.rec { display: flex; gap: 12px; padding: 10px; }
.thumb { width: 76px; height: 76px; flex: none; border-radius: 10px; object-fit: cover; background: var(--leaf-soft); }
.thumb.ph { display: grid; place-items: center; font-size: 1.8rem; }
.rec-body { min-width: 0; flex: 1; }
.rec-body h3 { font-size: 1rem; line-height: 1.4; margin: 2px 0; overflow-wrap: anywhere; }
.rec-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.count { margin-left: auto; }
.badge { font-size: .7rem; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--leaf-soft); color: var(--paddy); white-space: nowrap; }
.badge.shop { background: var(--clay-soft); color: var(--clay); }
.badge.claude { background: #f3e3d6; color: #9a4a1c; }
.badge.grok { background: #e4e6ea; color: #23272e; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.chips span { font-size: .74rem; padding: 0 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { height: 60px; }

/* tabs, search */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: #e9e5d6; border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs a { text-align: center; padding: 8px 4px; border-radius: 9px; color: var(--muted); font-size: .92rem; }
.tabs a.on { background: var(--card); color: var(--paddy); font-weight: 650; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.search { width: 100%; margin-bottom: 12px; }

/* forms */
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 46px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--leaf); outline-offset: 1px; }
.form label { display: block; font-size: .84rem; color: var(--muted); margin-bottom: 12px; }
.form label > input, .form label > select, .form label > textarea { margin-top: 4px; color: var(--ink); font-size: 1rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 4px 0 14px; background: var(--card); min-width: 0; }
legend { font-size: .84rem; color: var(--paddy); font-weight: 650; padding: 0 6px; }
.form.shop legend { color: var(--clay); }
.prow { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--line); position: relative; }
.prow input:first-child { grid-column: 1 / -1; padding-right: 44px; }
.prow .x { position: absolute; top: 12px; right: 4px; }
.x { border: 0; background: rgba(0,0,0,.06); color: var(--muted); width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; line-height: 1; flex: none; }
.gps { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.note { background: #fbf1c9; border-radius: 10px; padding: 8px 12px; font-size: .88rem; margin-bottom: 12px; }
.link { border: 0; background: none; color: var(--leaf); padding: 8px 0; font-size: .92rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.pthumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--leaf-soft); }
.pthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pthumb .x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; width: 28px; height: 28px; }
.pthumb.add { display: flex !important; flex-direction: column; align-items: center; justify-content: center; border: 1.5px dashed var(--leaf); background: transparent;
  color: var(--leaf); font-size: 1.5rem; margin: 0 !important; cursor: pointer; text-align: center; }
.pthumb.add small { font-size: .7rem; line-height: 1.3; padding: 0 4px; }
.pthumb.new { outline: 2px solid var(--leaf); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 600; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn.primary { background: var(--paddy); border-color: var(--paddy); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }
.row.between { justify-content: space-between; align-items: center; }
.row.between > .btn { flex: none; }
.row.sticky { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 70px); background: var(--paper); padding: 8px 0; }

/* detail */
.detail { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--leaf); border-radius: var(--radius); padding: 14px; margin-bottom: 26px; }
.detail.shop { border-top-color: var(--clay); }
.detail .title { font-size: 1.3rem; line-height: 1.35; margin: 6px 0 2px; overflow-wrap: anywhere; }
.detail h4 { font-size: .84rem; color: var(--muted); margin: 16px 0 6px; }
.gallery { display: flex; gap: 8px; overflow-x: auto; margin: 12px -14px 0; padding: 0 14px 4px; scroll-snap-type: x mandatory; }
.gallery img { height: 190px; border-radius: 10px; flex: none; scroll-snap-align: center; cursor: zoom-in; background: var(--leaf-soft); }
.ptable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ptable th { text-align: left; font-weight: 600; color: var(--muted); font-size: .76rem; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); }
.ptable td { padding: 7px 6px 7px 0; border-bottom: 1px dashed var(--line); vertical-align: top; overflow-wrap: anywhere; }
dl { margin: 14px 0; }
.kv { display: grid; grid-template-columns: 38% 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv dt { color: var(--muted); font-size: .84rem; }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; }

/* AI */
.badge.other { background: #ece8da; color: var(--muted); }
.connect { padding: 14px; }
.connect h3 { font-size: 1rem; margin-bottom: 4px; }
.connect p { font-size: .9rem; }
.url-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.url-row code { flex: 1; min-width: 0; padding: 9px 10px; background: #efecdf; border-radius: 8px; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { margin: 2px 2px 10px; }
.btn.wide { width: 100%; margin-bottom: 10px; }
.manual { padding: 0 12px; }
.manual summary { padding: 12px 0; color: var(--leaf); font-weight: 600; font-size: .92rem; cursor: pointer; }
.manual form { display: grid; gap: 8px; padding-bottom: 12px; }
.qa { padding: 12px; }
.qa-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qa-head .x { margin-left: auto; }
.qa .q { font-weight: 650; margin: 8px 0 6px; overflow-wrap: anywhere; }
.qa .a { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; border-left: 3px solid var(--leaf-soft); padding-left: 10px; }

/* login, dialog, toast */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.login-mark { font-size: 3rem; }
.login h1 { font-size: 1.6rem; color: var(--paddy); }
.login form { width: 100%; max-width: 320px; margin-top: 24px; display: grid; gap: 10px; }
.err { color: var(--danger); font-size: .88rem; min-height: 1.4em; overflow-wrap: anywhere; }
dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(92vw, 360px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: grid; gap: 10px; }
.foot-actions { display: flex; justify-content: center; gap: 24px; }
#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translate(-50%, 20px); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
