:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #f2f1e4;
  background: #0d1918;
  --line: #2a423b;
  --muted: #a3b6aa;
  --accent: #c4e994;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button { color: inherit; font: inherit; cursor: pointer; }
button:focus-visible, canvas:focus-visible, summary:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: .48; }
[hidden] { display: none !important; }
.game-shell { min-height: 100dvh; display: grid; grid-template-rows: auto minmax(355px, 1fr) auto; gap: 14px; max-width: 1700px; margin: auto; padding: 16px clamp(12px, 3vw, 48px) 12px; }
.topbar, .brand, .village-stats, .stat { display: flex; align-items: center; }
.topbar { justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.brand { gap: 12px; }
.brand-icon { display: grid; width: 47px; height: 47px; place-items: center; border-radius: 14px; border: 1px solid #537050; background: #243d31; color: var(--accent); font-size: 30px; line-height: 1; }
h1, h2, p { margin: 0; }
h1 { font-family: Georgia, serif; font-size: clamp(23px, 3vw, 33px); font-weight: 500; letter-spacing: -.035em; line-height: 1.05; }
.brand p { color: var(--muted); font-size: 11px; margin-top: 4px; }
.village-stats { gap: 6px; flex-wrap: wrap; }
.stat { min-width: 79px; gap: 7px; background: #172825; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
.stat-icon { display: grid; place-items: center; width: 27px; height: 27px; color: #c8e697; background: #293b2f; border-radius: 7px; font-size: 18px; }
.stat-heart { color: #f5c98b; background: #42392c; font-size: 14px; }
.stat-gold { color: #f5d17e; background: #443a28; font-size: 16px; }
.stat-berry { background: #423031; font-size: 14px; }
.stat-level { color: #d2beee; background: #3a3348; font-size: 17px; }
.stat small, .stat strong { display: block; line-height: 1.1; }
.stat small { color: var(--muted); font-size: 10px; }
.stat strong { margin-top: 3px; font-size: 17px; font-variant-numeric: tabular-nums; }
.save-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.save-actions button { border: 1px solid #3a5549; border-radius: 8px; background: #1c3029; padding: 7px 8px; font-size: 11px; }
.save-actions button:hover { border-color: #9bbf7e; background: #2c4537; }
.save-actions .save-now { background: #425d36; border-color: #819d64; color: #edf3de; font-weight: 650; }
.save-actions button > span:first-child { margin-right: 2px; color: var(--accent); }
.file-extension { color: var(--muted); }
.topbar-tools, .lighting-tools, .village-tools { display: flex; align-items: center; gap: 6px; }
.topbar-tools { position: relative; flex: 1 0 100%; justify-content: space-between; flex-wrap: wrap; gap: 7px; border-top: 1px solid #263b34; padding-top: 8px; }
.lighting-tools { gap: 2px; padding: 2px; border-radius: 9px; border: 1px solid var(--line); background: #11211e; }
.lighting-tools button, .sound-toggle, .village-board summary { border: 1px solid transparent; border-radius: 7px; padding: 5px 8px; color: #c3d2c8; background: transparent; font-size: 11px; white-space: nowrap; }
.lighting-tools button > span, .sound-toggle > span:first-child, .village-board summary > span { color: #e4c889; padding-right: 2px; }
.lighting-tools button:hover, .sound-toggle:hover, .village-board summary:hover { background: #283d32; color: #f2f1e4; }
.lighting-tools button[aria-pressed='true'] { border-color: #547054; background: #2e4436; color: #f4f0db; }
.lighting-tools button[data-lighting='sunset'][aria-pressed='true'] { background: #51382f; border-color: #92674c; }
.lighting-tools button[data-lighting='moonlight'][aria-pressed='true'] { background: #2d3551; border-color: #646e9d; }
.sound-toggle, .village-board summary { border-color: var(--line); background: #172825; }
.sound-toggle[aria-pressed='true'] { color: #e4efbe; border-color: #678258; }
.village-board { position: relative; }
.village-board summary { list-style: none; cursor: pointer; font-weight: 600; }
.village-board summary::-webkit-details-marker { display: none; }
.village-board[open] summary { background: #314737; border-color: #688459; }
.board-panel { position: absolute; z-index: 3; top: calc(100% + 8px); right: 0; width: min(320px, calc(100vw - 28px)); padding: 11px; border: 1px solid #55725e; border-radius: 11px; background: #192d26; box-shadow: 0 12px 30px #0a1513b3; }
.board-panel label { display: block; font-size: 12px; font-weight: 600; }
.board-panel textarea { display: block; width: 100%; margin: 6px 0; padding: 8px; border-radius: 6px; border: 1px solid #476051; background: #11211e; color: inherit; font: inherit; font-size: 13px; line-height: 1.45; resize: vertical; min-height: 80px; }
.board-panel textarea::placeholder { color: #9fada2; }
.board-panel p { color: var(--muted); font-size: 10px; text-align: right; }
.room-form { display: grid; gap: 5px; }
.room-form input { width: 100%; border: 1px solid #456253; border-radius: 6px; color: inherit; background: #0f211b; padding: 6px 8px; font: inherit; font-size: 12px; }
.room-form button, #room-leave, .order-card button { padding: 5px 8px; border: 1px solid #5d8159; border-radius: 6px; background: #324d36; color: #e5f5c2; font-size: 11px; }
#room-status { font-size: 11px; color: var(--muted); margin-top: 8px; }
#room-save-status { margin-top: 5px; font-size: 10px; color: var(--accent); }
.room-panel { position: static; }
.room-panel[open] .board-panel { right: 0; }
.resident-buttons { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 7px; }
.resident-buttons button { flex: 1; padding: 4px 3px; border: 1px solid #456653; border-radius: 5px; background: #243c33; color: #c6e3e8; font-size: 10px; }
.resident-buttons button:hover { background: #35564a; }
.expeditions { position: relative; margin-top: 9px; border-radius: 7px; border: 1px solid #526c4d; padding: 7px; background: #1c3029; font-size: 11px; }
.expeditions summary { cursor: pointer; font-weight: 700; color: #d7eab4; }
.expeditions[open] { overflow-y: auto; max-height: 360px; }
.order-card { border-top: 1px solid #3b5748; margin-top: 6px; padding-top: 6px; }
.order-card button { margin-top: 4px; }
.order-card strong, .order-card small { display: block; margin: 3px 0; }
.order-card small, #order-info, #stock-list { margin-top: 5px; color: #b7cbb7; line-height: 1.4; overflow-wrap: anywhere; }
.play-area { position: relative; display: grid; grid-template-columns: 184px minmax(0, 1fr); gap: 12px; }
.goals-panel { align-self: start; border: 1px solid var(--line); background: #142522; border-radius: 14px; padding: 12px; }
.goals-panel h2 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 3px; font-size: 13px; }
.goals-panel h2 span { color: var(--muted); font-size: 10px; font-weight: 500; white-space: nowrap; }
.goal-list { display: grid; gap: 7px; }
.goal-card { display: grid; gap: 7px; min-width: 0; border-radius: 9px; border: 1px solid #344a41; background: #1c3029; padding: 8px; }
.goal-card[data-done='true'] { border-color: #618253; background: #273d2e; }
.goal-card.just-completed { animation: goal-reward-glow 850ms ease-out; }
@keyframes goal-reward-glow { 22% { border-color: #edce83; box-shadow: inset 0 0 22px #f2c37440; } }
.goal-top { display: flex; justify-content: space-between; gap: 4px; align-items: baseline; font-size: 11px; }
.goal-count { color: var(--accent); font-size: 10px; white-space: nowrap; }
.goal-card progress { width: 100%; height: 5px; appearance: none; border: 0; border-radius: 5px; background: #101e1b; accent-color: #a6cf77; }
.goal-card progress::-webkit-progress-bar { border-radius: 5px; background: #101e1b; }
.goal-card progress::-webkit-progress-value { border-radius: 5px; background: #a6cf77; }
.goal-card progress::-moz-progress-bar { border-radius: 5px; background: #a6cf77; }
.goal-reward { color: #e6c883; font-size: 10px; }
.viewport { position: relative; isolation: isolate; overflow: hidden; border-radius: 18px; border: 1px solid #345148; background: radial-gradient(ellipse at 50% 46%, #304e3d, #182e2a 64%, #142622); }
.viewport::before, .viewport::after { content: ''; position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity 360ms ease; }
.viewport::before { background: radial-gradient(ellipse at 52% 37%, #68493b, #3c2c2d 60%, #241f28); }
.viewport::after { background: radial-gradient(ellipse at 50% 46%, #263b59, #151f35 64%, #10182a); }
.viewport[data-lighting='sunset']::before, .viewport[data-lighting='moonlight']::after { opacity: 1; }
#village { position: absolute; z-index: 1; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }
#village:focus-visible { outline-offset: -3px; border-radius: inherit; }
.map-effects { position: absolute; z-index: 2; inset: 0; pointer-events: none; overflow: hidden; }
.effect-anchor { position: absolute; top: 0; left: 0; width: 0; height: 0; }
.map-particle { position: absolute; left: -4px; top: -12px; width: 8px; height: 8px; color: var(--color); background: var(--color); opacity: 0; animation: map-spark 760ms var(--delay) cubic-bezier(.18,.58,.44,1) both; }
.map-particle.leaf { border-radius: 85% 10%; }
.map-particle.star { clip-path: polygon(50% 0%, 61% 36%, 100% 50%, 61% 62%, 50% 100%, 36% 62%, 0% 50%, 36% 36%); }
.map-particle.heart { background: transparent; font: normal 12px/8px system-ui, sans-serif; }
@keyframes map-spark {
  0% { opacity: 0; transform: scale(.25); }
  14% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--rotation)) scale(.45); }
}
.effect-caption { position: absolute; left: var(--nudge, 0px); top: -23px; display: grid; justify-items: center; gap: 2px; width: max-content; font-weight: 750; font-size: 13px; text-shadow: 0 1px 3px #0b1513, 0 0 4px #0b1513; opacity: 0; animation: map-reward 1150ms var(--delay) ease-out both; }
.reward-gold { color: #ffe091; }
.reward-berries { color: #ffb8c5; }
.reward-village { color: #d6efa8; }
@keyframes map-reward {
  0% { opacity: 0; transform: translate(-50%, 3px); }
  13%, 70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -33px); }
}
@keyframes map-reward-fade { 0% { opacity: 0; } 13%, 70% { opacity: 1; } 100% { opacity: 0; } }
.map-label, .map-hint, .camera, .selection-panel { position: absolute; border: 1px solid #3e564d; background: #122622ef; }
.map-label, .map-hint, .camera { z-index: 3; }
.map-label { top: 14px; left: 14px; padding: 8px 10px; border-radius: 8px; color: #dbe9d9; font-size: 10px; font-weight: 700; letter-spacing: .09em; pointer-events: none; }
.map-label i, .hint-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.map-label i { margin-right: 5px; }
.map-label span { color: var(--muted); margin-left: 7px; }
.map-hint { bottom: 12px; left: 14px; max-width: calc(100% - 73px); padding: 8px 10px; border-radius: 8px; color: #dbe9d9; font-size: 11px; display: flex; align-items: center; gap: 7px; pointer-events: none; }
.hint-dot { flex: 0 0 6px; }
.camera { bottom: 12px; right: 14px; display: grid; border-radius: 9px; overflow: hidden; }
.camera button, .selection-heading button { border: 0; background: transparent; }
.camera button { width: 36px; height: 34px; font-size: 22px; line-height: 1; }
.camera button + button { border-top: 1px solid var(--line); }
.camera button:hover, .selection-heading button:hover { background: #2c453a; }
.camera button:focus-visible { outline-offset: -3px; }
.selection-panel { z-index: 1; top: 14px; right: 14px; border-radius: 11px; width: min(290px, calc(100% - 28px)); padding: 10px; box-shadow: 0 8px 24px #101c1780; }
.selection-heading { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 14px; }
.selection-heading button { border-radius: 5px; width: 25px; height: 25px; }
.selection-panel p { margin: 4px 0 10px; color: var(--muted); font-size: 12px; }
.selection-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.selection-actions button { background: #294237; border: 1px solid #48624c; border-radius: 6px; padding: 5px 7px; font-size: 11px; }
.selection-actions button:hover:not(:disabled) { border-color: var(--accent); }
.selection-actions .danger { color: #ffc2ae; background: #3b2b27; border-color: #6a483e; }
.selection-actions .primary { color: #e0f3b8; background: #394f32; border-color: #759459; }
.crop-menu { display: grid; gap: 5px; margin-bottom: 9px; max-height: min(235px, 29vh); overflow-y: auto; padding: 2px 4px 2px 2px; }
.crop-choice { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; column-gap: 6px; row-gap: 3px; align-items: center; border: 1px solid #455f4e; border-radius: 7px; background: #22382e; padding: 5px; text-align: left; }
.crop-choice:hover:not(:disabled) { border-color: var(--accent); background: #2e4635; }
.crop-choice > span:first-child { grid-row: span 2; display: grid; place-items: center; font-size: 17px; }
.crop-choice strong { font-size: 11px; }
.crop-choice small { grid-column: 2 / -1; color: #b6c9ba; font-size: 10px; }
.crop-cost { color: #f0d08b; font-size: 10px; white-space: nowrap; }
.build-dock { background: #142522; border: 1px solid var(--line); border-radius: 14px; padding: 11px 13px 9px; }
.dock-heading { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.dock-heading h2 { font-size: 13px; }
.dock-heading > span, .control-help { color: var(--muted); font-size: 10px; }
.dock-heading > span { margin-left: auto; }
.build-catalog { position: relative; }
.build-catalog summary, .catalog-groups button { list-style: none; cursor: pointer; color: #e1ebd5; border: 1px solid #55704d; background: #2b4133; padding: 4px 8px; border-radius: 7px; font-size: 11px; }
.build-catalog summary::-webkit-details-marker { display: none; }
.catalog-panel { position: absolute; z-index: 5; right: 0; bottom: calc(100% + 8px); width: min(620px, calc(100vw - 40px)); background: #172b24; border: 1px solid #55704d; border-radius: 12px; padding: 9px; box-shadow: 0 8px 30px #081510b0; }
.catalog-panel input { width: 100%; min-height: 29px; margin-bottom: 7px; border: 1px solid #496654; border-radius: 6px; padding: 4px 8px; background: #0e211b; color: inherit; }
#catalog-empty { padding: 8px; color: var(--muted); font-size: 11px; }
.catalog-groups { display: flex; gap: 5px; margin-bottom: 7px; }
.catalog-groups button[aria-pressed='true'] { background: #485f3b; border-color: #a4bd79; }
.catalog-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; overflow-y: auto; max-height: min(270px, 44dvh); padding: 2px; }
.catalog-card { display: flex; align-items: center; gap: 7px; text-align: left; padding: 6px; border: 1px solid #40594c; border-radius: 7px; background: #22382d; }
.catalog-card:hover, .catalog-card[aria-pressed='true'] { border-color: #9bbf7e; background: #314a35; }
.catalog-card canvas { flex: 0 0 auto; width: 44px; height: 37px; }
.catalog-card strong, .catalog-card small { display: block; }
.catalog-card strong { font-size: 11px; }
.catalog-card small { color: #d9c790; font-size: 10px; margin-top: 3px; }
.catalog-card .catalog-price { color: #f6d591; font-weight: 650; }
.catalog-card .catalog-description { color: #b0c4b1; line-height: 1.25; }
.farm-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.farm-toolbar label { font-size: 11px; font-weight: 650; }
.farm-toolbar select, .farm-toolbar button { min-height: 28px; padding: 4px 8px; border-radius: 6px; border: 1px solid #58794f; background: #2c4335; color: #e8f3db; font: inherit; font-size: 11px; }
.farm-toolbar button[aria-pressed='true'] { background: #486839; border-color: #bdd584; }
#farm-help { color: var(--muted); font-size: 10px; }
#stock-count { color: var(--muted); font-weight: 400; }
#stock-list > div { display: flex; justify-content: space-between; gap: 7px; padding: 4px; border-bottom: 1px solid #385346; }
#stock-list strong { color: #e8efba; }
.build-tools { display: grid; grid-template-columns: .77fr repeat(3, 1fr) 1.2fr; gap: 7px; }
.tool { display: flex; min-width: 0; align-items: center; gap: 7px; text-align: left; border: 1px solid #344a41; border-radius: 9px; padding: 5px 7px; background: #1c302a; }
.tool:hover { border-color: #75936a; background: #263e33; }
.tool[aria-pressed='true'] { border-color: #a5d47e; background: #324b35; box-shadow: inset 0 0 0 1px #94c36c34; }
.tool-art { flex: 0 0 auto; width: 44px; height: 37px; }
.pointer { display: grid; place-items: center; font-size: 22px; color: var(--accent); }
.tool-copy { flex: 1; }
.tool-copy strong, .tool-copy small { display: block; }
.tool-copy strong { font-size: 12px; line-height: 1.14; }
.tool-copy small { color: #b0c4b6; font-size: 10px; margin-top: 4px; }
kbd { font: inherit; border: 1px solid #42584d; border-radius: 4px; color: #d5e3d3; padding: 1px 4px; white-space: nowrap; }
.tool > kbd { align-self: flex-start; font-size: 9px; }
.control-help { display: flex; flex-wrap: wrap; gap: 7px 14px; margin-top: 9px; line-height: 1.5; }

@media (max-width: 880px) {
  .game-shell { grid-template-rows: auto auto auto; align-content: start; }
  .play-area { grid-template-columns: minmax(0, 1fr); }
  .viewport { order: 1; min-height: clamp(350px, 58dvh, 510px); }
  .goals-panel { order: 3; padding: 7px; }
  .goals-panel h2 { margin-bottom: 6px; }
  .goal-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .file-extension { display: none; }
}

@media (max-width: 760px) {
  .village-stats { order: 2; flex-basis: 100%; }
  .topbar-tools { order: 3; }
  .stat { flex: 1; }
  .tool { gap: 3px; padding-inline: 4px; }
  .tool-art { width: 34px; height: 30px; }
  .tool > kbd { display: none; }
}

@media (max-width: 540px) {
  .village-stats { gap: 4px; }
  .stat { min-width: auto; gap: 4px; padding: 5px; }
  .stat-icon { display: none; }
  .goal-top { flex-wrap: wrap; }
  .brand { gap: 6px; }
  .brand-icon { width: 33px; height: 36px; font-size: 22px; }
  .brand p { font-size: 10px; }
  .game-shell { gap: 8px; padding: 9px 7px; }
  .build-dock { padding-inline: 6px; }
  .build-tools { gap: 4px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tool { flex-direction: column; text-align: center; min-height: 65px; }
  .tool-copy strong { font-size: 10px; }
  .tool-copy small { display: none; }
  .selection-panel { position: static; z-index: auto; order: 2; width: 100%; }
  .lighting-tools button, .sound-toggle, .village-board summary { padding-inline: 6px; }
  .village-tools { justify-content: end; flex: 1; }
  .catalog-list { grid-template-columns: minmax(0,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .viewport::before, .viewport::after { transition: none; }
  .goal-card.just-completed, .map-particle { animation: none; }
  .effect-caption { transform: translateX(-50%); animation-name: map-reward-fade; }
}
