.city-carthage:has(.cm-board) {
    --cm-incision: #2a190d;
    --cm-cut-shadow: rgba(41, 25, 12, .75);
    --cm-stone-edge: rgba(148, 108, 66, .5);
    --cm-active: #23604e;
    --cm-error: #963a27;
    --cm-focus: #725331;
    --cm-surround: #261e16;
}

/* Full-height stone chamber background covering entire viewport */
body.playing .chapter-root.city-carthage.stage-1,
body.playing .chapter-root.city-carthage:has(.cm-board) {
    display: flex !important;
    flex-direction: column !important;
    min-height: 100svh !important;
    height: 100svh !important;
    box-sizing: border-box !important;
    background: var(--cm-surround, #261e16) url("assets/carthage/memory-chamber.png") center top / cover no-repeat !important;
    padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* World is transparent so the full-screen stone chamber shows seamlessly */
body.playing .chapter-root.city-carthage.stage-1 .chapter-world,
body.playing .chapter-root.city-carthage:has(.cm-board) .chapter-world {
    background: transparent !important;
    order: 2 !important;
    position: relative !important;
    min-height: auto !important;
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    padding: 0 !important;
}

body.playing .city-carthage.stage-1 .chapter-world.world-temple.world-unlocked,
body.playing .city-carthage .chapter-world.world-temple.world-unlocked:has(.cm-board) {
    background: transparent !important;
}

.city-carthage.stage-1 .chapter-world .chapter-shade,
.city-carthage:has(.cm-board) .chapter-world .chapter-shade,
.city-carthage.stage-1 .chapter-world .chapter-motes,
.city-carthage:has(.cm-board) .chapter-world .chapter-motes {
    display: none !important;
}

.city-carthage.stage-1 .chapter-heading,
.city-carthage:has(.cm-board) .chapter-heading {
    display: none !important;
}

/* HUD stats (score and temple badge) sit cleanly at top right below header */
body.playing .chapter-root.city-carthage.stage-1 .chapter-stats,
body.playing .chapter-root.city-carthage:has(.cm-board) .chapter-stats {
    order: 0 !important;
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    margin: calc(54px + env(safe-area-inset-top, 0px)) auto 6px !important;
    width: calc(100% - 28px) !important;
    max-width: 432px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    z-index: 25 !important;
}

/* Task instruction box sits right below HUD stats */
body.playing .chapter-root.city-carthage.stage-1 .chapter-task,
body.playing .chapter-root.city-carthage:has(.cm-board) .chapter-task {
    order: 1 !important;
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    bottom: auto !important;
    margin: 4px auto 14px !important;
    width: calc(100% - 28px) !important;
    max-width: 432px !important;
    z-index: 15 !important;
}

.city-carthage.stage-1 .task-raised,
.city-carthage:has(.cm-board) .task-raised {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    bottom: auto !important;
}

.city-carthage.stage-1 .gesture-instruction,
.city-carthage:has(.cm-board) .gesture-instruction {
    font-size: 15px;
    line-height: 1.45;
}

/* Board container inside chamber wall */
body.playing .chapter-root.city-carthage.stage-1 .cm-board,
body.playing .chapter-root.city-carthage:has(.cm-board) .cm-board {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    margin: 10px auto 0 !important;
    width: calc(100% - 24px) !important;
    max-width: 400px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 12px !important;
    z-index: 10 !important;
    pointer-events: none !important;
    background: none !important;
    border: 0 !important;
    box-shadow: none !important;
}

.cm-board .cm-symbol,
.cm-board .cm-observe {
    pointer-events: auto !important;
}

/* Five carved stone boxes */
.cm-slots,
.cm-symbols {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 380px;
    list-style: none;
    margin: 0;
    padding: 0;
    direction: ltr !important;
}

.cm-slot {
    min-width: 0;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--cm-incision);
    direction: ltr !important;
}

.cm-slot b {
    font-family: Georgia, serif;
    font-size: 26px;
    line-height: 1;
    text-shadow: none;
    font-weight: 900;
    -webkit-text-stroke: .7px currentColor;
    direction: ltr !important;
    unicode-bidi: isolate !important;
}

.cm-slot-glyph {
    height: 32px;
}

.cm-slot-glyph svg {
    width: 30px;
    height: 30px;
}

.cm-slot-glyph:empty {
    display: none;
}

.cm-board.observing .cm-slot b {
    display: none;
}

.cm-slot.filled {
    color: var(--cm-incision);
}

/* Stones match authentic wall masonry with recessed carved inset */
.cm-slot,
.cm-board .cm-symbol {
    background: url("assets/carthage/memory-chamber.png") 38% 46% / 900% auto no-repeat;
    border: 1px solid rgba(85, 60, 35, 0.48);
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 230, 180, 0.22);
    mix-blend-mode: normal;
}

