* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    /* Zero scrolling */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #111;
    color: white;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: manipulation;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    /* Fit window */
    position: relative;
    background-image:
        linear-gradient(rgba(0, 102, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 102, 255, 0.07) 1px, transparent 1px);
    background-size: 50px 50px;
    padding: 20px;
}

/* Header */
.game-header {
    --gear-btn-size: clamp(35px, 7vw, 50px);
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: auto;
    /* Push to top but stay in flow */
    z-index: 80;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-wrap: nowrap;
    /* Force one line */
    gap: 10px;
}

.header-left {
    display: flex;
    gap: clamp(5px, 1.5vw, 15px);
    align-items: center;
    flex-shrink: 1;
    min-width: 0;
    /* Allow shrinking below content size */
}

.gear-btn {
    font-size: calc(var(--gear-btn-size) * 0.5);
    background: #222;
    border: 1px solid #444;
    width: var(--gear-btn-size);
    height: var(--gear-btn-size);
    border-radius: 50%;
    cursor: pointer;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    padding: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    outline: none;
    appearance: none;
    flex-shrink: 1;
}

.gear-btn:hover {
    background: #333;
    border-color: #555;
}

#settings-gear:hover {
    transform: rotate(90deg);
    border-color: #0066ff;
}

.restart-btn:hover {
    transform: rotate(-180deg);
}

.auto-btn {
    font-family: 'Inter', sans-serif;
    font-weight: 900;
}

.auto-btn.active {
    background: #00cc44;
    border-color: #fff;
    box-shadow: 0 0 15px rgba(0, 204, 68, 0.5);
}

