/* Agentopia: the town fills the screen; Hay Day's top bar (the town, the level, coins and acorns), a bar of four buttons at the bottom,
   a card for whatever you tap and a sheet for the order board, the barn and the builder's catalogue. Warm paper, Mongoose Town's palette. */
:root { --paper: #fffaf1; --ink: #2f281f; --muted: #776a58; --line: #e6dac6; --accent: #b5602f; --grass: #7daa4a; --gold: #c99a3a; --ok: #2f6b4f; --short: #b4452f; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { user-select: none; -webkit-user-select: none; }
input { user-select: text; }
html, body { margin: 0; height: 100%; background: var(--grass); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--ok); outline-offset: 2px; }
.ag-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.ag-top { position: fixed; inset: 0 0 auto; z-index: 3; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); pointer-events: none; }
.ag-top > * { pointer-events: auto; background: rgba(255,250,241,.95); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 2px 10px rgba(40,30,15,.18); height: 38px; display: flex; align-items: center; }
.ag-town { padding: 0 16px; font: 600 17px/1 Georgia, 'Iowan Old Style', serif; cursor: pointer; max-width: 40vw; }
.ag-town span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-lvlbox { gap: 8px; padding: 0 12px 0 3px; margin-right: auto; }
.ag-lvl { width: 32px; height: 32px; border-radius: 50%; background: #3e7fbf; color: #fff; display: grid; place-items: center; font-size: 15px; border: 2px solid #fff; box-shadow: 0 0 0 2px #2e5c86; }
.ag-xpbar { width: 84px; height: 10px; border-radius: 5px; background: #e8dcc6; overflow: hidden; }
.ag-xpbar i { display: block; height: 100%; background: linear-gradient(#7cc4f0, #3e8fd0); border-radius: 5px; transition: width .4s ease; }
.ag-money { gap: 7px; padding: 0 14px 0 8px; font-size: 16px; }
.ag-coin { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe9a3, #e9b53c 55%, #b9821f); border: 2px solid #a87518; }

.ag-main { position: fixed; inset: 0; }
.ag-map { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.ag-map:active { cursor: grabbing; }
.ag-editing .ag-map { cursor: crosshair; }
.ag-loading { position: fixed; inset: 45% 0 auto; text-align: center; font: 600 18px/1.3 Georgia, serif; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.4); margin: 0; }

.ag-zoom { position: fixed; right: max(12px, env(safe-area-inset-right, 0px)); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); z-index: 2; display: grid; gap: 6px; }
.ag-zoom button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,250,241,.95); font-size: 20px; line-height: 1; cursor: pointer; box-shadow: 0 2px 10px rgba(40,30,15,.18); }

.ag-bar { position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; padding: 6px; background: rgba(255,250,241,.95); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 6px 22px rgba(40,30,15,.25); }
.ag-bar button { position: relative; display: grid; justify-items: center; gap: 1px; min-width: 70px; padding: 6px 10px 5px; border: 0; border-radius: 16px; background: transparent; font-size: 12px; font-weight: 600; cursor: pointer; }
.ag-bar button span { font-size: 22px; line-height: 1.1; }
.ag-bar button:hover { background: #f4ead8; }
.ag-bar button[aria-pressed="true"] { background: #f3dfc0; box-shadow: inset 0 0 0 2px var(--gold); }
.ag-badge { position: absolute; top: 2px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--short); color: #fff; font-size: 11px; line-height: 18px; }

.ag-tools { position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 4px; padding: 4px; background: rgba(255,250,241,.95); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 16px rgba(40,30,15,.2); }
.ag-tools button { border: 0; background: transparent; padding: 7px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.ag-tools button[aria-pressed="true"] { background: var(--ok); color: #fff; }

.ag-place { position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); top: calc(62px + env(safe-area-inset-top, 0px)); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 8px; width: max-content; max-width: calc(100vw - 24px); padding: 8px 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 6px 22px rgba(40,30,15,.25); }
.ag-place-name { font-weight: 600; } .ag-place-hint { color: var(--muted); font-size: 13px; margin-right: 6px; }
.ag-pbtn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 12px; font-weight: 600; cursor: pointer; }
.ag-ok { background: var(--ok); border-color: var(--ok); color: #fff; }

.ag-card, .ag-sheet { position: fixed; z-index: 4; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 10px 32px rgba(40,30,15,.25); overflow: auto; }
.ag-card { left: max(12px, env(safe-area-inset-left, 0px)); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); width: min(380px, calc(100vw - 24px)); max-height: min(58vh, 520px); border-radius: 16px; padding: 14px 16px; }
.ag-sheet { left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 170px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); border-radius: 20px; padding: 16px 18px; }
.ag-card h2, .ag-sheet h2 { margin: 0 34px 6px 0; font: 600 20px/1.25 Georgia, serif; }
.ag-sheet h3, .ag-store h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ag-card p, .ag-sheet p { margin: 0 0 8px; }
.ag-meta { color: var(--muted); font-size: 13px; }
.ag-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.06); font-size: 20px; line-height: 1; cursor: pointer; }
.ag-btn { border: 0; background: var(--ok); color: #fff; border-radius: 10px; padding: 7px 14px; font-weight: 600; cursor: pointer; }
.ag-btn:disabled, .ag-choice:disabled, .ag-item:disabled { opacity: .45; cursor: default; }
.ag-link { border: 0; background: none; padding: 4px 0; color: var(--accent); font-weight: 600; cursor: pointer; display: block; }
.ag-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.ag-choice { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 12px; font-weight: 600; cursor: pointer; }
.ag-needs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.ag-needs span { padding: 2px 8px; border-radius: 8px; font-size: 13px; font-weight: 600; background: #eef5e6; color: var(--ok); }
.ag-needs .ag-short { background: #f8e6df; color: var(--short); }
.ag-queue { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 4px; }
.ag-queue li { display: flex; justify-content: space-between; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.ag-recipes { display: grid; gap: 6px; }
.ag-recipe { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.ag-recipe .ag-rname { font-weight: 600; } .ag-recipe .ag-needs, .ag-recipe > .ag-meta { grid-column: 1; } .ag-recipe .ag-btn { grid-column: 2; grid-row: 1 / span 3; }
.ag-rename { display: flex; gap: 6px; margin: 6px 0 10px; }
.ag-rename input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font: inherit; background: #fff; }

.ag-orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.ag-order { background: #fff8e8; border: 1px solid #ead7b0; border-radius: 14px; padding: 10px 12px; box-shadow: 0 1px 0 #ead7b0; }
.ag-order.ag-wait { background: #f4efe6; display: grid; place-items: center; min-height: 96px; }
.ag-pay { font-weight: 700; color: #8a6418; }
.ag-store { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px 12px; margin-bottom: 10px; }
.ag-meter { height: 10px; border-radius: 5px; background: #efe5d3; overflow: hidden; margin-bottom: 8px; }
.ag-meter i { display: block; height: 100%; background: var(--gold); }
.ag-inv { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.ag-inv li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.ag-inv .ag-link { display: inline; }
.ag-shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.ag-item { display: grid; justify-items: center; gap: 2px; padding: 8px 6px; background: #fff; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; text-align: center; }
.ag-item img { width: 92px; height: 70px; object-fit: contain; }
.ag-item b { font-size: 13px; }

.ag-toast { position: fixed; z-index: 5; left: 50%; transform: translateX(-50%); top: calc(62px + env(safe-area-inset-top, 0px)); margin: 0; max-width: calc(100vw - 24px); padding: 9px 16px; border-radius: 14px; background: rgba(47,40,31,.92); color: #fff7ea; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.ag-toast.ag-good { background: rgba(47,107,79,.95); }

@media (max-width: 560px) {
  .ag-top { gap: 6px; }
  .ag-town { font-size: 15px; padding: 0 12px; max-width: 34vw; }
  .ag-xpbar { width: 40px; }
  .ag-money { padding: 0 10px 0 6px; font-size: 14px; }
  .ag-bar button { min-width: 62px; padding: 6px 6px 5px; }
  .ag-card { left: 12px; right: 12px; width: auto; max-height: 46vh; }
}

.ag-ico { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; flex: none; }
.ag-lab { display: inline-flex; align-items: center; gap: 5px; }
.ag-needs .ag-lab { padding: 2px 8px 2px 4px; }
.ag-choice, .ag-btn { display: inline-flex; align-items: center; gap: 6px; }
.ag-link { display: flex; align-items: center; gap: 6px; }
.ag-inv .ag-link { display: inline-flex; }
.ag-btn .ag-ico, .ag-link .ag-ico { width: 20px; height: 20px; }
.ag-rname { font-weight: 600; }
.ag-needs .ag-ico, .ag-inv .ag-ico, .ag-rname .ag-ico, .ag-queue .ag-ico { width: 32px; height: 32px; }
