:root {
    /* 14 cells * 50px max cell size + 13 * 1px gap + 2px border */
    --grid-max-width: 715px;
}
 * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    padding: 40px;
    background: #fff;
    color: #1a1a1a;
}
h1 {
    margin-bottom: 1.5rem;
    color: #1a1a1a;
    font-size: 1.6rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.controls {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 12px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 20px;
}
button {
    padding: 10px 1.5rem;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid #1a1a1a;
    border-radius: 0;
    background: transparent;
    color: #1a1a1a;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 400;
    transition: all 0.2s;
}
button:hover {
    background: #1a1a1a;
    color: #fff;
}
button.submit {
    border-color: #FBC52F;
    color: #FBC52F;
    background: transparent;
}
button.submit:hover {
    background: #FBC52F;
    color: #fff;
}
button.danger {
    border-color: #d9534f;
    color: #d9534f;
    background: transparent;
}
button.danger:hover {
    background: #d9534f;
    color: #fff;
}
.grid-container {
    display: inline-block;
    background: #fff;
    padding: 0;
}
.grid {
    display: grid;
    gap: 1px;
    background: #e0e0e0;
    border: 1px solid #e0e0e0;
    user-select: none;
    touch-action: none;
    margin-block: 1.5rem;
}
.cell {
    width: 60px;
    height: 60px;
    overflow: hidden;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #999;
    transition: background 0.1s;
}
.cell img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
    object-fit: contain;
}
.cell.invalid {
    background: #f5c6cb;
}
.cell:hover {
    box-shadow: inset 0 0 0 2px #FBC52F;
}
.cell { position: relative; }
.cell.daybed-anchor {
    overflow: visible;
    z-index: 5;
}
.main-content {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    align-items: flex-start;
}
.grid-wrapper {
    flex-shrink: 0;
}
.quantity-overview {
    padding: 20px;
    border: 1px solid #e0e0e0;
    flex: 1 1 220px;
    max-width: var(--grid-max-width);
}
.quantity-overview h3 {
    margin-bottom: 12px;
    color: #1a1a1a;
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}
.quantity-list {
    list-style: none;
}
.quantity-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-top: 1px solid #f0f0f0;
    font-size: 13px;
    color: #333;
}
.quantity-list li:first-child {
    border-top: none;
}
.tutorial {
    padding: 20px;
    border: 1px solid #e0e0e0;
    flex-shrink: 0;
    width: 100%;
    max-width: var(--grid-max-width);
}
.tutorial h3 {
    margin-bottom: 12px;
    color: #1a1a1a;
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}
.tutorial ol {
    padding-left: 10px;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    grid-auto-flow: row;
    column-gap: 1.5rem;
}
.tutorial li {
    font-size: 13px;
    color: #333;
    padding: 6px 0;
    line-height: 1.5;
}
.tutorial li + li {
    border-top: 1px solid #f0f0f0;
}
.tutorial .hint {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    color: #999;
    line-height: 1.5;
}
.tutorial .button-wrapper {
    display: flex;
    justify-content: space-between;
}
.tutorial button {
    background: none;
    border: none;
    padding: 0;
    width: 100%;
    position: relative;
    text-align: left;
}
.tutorial-button {
    text-decoration: underline transparent;
    text-underline-offset: 4px;
    transition: text-decoration-color 0.2s ease;
}
.tutorial-button:hover {
    background: none;
    color: inherit;
    text-decoration-color: currentColor;
}
.tutorial .tutorial-collapsed {
    padding-top: 0px;
    overflow: hidden;
    height: 0px;
}
.legend {
    padding: 20px;
    border: 1px solid #e0e0e0;
    width: 100%;
    max-width: var(--grid-max-width);
}
.legend h3 {
    margin-bottom: 12px;
    color: #1a1a1a;
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}
.legend-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 1rem;
    width: fit-content;
    column-gap: 3rem;
}
.legend-item {
    display: grid;
    grid-template-columns: 50px 50px 1fr;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 8px 0;
    border-top: 1px solid #f0f0f0;
    font-size: 13px;
    color: #333;
    white-space: nowrap;
}
.legend-item:nth-child(-n+2) {
    border-top: none;
}
.legend-img {
    width: 50px;
    min-width: 50px;
    height: 30px;
    object-fit: contain;
    object-position: left;
}
.legend-img-wide {
    width: 50px;
    height: 30px;
}
.legend-img-placeholder {
    width: 50px;
    min-width: 50px;
    height: 30px;
}
.status {
    margin-top: 1.5rem;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #FBC52F;
    color: #1a1a1a;
    font-size: 13px;
}
.status.error {
    background: #fff;
    border-color: #FBC52F;
    color: #FBC52F;
}
#exportOutput {
    margin-top: 1.5rem;
    padding: 20px;
    background: #fff;
    border: 1px solid #e0e0e0;
}
#exportOutput h3 {
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 12px;
}
#exportOutput pre {
    background: #fafafa;
    padding: 12px;
    border: 1px solid #e0e0e0;
    overflow-x: auto;
    font-size: 12px;
}

/* Dropdown popover */
.piece-popover {
    position: absolute;
    z-index: 100;
    background: #fff;
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 180px;
    padding: 4px 0;
}
.piece-popover .popover-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
}
.piece-popover .popover-option:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}
.piece-popover .popover-option.active {
    background: #FBC52F22;
    font-weight: 600;
}
.piece-popover .popover-option img {
    width: 30px;
    height: 20px;
    object-fit: contain;
}
.piece-popover .popover-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 4px 0;
}

/* Responsive styles */
.grid-container {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 1400px) {
    .tutorial ol {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }
    h1 {
        font-size: 1.2rem;
    }
    .controls {
        flex-wrap: wrap;
    }
    button {
        padding: 8px 12px;
        font-size: 11px;
        flex: 1 1 auto;
        min-width: 80px;
    }
    .legend {
        width: 100%;
    }
    .legend-item span {
        font-size: 12px;
    }
    .legend-grid {
        grid-template-columns: 1fr;
    }
    .legend-item:nth-child(2) {
        border-top: 1px solid #f0f0f0;
    }
    #exportOutput {
        width: 100%;
    }
    #exportOutput pre {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .controls {
        gap: 5px;
    }
    button {
        padding: 6px 8px;
        font-size: 11px;
    }
    .legend-item span {
        font-size: 11px;
    }
}