.restart-btn {
    font-size: 2.8rem;
    line-height: 1;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.high-score-header {
    font-size: 0.8rem;
    color: #0066ff;
    font-weight: bold;
    letter-spacing: 1px;
    opacity: 0.8;
}

.score-display {
    font-size: 2.5rem;
    font-weight: bold;
    color: #eee;
}

/* Board & Pads */
.board-frame {
    width: min(80vw, 80vh);
    /* Responsive scaling */
    height: min(80vw, 80vh);
    max-width: 450px;
    max-height: 450px;
    position: relative;
    margin: auto;
    /* Center in remaining space */
    overflow: visible;
}

.simon-board {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform: rotate(var(--board-rotation, 45deg));
}

.theme-squares {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 15px;
}

.theme-modern,
.theme-original {
    display: block;
    /* Non-grid layout for SVG focus */
}

/* SVG Original Layout Styles */
.board-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

.svg-pad {
    cursor: pointer;
    transition: fill 0.1s, filter 0.2s, transform 0.1s, stroke 0.1s;
    transform-origin: center;
    stroke-width: 14;
    stroke-linejoin: round;
    stroke-linecap: round;
    paint-order: stroke fill;
}

.svg-pad:hover {
    filter: brightness(1.2);
}

.svg-pad.active {
    transform: scale(1.02);
}

.svg-pad.green {
    fill: #004400;
    stroke: #004400;
}

.svg-pad.red {
    fill: #440000;
    stroke: #440000;
}

.svg-pad.yellow {
    fill: #444400;
    stroke: #444400;
}

.svg-pad.blue {
    fill: #000044;
    stroke: #000044;
}

.svg-pad.green.active {
    fill: #00ff00;
    stroke: #00ff00;
    filter: drop-shadow(0 0 15px #00ff00);
}

.svg-pad.red.active {
    fill: #ff0000;
    stroke: #ff0000;
    filter: drop-shadow(0 0 15px #ff0000);
}

.svg-pad.yellow.active {
    fill: #ffff00;
    stroke: #ffff00;
    filter: drop-shadow(0 0 15px #ffff00);
}

.svg-pad.blue.active {
    fill: #0066ff;
    stroke: #0066ff;
    filter: drop-shadow(0 0 15px #0066ff);
}

/* Vintage "Burn-Through" Styles */
.theme-original .svg-pad.active.green {
    fill: url(#grad-green) !important;
    stroke: url(#grad-green) !important;
}

.theme-original .svg-pad.active.red {
    fill: url(#grad-red) !important;
    stroke: url(#grad-red) !important;
}

.theme-original .svg-pad.active.yellow {
    fill: url(#grad-yellow) !important;
    stroke: url(#grad-yellow) !important;
}

.theme-original .svg-pad.active.blue {
    fill: url(#grad-blue) !important;
    stroke: url(#grad-blue) !important;
}

.svg-hub {
    fill: #111;
    stroke: #222;
    stroke-width: 2;
}

.pad {
    width: 100%;
    height: 100%;
    cursor: pointer;
    transition: background-color 0.05s, transform 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pad.active {
    transform: scale(1.05);
    z-index: 2;
}

.green {
    grid-row: 1;
    grid-column: 2;
    background-color: #004400;
    border-radius: 15px 15px 2px 2px;
}

.red {
    grid-row: 2;
    grid-column: 3;
    background-color: #440000;
    border-radius: 2px 15px 15px 2px;
}

.yellow {
    grid-row: 2;
    grid-column: 1;
    background-color: #444400;
    border-radius: 15px 2px 2px 15px;
}

.blue {
    grid-row: 3;
    grid-column: 2;
    background-color: #000044;
    border-radius: 2px 2px 15px 15px;
}

.pad.green.active {
    background-color: #00ff00;
    box-shadow: 0 0 20px #00ff00;
}

.pad.red.active {
    background-color: #ff0000;
    box-shadow: 0 0 20px #ff0000;
}

.pad.yellow.active {
    background-color: #ffff00;
    box-shadow: 0 0 20px #ffff00;
}

.pad.blue.active {
    background-color: #0000ff;
    box-shadow: 0 0 20px #0000ff;
}

/* Countdown */
.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 8rem;
    font-weight: 900;
    color: #0066ff;
    z-index: 100;
    pointer-events: none;
    animation: breathe 1s ease-in-out infinite;
    text-shadow: 0 0 20px rgba(0, 102, 255, 0.5);
}

@keyframes breathe {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.5;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 1;
    }
}

/* Pattern Reveal Pane */
.reveal-pane {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    z-index: 70;
}

/* Piano Guide */
.piano-guide-container {
    --key-width: clamp(20px, 4vw, 40px);
    width: 100%;
    max-width: 650px;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #444;
    display: flex;
    justify-content: center;
    gap: 2px;
    z-index: 75;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    margin: 10px 0;
    transition: opacity 0.3s, transform 0.3s;
    overflow: hidden;
}

.piano-guide-container.hidden {
    display: none;
}

.piano-key {
    position: relative;
    width: var(--key-width);
    height: 120px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 0 0 4px 4px;
    cursor: default;
    flex-shrink: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 10px;
    color: #333;
    font-size: 0.7rem;
    font-weight: bold;
}

.piano-key.black {
    width: calc(var(--key-width) * 0.65);
    height: 70px;
    background: #222;
    color: #eee;
    z-index: 2;
    margin-left: calc(var(--key-width) * -0.325);
    margin-right: calc(var(--key-width) * -0.325);
    border-color: #000;
}

.piano-key .color-marker {
    width: clamp(8px, 1vw, 12px);
    height: clamp(8px, 1vw, 12px);
    border-radius: 50%;
    margin-bottom: 5px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

.key-label {
    white-space: nowrap;
}

@media (max-width: 450px) {
    .key-label {
        font-size: 0.5rem;
    }

    .piano-key.black .key-label {
        display: none;
        /* Hide labels on black keys if too tight */
    }
}

.piano-key.active {
    background: #eee;
    transform: translateY(2px);
}

.piano-key.black.active {
    background: #444;
}

.piano-key.highlight-green {
    background: #00ff00 !important;
    color: white !important;
}

.piano-key.highlight-red {
    background: #ff0000 !important;
    color: white !important;
}

.piano-key.highlight-yellow {
    background: #ffff00 !important;
    color: black !important;
}

.piano-key.highlight-blue {
    background: #0066ff !important;
    color: white !important;
}

.reveal-step {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    border: 2px solid #222;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    position: relative;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.reveal-step.highlight-active {
    transform: scale(1.3);
    border-color: white;
    box-shadow: 0 0 15px currentColor;
    z-index: 10;
}

.reveal-step.miss::after {
    content: '✖';
    color: white;
    font-weight: bold;
    text-shadow: 0 0 3px black;
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2%;
    /* Padding between window and content */
    z-index: 100;
    box-sizing: border-box;
    transition: background-color 0.3s, backdrop-filter 0.3s;
}

.overlay.transparent-mode {
    background-color: transparent !important;
    backdrop-filter: none !important;
}

.overlay.transparent-mode .overlay-content {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    transition: opacity 0.3s;
}

.overlay.transparent-mode .overlay-content>*:not(#rotation-group) {
    opacity: 0.05 !important;
}

.overlay.transparent-mode #rotation-group {
    opacity: 0.8 !important;
}

.overlay-content {
    background-color: #222;
    padding: 3%;
    border-radius: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2%;
    border: 1px solid #444;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    width: 65%;
    min-width: 260px;
    max-width: 380px;
    box-sizing: border-box;
}

.overlay-content h1 {
    font-size: clamp(2rem, 10vw, 4rem);
    letter-spacing: clamp(5px, 2vw, 15px);
    margin: 0;
    text-shadow: 0 0 10px rgba(0, 102, 255, 0.3);
    line-height: 1.1;
}

.overlay-content h1 span {
    display: inline-block;
    transition: transform 0.3s;
}

.overlay-content h1 span:hover {
    transform: scale(1.2) rotate(5deg);
}

.green-text {
    color: #00ff00;
}

.red-text {
    color: #ff0000;
}

.yellow-text {
    color: #ffff00;
}

.blue-text {
    color: #0066ff;
}

.replay-btn {
    width: 30px;
    height: 30px;
    background: #333;
    border: 1px solid #444;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 5px;
    transition: all 0.2s;
    font-size: 0.8rem;
}

.replay-btn:hover {
    background: #444;
    border-color: #0066ff;
    transform: scale(1.1);
}

.high-score {
    color: #0066ff;
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 2px;
}

.overlay-content.full {
    width: 65%;
    max-width: 400px;
    height: auto;
    max-height: 65vh;
    border-radius: 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(135deg, #222 0%, #1a1a1a 100%);
    overflow-y: auto;
    padding: 3%;
    box-shadow:
        0 30px 60px rgba(0, 0, 0, 0.9),
        0 0 20px rgba(0, 102, 255, 0.1);
    box-sizing: border-box;
    text-align: center;
}

.settings-header {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2%;
}

.settings-header #close-settings {
    position: absolute;
    left: 0;
    font-size: 0.8rem;
    padding: 1.5% 3%;
    white-space: nowrap;
}

.overlay-content.full h2 {
    margin: 0;
    font-size: 1.4rem;
    letter-spacing: 2px;
    color: #fff;
    text-transform: uppercase;
}

.setting-group {
    width: 90%;
    margin: 1% auto;
    text-align: left;
}

.setting-group label {
    display: block;
    margin-bottom: 1%;
    font-size: 0.8rem;
    color: #999;
}

.compact-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 1%;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 2%;
    cursor: pointer;
    user-select: none;
    margin-bottom: 1%;
}

.checkbox-label input {
    width: 16px;
    height: 16px;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 0.8vh, 10px);
}

.button-group.horizontal {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
}

.btn {
    padding: 2% 8%;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 30px;
    border: 2px solid #444;
    background: #222;
    color: white;
    transition: all 0.2s;
}

.btn:hover {
    background: #333;
    transform: scale(1.05);
}

.btn.primary {
    background: #0066ff;
    border-color: #0055dd;
    font-weight: bold;
}

.btn.success {
    background: #008800;
    border-color: #006600;
    font-weight: bold;
}

.btn.danger {
    background: #660000;
    border-color: #aa0000;
    font-size: 0.9rem;
}

.btn.small {
    padding: 8px 15px;
    font-size: 0.9rem;
    width: 100px;
}

.btn-text {
    background: none;
    border: none;
    color: #0066ff;
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: underline;
    opacity: 0.7;
    margin: 10px 0;
}

.btn-text:hover {
    opacity: 1;
}

.settings-divider {
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.05);
    margin: 10px 0;
}

.settings-subtitle {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 15px;
    letter-spacing: 2px;
}

/* Keymapping Section */
.keymapping-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 90%;
    margin: 10px auto;
    background: #1a1a1a;
    padding: 10px;
    border-radius: 15px;
}

.mini-readout {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    width: 90px;
    height: 90px;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px;
    border-radius: 8px;
}

.readout-pad {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 900;
    color: white;
    border-radius: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.readout-pad.green {
    grid-row: 1;
    grid-column: 2;
    background: #008800;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

.readout-pad.red {
    grid-row: 2;
    grid-column: 3;
    background: #880000;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.3);
}

.readout-pad.yellow {
    grid-row: 2;
    grid-column: 1;
    background: #888800;
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.3);
}

.readout-pad.blue {
    grid-row: 3;
    grid-column: 2;
    background: #000088;
    box-shadow: 0 0 10px rgba(0, 0, 255, 0.3);
}

.settings-footer {
    width: 100%;
    margin: 4% auto 0;
    display: flex;
    justify-content: space-between;
    gap: 2%;
}

.settings-footer .btn {
    flex: 1;
    font-size: 0.8rem;
    padding: 3% 0;
}

/* Mini Board for Remapping */
.mini-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 12px;
    margin: 30px auto;
    width: 210px;
    height: 210px;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 20px;
}

.mini-pad {
    width: 100%;
    height: 100%;
    border: 3px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 900;
    border-radius: 12px;
    background: #050505;
    transition: all 0.2s;
    color: white;
}

.mini-pad.green {
    grid-row: 1;
    grid-column: 2;
    border-color: #004400;
}

.mini-pad.red {
    grid-row: 2;
    grid-column: 3;
    border-color: #440000;
}

.mini-pad.yellow {
    grid-row: 2;
    grid-column: 1;
    border-color: #444400;
}

.mini-pad.blue {
    grid-row: 3;
    grid-column: 2;
    border-color: #000044;
}

.mini-pad.active {
    border-color: #fff;
    background: #222;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.hidden {
    display: none !important;
}

.disabled {
    pointer-events: none;
}

.shapes-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.shape-option.active {
    border-color: #0066ff;
    background: #001a44;
}

/* Rotation Control */
.rotation-control {
    display: flex;
    align-items: center;
    gap: 15px;
}

.rotation-control input[type="range"] {
    flex: 1;
    cursor: pointer;
}

@media (max-width: 500px) {
    .header-left {
        gap: 8px;
    }

    .gear-btn {
        width: clamp(35px, 9vw, 50px);
        height: clamp(35px, 9vw, 50px);
        font-size: clamp(1.4rem, 4vw, 2rem);
    }

    .restart-btn {
        font-size: clamp(1.8rem, 5vw, 2.8rem);
    }

    .score-display {
        font-size: clamp(1.6rem, 5vw, 2.5rem);
    }
}