#play-menu-dialog,
#clear-result-dialog {
    width: min(24rem, calc(100% - 2rem));
}

.play-menu-actions {
    display: grid;
    gap: 0.5rem;
    margin-block-start: 0.75rem;
}

#clear-mosaic-downloads {
    margin-block-start: 0;
}

.play-menu-actions .action-link:not([hidden]) {
    justify-content: flex-start;
}

dialog {
    box-sizing: border-box;
    width: min(34rem, calc(100% - 2rem));
    max-height: calc(100% - 2rem);
    padding: 1rem;
    border: 1px solid var(--puzzle-major-rule);
    border-radius: var(--ui-corner);
    background: var(--puzzle-paper);
    color: var(--puzzle-ink);
}

dialog::backdrop {
    background: rgb(32 32 31 / 50%);
}

dialog button:focus-visible {
    outline-color: var(--puzzle-accent);
}

.dialog-heading,
#restart-dialog h2 {
    padding-block-end: 0.6rem;
    border-bottom: 1px solid var(--puzzle-rule);
}

#prepare-puzzle {
    width: fit-content;
    min-width: min(18rem, calc(100% - 2rem));
}

#prepare-puzzle-message {
    margin: 0;
}

.action-link.action-danger {
    border-color: #a32727;
    background: #a32727;
    color: #fff;
}

.action-link.action-danger:hover,
.action-link.action-danger:active {
    border-color: #7e1919;
    background: #7e1919;
}

#restart-dialog {
    width: min(25rem, calc(100% - 2rem));
}

.restart-actions {
    justify-content: flex-end;
}

.dialog-heading h2,
#restart-dialog h2 {
    margin: 0;
    font-size: 1.25rem;
}

#settings-dialog > fieldset {
    margin: 0.75rem 0 0;
    padding: 0.25rem 0.65rem;
    border: 1px solid var(--puzzle-rule);
    border-radius: 0.25rem;
}

#settings-dialog input {
    accent-color: var(--puzzle-accent);
}

#settings-dialog label {
    display: flex;
    align-items: center;
    min-height: 44px;
    gap: 0.5rem;
}

#settings-dialog .settings-options {
    margin: 0.25rem 0;
    padding: 0 0.5rem;
    border: 1px solid var(--puzzle-rule);
    border-radius: 0.25rem;
}

.settings-options > div {
    display: flex;
    flex-wrap: wrap;
    column-gap: 1rem;
}

.settings-options input:focus-visible {
    outline: 2px solid var(--puzzle-accent);
    outline-offset: 2px;
}

.settings-options .sound-choices {
    column-gap: 0.625rem;
}

#settings-dialog .sound-choices label {
    gap: 0.25rem;
}

.settings-options .sound-previews {
    gap: 0.4rem;
    padding-block-end: 0.5rem;
}

#play-guide-dialog p {
    margin: 0.5rem 0;
}

.guide-more {
    margin-top: 0.75rem;
}

.guide-example {
    --example-cell: 1.75rem;
    border-collapse: collapse;
}

.guide-clues {
    display: inline-flex;
    vertical-align: middle;
    font-size: 0.8125rem;
}

.guide-example th {
    padding: 0;
    text-align: right;
    white-space: nowrap;
}

.guide-example td {
    box-sizing: border-box;
    width: var(--example-cell);
    height: var(--example-cell);
    border: 1px solid var(--puzzle-rule);
    background: #fff;
    color: var(--puzzle-ink);
    text-align: center;
}

.guide-example .guide-filled {
    background: var(--puzzle-accent);
    border-color: var(--puzzle-rule);
}

.guide-more summary {
    padding-block: 0.65rem;
    cursor: pointer;
}

/* Keep the rule examples distinct from the puzzle's own palette. */
.guide-color-example .guide-color-a {
    background: var(--ui-accent);
    color: #fff;
}

.guide-color-example .guide-color-b {
    background: #e8c36d;
    color: var(--ui-ink);
}

/* The guide keeps navigation visible while only its text scrolls. */
#play-guide-dialog[open] {
    height: min(38rem, calc(100dvh - 2rem));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#play-guide-dialog .dialog-heading,
.guide-tabs {
    flex: 0 0 auto;
}

#play-guide-title {
    font-size: 1.5rem;
    margin: 0;
}

.guide-tabs {
    margin-block-start: 0.5rem;
}

.guide-tabs [role="tab"] {
    flex: 1;
    min-width: 0;
}

.guide-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-inline-end: 0.25rem;
    line-height: 1.65;
}

#play-guide-dialog h3 {
    font-size: 1.125rem;
    margin: 0.75rem 0 0.5rem;
}

#play-guide-dialog summary {
    font-weight: 700;
}

#play-guide-dialog [role="tabpanel"]:focus-visible {
    outline: 2px solid var(--puzzle-accent);
    outline-offset: -2px;
}

#paint-feedback-note {
    margin: 0.25rem 0 0;
    font-size: 0.8125rem;
}

.guide-keyboard {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.guide-keyboard th,
.guide-keyboard td {
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--puzzle-rule);
    text-align: start;
}

.guide-keyboard tbody th {
    font-weight: 400;
}

#keyboard-instructions kbd {
    display: inline-block;
    padding: 0 0.25rem;
    border: 1px solid #bdc2c7;
    border-radius: 0.2rem;
    background: #edf0f2;
    color: #203751;
    font-family: ui-monospace, "Menlo", monospace;
    font-size: 0.8125rem;
    white-space: nowrap;
}

#image-crop-stage {
    position: relative;
    overflow: hidden;
    margin-inline: auto;
    outline: 1px solid var(--puzzle-rule);
    background: var(--ui-subtle);
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

#image-crop-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#image-crop-selection {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--puzzle-accent);
    outline: 1px solid var(--puzzle-paper);
    box-shadow: 0 0 0 100vmax rgb(32 32 31 / 50%);
    pointer-events: none;
}

.image-crop-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(5rem, 1fr));
    gap: 0.5rem;
    margin-block: 0.85rem;
}

.image-crop-fields label,
.image-crop-fields input {
    display: block;
}

.image-crop-fields input {
    box-sizing: border-box;
    width: 100%;
    margin-block-start: 0.25rem;
    border-radius: var(--ui-corner);
}
