html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body {
    font-family: Arial, Helvetica, "Liberation Sans", FreeSans, sans-serif;
    background-color: #fff;
    border-width: 0;
    cursor: pointer;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

input,
select,
button {
    font: inherit;
}

input {
    caret-color: auto;
    -webkit-user-select: auto;
    user-select: auto;
}

#menu {
    font-size: 15px;
    margin: 0;
    padding: 10px;
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    top: max(10px, env(safe-area-inset-top));
    width: min(350px, calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 20px));
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);
    box-sizing: border-box;
    overflow-y: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;

    background: rgba(255, 255, 248, 0.94);
    color: #1e252b;
    border: 1px solid rgba(31, 41, 55, 0.16);
    border-radius: 14px;
    box-shadow: 0 14px 34px rgba(22, 31, 43, 0.18);
    backdrop-filter: blur(14px) saturate(1.05);
    -webkit-backdrop-filter: blur(14px) saturate(1.05);
    z-index: 10;
}

#menu.hidden {
    width: auto;
}

#menu button,
#menu select,
#menu input,
#menu label,
#menu p {
    color: #1e252b;
}

#menu hr {
    border: 0;
    border-top: 1px solid rgba(31, 41, 55, 0.12);
    margin: 8px 0;
}

#menu.hidden #showhide {
    display: none;
}

#controls {
    min-height: 38px;
    margin: 0;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    letter-spacing: 0;
}

#showhide > p {
    margin: 7px 0;
}

#menu .center {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

#menu .option-row,
#menu .toggle-row,
#menu .section-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

#menu .option-row {
    justify-content: space-between;
}

#menu .toggle-row {
    justify-content: flex-start;
}

#menu .section-title {
    justify-content: space-between;
    font-weight: 700;
}

#menu button {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 15px;
    background: #f3f5f2;
    color: #1e252b;
    border: 1px solid #c6ccc4;
    border-radius: 8px;
    touch-action: manipulation;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

#menu button:hover {
    background: #e9eee9;
}

#menu button:active {
    background: #dde4df;
}

#menu select,
#menu input[type="text"],
#menu input[type="number"] {
    min-height: 40px;
    max-width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    font-size: 15px;
    background: #ffffff;
    color: #1e252b;
    border: 1px solid #c6ccc4;
    border-radius: 8px;
}

#menu select {
    min-width: 112px;
}

#menu input[type="checkbox"] {
    width: 24px;
    height: 24px;
    margin: 0;
    accent-color: #2e765f;
}

#menu .help-button {
    min-width: 34px;
    min-height: 34px;
    padding: 4px 8px;
    border-radius: 999px;
    font-weight: 700;
}

#menu button.enhanced {
    background-color: #dff8e9;
    border-color: #2e765f;
}

#menu button:disabled {
    background: #edf0ed;
    color: #9aa39b;
    border-color: #d7ddd6;
    cursor: not-allowed;
    opacity: 0.9;
}

#forPuzzle {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: #ffffdd;
    background-image:
        linear-gradient(rgba(255,255,255,0.15), rgba(255,255,255,0.15)),
        linear-gradient(rgba(255,255,255,0.15), rgba(255,255,255,0.15));
    overflow: hidden;
    touch-action: none;
}

#forPuzzle canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#forPuzzle::after {
    content: var(--guide-content, none);
    position: absolute;
    left: var(--guide-left, 20%);
    top: var(--guide-top, 20%);
    width: var(--guide-width, 60%);
    height: var(--guide-height, 60%);
    border: 2px dashed rgba(0,0,0,0.15);
    border-radius: 8px;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1;
}

.moving {
    transition-property: top, left, width, height;
    transition-duration: 1s;
}

.showimage {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    display: none;
    background-color: #ffffee99;
    touch-action: manipulation;
}

.showimage img {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    object-fit: contain;
}

dialog {
    max-width: min(520px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

dialog button {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 16px;
}

@media (pointer: coarse) {
    #menu {
        font-size: 16px;
    }

    #menu button,
    #menu select,
    #menu input[type="text"],
    #menu input[type="number"] {
        min-height: 44px;
        font-size: 16px;
    }

    #controls {
        min-height: 42px;
    }
}

@media (max-width: 768px) {
    #menu {
        left: max(10px, env(safe-area-inset-left));
        top: max(10px, env(safe-area-inset-top));
        width: min(300px, calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 20px));
        max-width: 300px;
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        border-radius: 0 0 12px 12px;
    }

    #menu.hidden {
        width: auto;
        border-radius: 0 0 12px 0;
    }
}

#forPuzzle.hide-guide::after {
    display: none !important;
}
