:root {
    /* colour palette */
    --cream: #e8dabf;
    --cream-light: #f2ead6;
    --cream-panel: #E1CEA6;
    --field: #9caf80;
    --field-dark: #8ba070;
    --ink: #2f2a20;
    --ink-soft: #5c5344;
    --slot: #c4b3a4;
    --slot-edge: #b3a192;
    --gold: #e8c96a;
    --bar-track: #cdbfa3;

    /* shapes */
    --r-sm: 10px;
    --r-md: 18px;
    --r-lg: 28px;
    --r-xl: 36px;

    /* type */
    --font: "Pixelify Sans", sans-serif;
    --fs-title: 30px;
    --fs-head: 20px;
    --fs-body: 14px;
    --fs-small: 12px;

    /* spacing */
    --gap: 14px;
    --pad: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background: var(--cream);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-body);
    letter-spacing: .04em;
    text-transform: lowercase;
    overflow: hidden;
    display: block;
}

h1, h2 {
    font-weight: 700;
    line-height: 1.15;
    font-size: 5rem;
}

a {
    color: var(--ink);
    text-decoration: none;
}

button {
    font: inherit;
    text-transform: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

.world {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.field {
    position: absolute;
    inset: 15px;
    background-image: url("images/village drawing with river.png");
    background-repeat: no-repeat;
    background-size: 2500px auto;
    background-position: 0 0;
    border-radius: var(--r-lg);
    overflow: hidden;
    cursor: grab;
}

.field:active {
    cursor: grabbing;
}

.tile {
    aspect-ratio: 1;
    border-radius: 4px;
    display: grid;
    place-items: center;
    font-size: .85rem;
    opacity: .28;
    transition: opacity .25s ease, transform .25s ease, background .2s;
}

.tile.empty {
    opacity: 0;
}

.tile.empty:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .16);
}

.tile.active {
    opacity: 1;
    transform: scale(1.35);
}

@keyframes arrive {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    55% {
        transform: scale(1.7);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.tile.arriving {
    animation: arrive .9s cubic-bezier(.34, 1.56, .64, 1);
    opacity: 1 !important;
    z-index: 3;
}

/* titlebar */
.titlebar {
    position: absolute;
    top: 14px;
    left: 20px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 10px;
}

.titlebar h1 {
    font-size: 22px;
    line-height: 1.05;
    letter-spacing: .02em;
}

.stats {
    font-weight: 700;
    top: 14px;
    right: 14px;
}

.panel {
    top: 150px;
}

.pill-btn {
    position: relative;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--cream-light);
    display: grid;
    place-items: center;
    transition: transform .15s ease;
    flex-shrink: 0;
    margin-top: 2px;
}

.pill-btn .pill-lines,
.pill-btn .pill-lines::before,
.pill-btn .pill-lines::after {
    content: "";
    position: absolute;
    width: 12px;
    height: 2px;
    border-radius: 99px;
    background: var(--ink);
    display: block;
}

.pill-btn .pill-lines {
    transform: translateY(0);
}

.pill-btn .pill-lines::before {
    transform: translateY(-5px);
}

.pill-btn .pill-lines::after {
    transform: translateY(5px);
}

.pill-btn:hover {
    transform: translateY(-2px);
}

.pill-btn:active {
    transform: translateY(1px);
}

/* stats card — coins + happiness */
.stats {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 6;
    width: 200px;
    padding: 14px 16px 16px;
    background: rgba(232, 218, 191, 0.62);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.stat-label {
    font-size: var(--fs-small);
    color: #412812;
    line-height: 1.2;
}

.stat-value {
    background: var(--cream-light);
    border-radius: var(--r-sm);
    padding: 5px 10px;
    font-size: var(--fs-body);
    white-space: nowrap;
}

/* happiness bar */
.bar {
    height: 7px;
    background: var(--bar-track);
    border-radius: 99px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    width: 0%;
    background: var(--gold);
    border-radius: 99px;
    transition: width .5s ease, background .5s ease;
}

.bar-fill.low {
    background: #c98b5e;
}

.bar-fill.mid {
    background: var(--field-dark);
}

/* game guide */
.panel {
    position: absolute;
    top: 140px;
    left: 0;
    z-index: 7;
    width: 230px;
    max-height: 360px;
    padding: var(--pad) 18px;
    background: var(--cream-panel);
    border-radius: 0 var(--r-md) var(--r-md) 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform .3s cubic-bezier(.34, 1.3, .64, 1),
                opacity .25s ease,
                visibility .3s;
}

.panel.open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

.panel h2 {
    font-size: var(--fs-head);
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--cream-light);
    display: grid;
    place-items: center;
    font-size: var(--fs-small);
}

.panel-body {
    overflow-y: auto;
    padding-right: 8px;
    line-height: 1.5;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* chunky pixel scrollbar */
.panel-body::-webkit-scrollbar {
    width: 5px;
}

.panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
    background: #6b4f2f;
    border-radius: 99px;
}

.backpack {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 8;
    width: 600px;
    padding: 0px 24px 24px;
    border-radius: 20px;
    background: var(--cream-panel);
    overflow: hidden;
    transition: transform .35s cubic-bezier(.34, 1.3, .64, 1);
}

.grabber {
    width: 170px;
    height: 7px;
    margin: 0 auto 14px;
    background: #6b4f2f;
    border-radius: 99px;
    cursor: grab;
    touch-action: none;
}

.backpack-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 5px;
}