.cm-slots li:nth-child(2),
.cm-symbols > :nth-child(2) {
    background-position: 52% 40%;
}

.cm-slots li:nth-child(3),
.cm-symbols > :nth-child(3) {
    background-position: 45% 52%;
}

.cm-slots li:nth-child(4),
.cm-symbols > :nth-child(4) {
    background-position: 58% 48%;
}

.cm-slots li:nth-child(5),
.cm-symbols > :nth-child(5) {
    background-position: 42% 38%;
}

.cm-symbol {
    width: 100%;
    min-height: 68px;
    padding: 6px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--cm-incision);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    text-shadow: none;
}

.cm-symbol svg {
    width: 36px;
    height: 36px;
}

.cm-symbol svg,
.cm-slot-glyph svg {
    filter: none;
    stroke-width: 3;
    opacity: .92;
}

.cm-symbol span {
    font-family: Georgia, serif;
    letter-spacing: .04em;
    -webkit-text-stroke: .4px currentColor;
}

.cm-symbol:disabled {
    opacity: 1;
    cursor: default;
}

.cm-symbol.picked {
    color: var(--cm-incision);
    opacity: .6;
    filter: brightness(.9);
}

.cm-symbol:focus-visible {
    outline: 2px dashed var(--cm-focus);
    outline-offset: 3px;
}

.cm-symbol:not(:disabled):hover,
.cm-symbol:not(:disabled):active {
    filter: brightness(1.08);
    transform: translateY(1px);
}

.cm-symbol.rejected {
    animation: cm-shake .5s;
    color: var(--cm-incision);
}

/* Observe button relief & 3D styling */
.cm-observe {
    position: relative;
    z-index: 6;
    font-size: 14px;
    min-height: 48px;
    margin: 12px auto 0;
    padding: 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 6px;
    background: #e9e2d4 url('assets/carthage/carthage-answer-stone-fill.png') center / 100% 100% no-repeat;
    color: var(--carthage-answer-lettering, #302b25);
    text-shadow: 0 1px 1px var(--carthage-answer-depth, #e3ded3);
    font-weight: 700;
    box-shadow: inset 0 2px 3px rgba(255, 255, 255, .5), inset 0 -3px 5px rgba(48, 43, 37, .45), inset 2px 0 3px rgba(255, 255, 255, .2), inset -2px 0 3px rgba(48, 43, 37, .2), 0 5px 2px -2px #302b2573, 0 9px 6px #302b2540;
    transform: perspective(400px) rotateX(4deg);
    transition: transform .15s, box-shadow .15s;
    mix-blend-mode: normal;
    pointer-events: auto !important;
}

.cm-board .cm-observe:hover:not(:disabled),
.cm-board .cm-observe:focus-visible {
    filter: brightness(1.12);
    outline: 2px solid var(--engraving-gold, #b08746);
    outline-offset: 2px;
    transform: perspective(400px) rotateX(4deg) translateY(-1px);
}

.cm-board .cm-observe:active {
    transform: perspective(400px) rotateX(4deg) translateY(2px) scale(.99);
    box-shadow: inset 0 3px 6px rgba(48, 43, 37, .5), 0 2px 2px #302b2540;
}

.cm-board .cm-observe:disabled {
    box-shadow: inset 0 2px 4px rgba(48, 43, 37, .35);
    transform: none;
    filter: none;
}

.cm-observe[hidden] {
    display: none !important;
}

/* The symbols row stays hidden until observation is done */
.cm-board .cm-symbols {
    display: none;
}

.cm-board.recall .cm-symbols {
    display: grid;
    visibility: visible;
}

.cm-board.observing .cm-symbols {
    display: none;
}

.cm-board.recall .cm-observe,
.cm-board.observing .cm-observe {
    display: none !important;
}

@keyframes cm-shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@media (max-height: 650px) {
    body.playing .chapter-root.city-carthage.stage-1 .chapter-stats,
    body.playing .chapter-root.city-carthage:has(.cm-board) .chapter-stats {
        margin: calc(48px + env(safe-area-inset-top, 0px)) auto 4px !important;
    }

    body.playing .chapter-root.city-carthage.stage-1 .chapter-task,
    body.playing .chapter-root.city-carthage:has(.cm-board) .chapter-task {
        margin: 2px auto 8px !important;
        padding: 8px 12px;
    }

    .city-carthage:has(.cm-board) .gesture-instruction {
        font-size: 13px;
        line-height: 1.35;
    }

    .cm-slot {
        height: 52px;
    }

    .cm-slot b {
        font-size: 22px;
    }

    .cm-symbol {
        min-height: 58px;
    }
}
