:root {
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #58361f; font-synthesis: none;
  --ink: #593722; --wood: #a76c39; --cream: #f4dca3; --edge: #e3b875;
  --surround: #302a26; --ui-ground: #483325; --ui-edge: #875123;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { display: grid; place-items: center; background: var(--surround); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 3px solid #fff2bc; outline-offset: 2px; }
button:disabled { cursor: default; opacity: .45; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
#game {
  --framed-view: 1; --maximized-view: 0;
  position: relative; box-sizing: content-box;
  width: min(1280px, calc(100vw - 76px), calc((100vh - 76px) * 10 / 7));
  width: min(1280px, calc(100vw - 76px), calc((100dvh - 76px) * 10 / 7));
  height: auto; aspect-ratio: 10 / 7; min-width: 0; min-height: 0; isolation: isolate; container-type: inline-size;
  border: 6px solid transparent; border-image: url('assets/hud-u01/toolbar-frame.png') 20 / 6px;
  box-shadow: 0 6px 0 #211b17; background: var(--ui-ground);
}
#game.is-maximized { --framed-view: 0; --maximized-view: 1; position: fixed; inset: 0; box-sizing: border-box; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-image: none; box-shadow: none; }
.viewport { position: absolute; inset: 0; overflow: hidden; min-width: 0; min-height: 0; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; image-rendering: pixelated; }
.wood { border: 9px solid transparent; border-image: url('assets/hud-u01/toolbar-frame.png') 20 fill / 9px; background: transparent; image-rendering: pixelated; }
.pixel-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 8px solid transparent; border-image: url('assets/account-a01/button-frame.png') 3 fill / 8px; background: transparent; color: #713d1c; image-rendering: pixelated; }
.pixel-button:hover { filter: brightness(1.08); }
.pixel-button:active { transform: translateY(1px); }
.pixel-button img { max-width: 100%; object-fit: contain; image-rendering: pixelated; }
.topbar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.place { display: flex; align-items: center; gap: 9px; padding: 8px 12px; pointer-events: auto; }
.place p { margin: 0 0 2px; color: #8b552d; font-size: 10px; }
.place h1 { margin: 0; font-size: 18px; white-space: nowrap; text-shadow: 0 1px #ffe0a1; }
.town-icon { display: block; flex: 0 0 auto; width: 25px; height: 25px; position: relative; background: #a34e29; clip-path: polygon(0 36%,50% 0,100% 36%,88% 36%,88% 100%,12% 100%,12% 36%); }
.town-icon::after { content: ''; position: absolute; width: 6px; height: 11px; left: 10px; top: 14px; background: #613b22; box-shadow: -7px -2px 0 -1px #ffda80; }
.world-hud { --hud-unit: 2.5px; --energy-unit: 1.5px; display: flex; flex-direction: column; align-items: flex-start; width: calc(var(--hud-unit) * 71 + var(--energy-unit) * 12 + 6px); pointer-events: auto; }
.season-caption { align-self: flex-start; width: calc(var(--hud-unit) * 71); margin: 0 0 2px; min-height: 25px; padding: 0 4px 1px; border-width: 6px; border-image-width: 6px; text-align: center; font-size: 12px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.world-panels { position: relative; width: 100%; }
.clock-panel { position: relative; width: calc(var(--hud-unit) * 71); height: calc(var(--hud-unit) * 43); background: url('assets/hud-u01/clock-frame.png') center / 100% 100% no-repeat; image-rendering: pixelated; }
#world-date { position: absolute; left: calc(var(--hud-unit) * 27); top: calc(var(--hud-unit) * 6); width: calc(var(--hud-unit) * 39); height: calc(var(--hud-unit) * 9); display: flex; align-items: center; justify-content: center; font-size: calc(var(--hud-unit) * 4.8); font-weight: 650; line-height: 1; white-space: nowrap; }
#clock-hand { position: absolute; left: calc(var(--hud-unit) * 19); top: calc(var(--hud-unit) * 5); width: calc(var(--hud-unit) * 7); height: calc(var(--hud-unit) * 19); transform-origin: calc(var(--hud-unit) * 3) calc(var(--hud-unit) * 17); image-rendering: pixelated; }
.weather-copy { position: absolute; left: calc(var(--hud-unit) * 29); top: calc(var(--hud-unit) * 17); width: calc(var(--hud-unit) * 12); height: calc(var(--hud-unit) * 8); }
.weather-icon { display: block; width: 100%; height: 100%; background: url('assets/hud-u01/weather-sunny.png') center / 100% 100% no-repeat; image-rendering: pixelated; }
.weather-icon[data-weather="rain"], .weather-icon[data-weather="heavy-rain"] { background-image: url('assets/hud-u01/weather-rain.png'); }
.weather-icon[data-weather="cloudy"] { background-image: url('assets/hud-u01/weather-rain.png'); clip-path: inset(0 0 25% 0); }
.weather-icon[data-weather="heavy-rain"][data-storm="true"] { background-image: url('assets/hud-u01/weather-storm.png'); }
.weather-icon[data-weather="snow"], .weather-icon[data-weather="heavy-snow"] { background-image: url('assets/hud-u01/weather-snow.png'); }
#season-icon { position: absolute; left: calc(var(--hud-unit) * 53); top: calc(var(--hud-unit) * 17); width: calc(var(--hud-unit) * 12); height: calc(var(--hud-unit) * 8); image-rendering: pixelated; }
.clock-line { position: absolute; left: calc(var(--hud-unit) * 27); top: calc(var(--hud-unit) * 29); width: calc(var(--hud-unit) * 39); height: calc(var(--hud-unit) * 8); display: flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap; }
#world-clock { font: 700 calc(var(--hud-unit) * 6.4)/1 ui-monospace, "SFMono-Regular", Consolas, monospace; color: #6a381e; }
#time-period { color: #89542a; font-size: 8px; line-height: 1; }
.money-panel { position: relative; margin-left: calc(var(--hud-unit) * 6); width: calc(var(--hud-unit) * 65); height: calc(var(--hud-unit) * 17); background: url('assets/hud-u01/money-frame.png') center / 100% 100% no-repeat; image-rendering: pixelated; }
#player-balance { position: absolute; left: calc(var(--hud-unit) * 10); top: calc(var(--hud-unit) * 6); width: calc(var(--hud-unit) * 47); height: calc(var(--hud-unit) * 8); display: grid; grid-template-columns: repeat(8, calc(var(--hud-unit) * 5)); column-gap: var(--hud-unit); color: #a3461d; font: 700 calc(var(--hud-unit) * 6.4)/1 ui-monospace, "SFMono-Regular", Consolas, monospace; }
#player-balance > span { display: grid; place-items: center; min-width: 0; }
.energy-column { position: absolute; top: 0; right: 0; width: calc(var(--energy-unit) * 12); height: calc(var(--hud-unit) * 60); background-image: url('assets/hud-u01/energy-top.png'), url('assets/hud-u01/energy-bottom.png'), url('assets/hud-u01/energy-middle.png'); background-position: top, bottom, center; background-size: 100% calc(var(--energy-unit) * 16), 100% calc(var(--energy-unit) * 16), 100% calc(100% - var(--energy-unit) * 32); background-repeat: no-repeat; image-rendering: pixelated; }
.energy-fill { position: absolute; left: calc(var(--energy-unit) * 3); right: calc(var(--energy-unit) * 3); top: calc(var(--energy-unit) * 15); bottom: calc(var(--energy-unit) * 5); background: linear-gradient(to right, #9acc41 0 30%, #69a02b 30% 80%, #4e7d20 80%); }
.view-controls { display: flex; align-items: center; justify-content: flex-end; gap: 3px; width: 100%; margin-top: 5px; }
.view-controls .pixel-button { width: 36px; height: 36px; }
#zoom-out, #zoom-in { border-image: none; }
.view-controls img { width: 21px; max-height: 24px; }
#zoom-value { width: 31px; color: #ffdfa3; text-align: center; text-shadow: 1px 1px #4b2c17; font: 700 12px ui-monospace, monospace; }
#camera .follow-icon { display: none; width: 24px; height: 24px; }
#camera .free-icon { width: 19px; height: 16px; border: 3px solid #713d1c; box-shadow: inset 2px 2px #ffdc90; }
#camera[data-follow="true"] .follow-icon { display: block; }
#camera[data-follow="true"] .free-icon { display: none; }
.window-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; }
.restore-icon, #window-maximize[aria-pressed="true"] .expand-icon { display: none; }
#window-maximize[aria-pressed="true"] .restore-icon { display: inline; }
#quickbar { position: absolute; z-index: 4; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 280px); }
.bottom-ui { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 4; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; pointer-events: none; }
.bottom-ui > * { pointer-events: auto; }
.chat { position: relative; bottom: 0; width: 284px; max-width: 45%; padding: 2px; color: #5b3e29; }
.chat-title { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 10px; min-height: 30px; padding: 2px 5px 5px; border: 0; background: transparent; font-size: 12px; font-weight: 700; text-align: left; }
.chat-heading, .chat-meta { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.chat-meta { color: #9d774d; font-size: 9px; font-weight: 500; }
.chat-mark { width: 13px; height: 10px; border: 2px solid #98613b; }
.fold-icon { font-size: 17px; line-height: 14px; }
#chat-toggle[aria-expanded="false"] .fold-icon { transform: rotate(180deg); }
.chat:has(#chat-toggle[aria-expanded="false"]) #chat-body { display: none; }
#chat-body { display: grid; grid-template-rows: minmax(0, 1fr) 36px; gap: 5px; height: 134px; padding: 4px 2px 2px; border-top: 1px solid #be8748; }
#chat-messages { list-style: none; margin: 0; padding: 2px; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #ba8d5a transparent; font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
#chat-messages li { padding-block: 2px; }
#chat-messages .system { color: #9a7954; font-size: 11px; }
#chat-messages .chat-name { color: #9c5935; font-weight: 700; margin-right: 5px; }
#chat-messages time { color: #a08964; font-size: 10px; margin-right: 5px; }
#chat-form { display: flex; gap: 5px; min-width: 0; }
#chat-input { flex: 1; width: 0; min-width: 0; height: 36px; padding: 6px 8px; border: 0; border-radius: 0; outline-offset: 1px; background: url('assets/account-a01/textbox-left.png') left / 12px 36px no-repeat, url('assets/account-a01/textbox-right.png') right / 12px 36px no-repeat, url('assets/account-a01/textbox-middle.png') center / calc(100% - 24px) 36px no-repeat; font-size: 12px; }
#chat-input::placeholder { color: #9b6d3c; }
#chat-send { flex: 0 0 44px; padding: 0 3px; border: 6px solid transparent; border-image: url('assets/account-a01/button-frame.png') 3 fill / 6px; background: transparent; font-size: 11px; font-weight: 700; }
.corner-actions { display: flex; gap: 7px; }
.corner-actions .pixel-button { width: 56px; height: 64px; align-content: center; gap: 2px; }
.corner-actions img { width: 32px; height: 32px; }
.corner-actions #tasks-open img { width: 22px; height: 28px; }
.corner-actions span { font-size: 11px; line-height: 1; font-weight: 700; }
/* Legacy model review remains available to its existing handlers, without a HUD shortcut. */
dialog.wood { width: min(724px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 25px; text-align: center; color: var(--ink); }
dialog::backdrop { background: #29221ca8; }
.close { position: absolute; right: 12px; top: 10px; font-size: 25px; border: 2px solid #90532d; background: #f2cd84; width: 32px; height: 32px; }
#character-preview { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.stride-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin: 12px 0; }
.stride-controls button { padding: 7px 10px; border: 2px solid #a46b38; background: #f4d797; }
/* Existing farm-controller test URL is retained; the approved F25 farm is separate. */
.farm-tools { position: absolute; z-index: 4; right: 12px; bottom: 100px; width: min(520px, calc(100% - 24px)); padding: 7px; }
.farm-tool-buttons { display: flex; gap: 5px; }
.farm-tools button, .farm-tools select { border: 2px solid #7c4b2d; background: #e5bf80; font: inherit; font-size: 12px; padding: 5px; }
.farm-tool-buttons button { flex: 1; }
.farm-tools button[aria-pressed="true"] { background: #ffe7a5; outline: 2px solid #e5a548; }
.farm-seed-label { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.farm-tools p, .farm-day-row { margin: 5px 0 0; font-size: 11px; }
.farm-day-row { display: flex; justify-content: space-between; }
/* Keep all bottom controls on one baseline; compact the bar only when needed. */
@container (max-width: 1220px) {
  #quickbar { --hud-slot-size: 40px; }
  .chat { width: min(260px, calc((100cqw - 508px) / 2 - 24px)); max-width: none; }
}
@container (max-width: 1000px) {
  #quickbar { --hud-slot-size: 32px; }
  .chat { width: min(240px, calc((100cqw - 412px) / 2 - 24px)); }
}
@container (max-width: 760px) {
  #quickbar { left: 240px; right: 136px; width: auto; max-width: none; transform: none; }
  .chat { width: 216px; }
}
@media (pointer: coarse), (max-width: 700px), (max-width: 1100px) and (max-height: 600px) {
  #game, #game.is-maximized { --framed-view: 0; --maximized-view: 0; position: relative; inset: auto; box-sizing: border-box; aspect-ratio: auto; width: 100%; height: 100vh; height: 100dvh; border: 0; border-image: none; box-shadow: none; }
  #camera, #window-maximize { display: none; }
  .world-hud { --hud-unit: 2px; --energy-unit: 1px; }
  .season-caption { min-height: 21px; font-size: 10px; border-width: 5px; border-image-width: 5px; }
  .view-controls { gap: 4px; justify-content: center; }
  .view-controls .pixel-button { width: 38px; height: 36px; }
  #time-period { display: none; }
  .topbar { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); }
  .bottom-ui { left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); }
  #quickbar { --hud-slot-size: 48px; left: 50%; right: auto; width: max-content; transform: translateX(-50%); bottom: max(8px, env(safe-area-inset-bottom)); max-width: calc(100% - 260px); }
  .chat { width: 250px; bottom: 82px; }
  .corner-actions .pixel-button { width: 48px; height: 58px; }
  .corner-actions img { width: 26px; height: 26px; }
  .corner-actions span { font-size: 10px; }
}
/* Do not shrink the bar in short, mouse-driven desktop windows. */
@media (pointer: coarse), (max-width: 700px) {
  #quickbar { --hud-slot-size: 36px; border-width: 9px; border-image-width: 9px; }
  #quickbar .hud-more { margin-left: 3px; font-size: 22px; padding-bottom: 9px; }
  #quickbar .hud-hotkey { top: 2.25px; left: 3.75px; font-size: 7.5px; }
  #quickbar .hud-item-count { right: 3.75px; bottom: 1.5px; font-size: 9px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .place { padding: 4px 7px; }
  .place h1 { font-size: 15px; }
  .place p { font-size: 9px; }
  #chat-body { height: 96px; grid-template-rows: minmax(0, 1fr) 32px; }
  #chat-input { height: 32px; font-size: 16px; background-size: 11px 32px, 11px 32px, calc(100% - 22px) 32px; }
}
/* A compact landscape chat toggle sits beside the bar; its body opens above. */
@media (orientation: landscape) and (min-width: 501px) and (pointer: coarse), (orientation: landscape) and (min-width: 501px) and (max-width: 700px) {
  #quickbar { left: calc(max(8px, env(safe-area-inset-left)) + 140px); right: auto; width: max-content; max-width: calc(100% - max(8px, env(safe-area-inset-left)) - 140px - max(8px, env(safe-area-inset-right)) - 111px); transform: none; }
  .chat { bottom: 0; width: 132px; max-width: none; padding: 0; border-width: 7px; border-image-width: 7px; }
  .chat-title { min-height: 40px; padding: 2px; gap: 5px; font-size: 11px; }
  .chat-heading { gap: 5px; }
  .chat-meta { gap: 4px; font-size: 8px; }
  #chat-body { position: absolute; left: -7px; bottom: calc(100% + 13px); width: min(300px, calc(100vw - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)))); height: min(144px, calc(100dvh - 78px)); padding: 6px; border: 7px solid transparent; border-image: url('assets/hud-u01/toolbar-frame.png') 20 fill / 7px; grid-template-rows: minmax(0, 1fr) 32px; }
  #chat-input { height: 32px; font-size: 16px; background-size: 11px 32px, 11px 32px, calc(100% - 22px) 32px; }
}
@media (max-width: 700px) and (orientation: portrait), (max-width: 500px) {
  #game { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .viewport { position: relative; grid-row: 2; min-height: 0; border-block: 3px solid var(--ui-edge); }
  .topbar { position: static; grid-row: 1; display: grid; grid-template-columns: minmax(0, 130px) 32px minmax(142px, 1fr); grid-template-rows: 36px 34px 30px; gap: 3px 8px; align-items: start; padding: max(7px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-right)) 7px max(9px, env(safe-area-inset-left)); }
  /* Flatten only the portrait layout, retaining the same live elements and IDs. */
  .world-hud, .world-panels { display: contents; }
  .place { grid-column: 1; grid-row: 1; justify-self: start; min-width: 0; height: 36px; gap: 6px; padding: 3px 6px; border-width: 6px; border-image-width: 6px; }
  .place p { display: none; }
  .place h1 { font-size: 14px; line-height: 18px; }
  .town-icon { width: 18px; height: 18px; }
  .town-icon::after { left: 7px; top: 10px; width: 5px; height: 8px; }
  .season-caption { grid-column: 3; grid-row: 1; justify-self: end; align-self: start; margin: 0; }
  .clock-panel { grid-column: 3; grid-row: 1 / 4; justify-self: end; align-self: start; margin-top: 24px; height: calc(var(--hud-unit) * 41); background-size: 100% calc(var(--hud-unit) * 43); background-position: center top; clip-path: polygon(0 0, 100% 0, 100% calc(var(--hud-unit) * 41), calc(var(--hud-unit) * 21) calc(var(--hud-unit) * 41), calc(var(--hud-unit) * 21) calc(var(--hud-unit) * 40), calc(var(--hud-unit) * 18) calc(var(--hud-unit) * 40), calc(var(--hud-unit) * 18) calc(var(--hud-unit) * 41), 0 calc(var(--hud-unit) * 41)); }
  .money-panel { grid-column: 1; grid-row: 2; margin-left: 0; }
  .energy-column { grid-column: 1; grid-row: 3; position: relative; inset: auto; width: 130px; height: 18px; border: 4px solid transparent; border-image: url('assets/hud-u01/toolbar-frame.png') 20 fill / 4px; background: none; pointer-events: auto; }
  .energy-column::before { content: '体力'; position: absolute; left: 1px; top: 50%; z-index: 1; transform: translateY(-50%); font-size: 9px; font-weight: 700; line-height: 1; }
  .energy-fill { left: 23px; right: 1px; top: 1px; bottom: 1px; background: linear-gradient(to bottom, #9acc41 0 30%, #69a02b 30% 80%, #4e7d20 80%); }
  .view-controls { grid-column: 2; grid-row: 1 / 4; width: 32px; height: 94px; margin: 0; flex-direction: column; align-items: center; justify-content: space-between; gap: 3px; pointer-events: auto; }
  .view-controls .pixel-button { width: 32px; height: 30px; border-width: 6px; border-image-width: 6px; }
  .view-controls img { width: 18px; max-height: 20px; }
  #zoom-in { order: -1; }
  #zoom-out { order: 1; }
  #quickbar { --hud-slot-size: 33px; max-width: calc(100% - 16px); bottom: 8px; }
  .bottom-ui { position: static; grid-row: 3; align-items: flex-end; gap: 7px; padding: 6px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .chat { position: static; bottom: auto; flex: 1; width: 0; min-width: 0; max-width: none; padding: 1px; border-width: 7px; border-image-width: 7px; }
  .chat-title { min-height: 32px; padding: 2px; font-size: 11px; }
  .chat-meta { gap: 4px; font-size: 8px; }
  #chat-body { height: 112px; grid-template-rows: minmax(0, 1fr) 36px; padding: 3px 0 0; }
  #chat-input { height: 36px; font-size: 16px; }
  #chat-send { flex-basis: 40px; }
  #chat-messages { font-size: 11px; }
  .corner-actions { gap: 5px; }
  .corner-actions .pixel-button { width: 45px; height: 56px; border-width: 7px; border-image-width: 7px; }
  #game[data-scene="farm"] { grid-template-rows: auto minmax(0, 1fr) auto auto; }
  #game[data-scene="farm"] .farm-tools { position: static; grid-row: 3; margin: 0 7px 5px; width: auto; }
  #game[data-scene="farm"] .bottom-ui { grid-row: 4; }
}
@media (max-width: 360px) {
  .topbar { padding-inline: 7px; column-gap: 5px; }
  .place { padding-inline: 4px; }
  .place h1 { font-size: 14px; }
  .money-panel { --hud-unit: 1.8px; }
  .energy-column { width: 117px; }
  .town-icon { display: none; }
  .bottom-ui { padding-inline: 6px; gap: 5px; }
  .chat-heading { gap: 4px; }
  .chat-meta { font-size: 7px; }
}