.backpack-head h2 {
    font-size: 24px;
    font-weight: 700;
}

.actions-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0px 14px;
    background: #E8DABF;
    border-radius: 10px;
    color: #412812;
    font-family: "Pixelify Sans";
    font-size: 14px;
    font-style: normal;
    font-weight: 700;
    line-height: normal;
}

.actions-pill .dots {
    color: var(--ink-soft);
    letter-spacing: -2px;
}

/* slots */
.slots {
    display: flex;
    flex-direction: row;
    gap: var(--gap);
    overflow-x: auto;
    padding: var(--pad);
    width: 100%;
    max-height: 200px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.slot {
    position: relative;
    width: 147px;
    height: 116px;
    background: #B9A698;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 30px;
    cursor: default;
    transition: transform .18s ease;
    flex-shrink: 0;
    overflow: hidden;
}

.slot.active {
  cursor: grabbing;
}

.slot img,
.slot .slot-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: auto;
  align-items: left;
}

.slot:hover {
    transform: translateY(-4px);
}

.slot.selected {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

.slot.locked {
    opacity: .45;
    cursor: not-allowed;
}

.toast {
    position: absolute;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    padding: 10px 20px;
    background: var(--cream-panel);
    border-radius: 99px;
    font-size: var(--fs-body);
    animation: drop .4s cubic-bezier(.34, 1.4, .64, 1);
    transition: opacity .5s, transform .5s;
}

.toast.out {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
}

@keyframes drop {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-14px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

dialog {
    border: none;
    border-radius: var(--r-md);
    padding: 26px;
    width: 320px;
    background: var(--cream-panel);
    color: var(--ink);
    font-family: var(--font);
    text-transform: lowercase;
}

dialog::backdrop {
    background: rgba(47, 42, 32, .45);
}

dialog h2 {
    font-size: var(--fs-head);
    margin-bottom: 14px;
}

dialog label {
    display: block;
    margin: 14px 0;
    font-size: var(--fs-small);
    color: var(--ink-soft);
}

dialog select,
dialog input {
    width: 100%;
    margin-top: 6px;
    padding: 9px 10px;
    font: inherit;
    font-size: var(--fs-body);
    color: var(--ink);
    background: var(--cream-light);
    border: none;
    border-radius: var(--r-sm);
}

dialog select:focus,
dialog input:focus {
    outline: 2px solid var(--field-dark);
}

.row {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}

.row button {
    flex: 1;
    padding: 11px;
    border-radius: var(--r-sm);
    background: var(--cream-light);
    transition: transform .15s ease;
}

.row button:hover {
    transform: translateY(-2px);
}

.row button:active {
    transform: translateY(2px);
}

.row .primary {
    background: var(--field);
    color: var(--cream-light);
}

@media (max-width: 720px) {
    :root {
        --fs-title: 24px;
        --fs-head: 17px;
    }

    .world {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .field {
        inset: 40px 12px 12px 12px;
        padding: 10px;
    }

    .stats {
        width: 150px;
        right: 0;
        padding: 10px 12px;
    }

    .panel {
        width: 165px;
        top: 150px;
        max-height: 260px;
    }

    .backpack {
        width: 100%;
        max-width: 100%;
        padding: 12px 16px 18px;
    }

    .backpack-head h2 {
        font-size: 22px;
    }
  }

.slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
}

.slot {
  position: relative;
  aspect-ratio: 1 / .82;
  padding: 8px;
  background: var(--slot);
  border-radius: var(--r-sm);
  box-shadow: inset 0 -4px 0 var(--slot-edge);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  transition: transform .18s ease, box-shadow .18s ease;
}

.slot:hover {
  transform: translateY(-5px);
  box-shadow: inset 0 -4px 0 var(--slot-edge), 0 6px 0 rgba(47, 42, 32, 0.12);
}

.slot.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  transform: translateY(-5px);
}

.slot-empty {
  cursor: default;
  box-shadow: inset 0 -4px 0 var(--slot-edge);
}
.slot-empty:hover { transform: none; }

/* the artwork */
.slot-img {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72%;
  height: 60%;
  max-width: 72%;
  max-height: 60%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: auto;
  transition: transform .18s ease;
}
.slot:hover .slot-img { transform: translate(-50%, -52%) scale(1.06); }

/* +0.8% badge */
.slot-happy {
  position: absolute;
  top: 7px; right: 8px;
  font-size: 10px;
  color: var(--ink-soft);
  z-index: 2;
}

/* name + note row */
.slot-foot {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px;
}

.slot-name {
  font-size: 15px;
  color: var(--ink);
  line-height: 1;
}

.slot-note {
  font-size: 9px;
  color: var(--ink-soft);
  text-align: right;
  line-height: 1.15;
  max-width: 52%;
}

.placed-items {
    position: absolute;
    left: 0;
    top: 0;
    width: 2500px;
    height: 1350px;
    z-index: 2;
    pointer-events: none;
}

.placed-items.dragging {
    z-index: 9;
}

.placed-item {
    position: absolute;
    width: 100px;
    height: auto;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
}

.placed-item:active {
    cursor: grabbing;
}

/* cursor feedback while an item is armed */
body.placing .tile.empty { opacity: .18; background: rgba(255,255,255,.14); }
body.placing .field      { cursor: crosshair; }