* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
    background: linear-gradient(135deg, #5f3dc4 0%, #845ef7 48%, #339af0 100%);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100vw;
    height: 100vh;
    padding: 2.5vh 4vw;
    gap: 1vh;
}

.game-title {
    color: #fff;
    font-size: clamp(22px, 7vw, 36px);
    line-height: 1.15;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.mode-panel {
    display: flex;
    gap: 2vw;
    padding: 1vw;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.mode-btn {
    min-width: clamp(86px, 26vw, 128px);
    padding: 2vw 4vw;
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-size: clamp(14px, 4vw, 18px);
    font-weight: 800;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.25s ease;
}

.mode-btn.active {
    color: #5f3dc4;
    background: #fff;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.progress {
    font-size: clamp(13px, 3.8vw, 18px);
    color: #fff;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.8vw 3vw;
    border-radius: 12px;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
}

.grid-wrapper {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 20px;
    padding: clamp(10px, 2.8vw, 18px);
    box-shadow: 0 12px 45px rgba(0, 0, 0, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.85);
    touch-action: none;
}

.grid-container {
    --grid-size: 4;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--grid-size), 1fr);
    gap: clamp(5px, 1.6vw, 10px);
    width: min(84vw, 430px);
    height: min(84vw, 430px);
    touch-action: none;
}

.grid-container.size-6 {
    width: min(88vw, 480px);
    height: min(88vw, 480px);
    gap: clamp(4px, 1.1vw, 8px);
}

.grid-cell {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: clamp(8px, 2.5vw, 14px);
    border: 2px solid #e9ecef;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    color: #343a40;
    font-size: clamp(18px, 6vw, 34px);
    font-weight: 900;
    user-select: none;
    touch-action: none;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
    transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}

.size-6 .grid-cell {
    font-size: clamp(15px, 4.6vw, 27px);
    border-width: 1.5px;
}

.grid-cell.selected {
    color: #fff;
    border-color: #ff922b;
    background: linear-gradient(135deg, #ff922b 0%, #fcc419 100%);
    box-shadow: 0 0 0 4px rgba(255, 146, 43, 0.18), 0 8px 18px rgba(255, 146, 43, 0.3);
    transform: scale(1.06);
}

.grid-cell.completed {
    color: #fff;
    animation: completePop 0.42s ease-out;
}

.grid-cell.completed-color-0,
.answer-item.done.completed-color-0 {
    border-color: #12b886;
    background: linear-gradient(135deg, #12b886 0%, #40c057 100%);
    box-shadow: 0 0 18px rgba(18, 184, 134, 0.42);
}

.grid-cell.completed-color-1,
.answer-item.done.completed-color-1 {
    border-color: #f76707;
    background: linear-gradient(135deg, #ff922b 0%, #f76707 100%);
    box-shadow: 0 0 18px rgba(247, 103, 7, 0.42);
}

.grid-cell.completed-color-2,
.answer-item.done.completed-color-2 {
    border-color: #7048e8;
    background: linear-gradient(135deg, #9775fa 0%, #7048e8 100%);
    box-shadow: 0 0 18px rgba(112, 72, 232, 0.42);
}

.grid-cell.completed-color-3,
.answer-item.done.completed-color-3 {
    border-color: #1c7ed6;
    background: linear-gradient(135deg, #4dabf7 0%, #1c7ed6 100%);
    box-shadow: 0 0 18px rgba(28, 126, 214, 0.42);
}

.grid-cell.completed-color-4,
.answer-item.done.completed-color-4 {
    border-color: #d6336c;
    background: linear-gradient(135deg, #f06595 0%, #d6336c 100%);
    box-shadow: 0 0 18px rgba(214, 51, 108, 0.42);
}

.grid-cell.completed-color-5,
.answer-item.done.completed-color-5 {
    border-color: #099268;
    background: linear-gradient(135deg, #20c997 0%, #099268 100%);
    box-shadow: 0 0 18px rgba(9, 146, 104, 0.42);
}

.grid-cell.completed-color-6,
.answer-item.done.completed-color-6 {
    border-color: #e67700;
    background: linear-gradient(135deg, #ffd43b 0%, #e67700 100%);
    box-shadow: 0 0 18px rgba(230, 119, 0, 0.42);
}

.grid-cell.completed-color-7,
.answer-item.done.completed-color-7 {
    border-color: #0b7285;
    background: linear-gradient(135deg, #22b8cf 0%, #0b7285 100%);
    box-shadow: 0 0 18px rgba(11, 114, 133, 0.42);
}

.grid-cell.completed-color-8,
.answer-item.done.completed-color-8 {
    border-color: #c92a2a;
    background: linear-gradient(135deg, #ff6b6b 0%, #c92a2a 100%);
    box-shadow: 0 0 18px rgba(201, 42, 42, 0.42);
}

.grid-cell.empty {
    color: transparent;
    background: rgba(248, 249, 250, 0.5);
}

.path-line-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.path-line {
    fill: none;
    stroke: #ffd43b;
    stroke-width: 4.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 8px rgba(255, 212, 59, 0.78));
    stroke-dasharray: 170;
    stroke-dashoffset: 170;
    animation: drawPathLine 0.46s ease-out forwards;
}

.size-6 .path-line {
    stroke-width: 3.8;
}

.answer-panel {
    width: min(92vw, 520px);
    max-height: 15vh;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.93);
    border-radius: 16px;
    padding: 1.5vh 3vw;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.12);
}

.answer-title {
    color: #5f3dc4;
    font-size: clamp(13px, 3.6vw, 16px);
    font-weight: 800;
    text-align: center;
    margin-bottom: 0.8vh;
}

.answer-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1vw 2vw;
}

.answer-item {
    min-width: clamp(62px, 18vw, 86px);
    text-align: center;
    padding: 0.7vw 1.8vw;
    border-radius: 999px;
    color: #868e96;
    background: #f1f3f5;
    font-size: clamp(12px, 3.5vw, 15px);
    font-weight: 800;
}

.answer-item.done {
    color: #fff;
}

.controls {
    display: flex;
    gap: 3vw;
}

.btn {
    padding: 2.4vw 5vw;
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-size: clamp(14px, 4vw, 18px);
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.16);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.btn:active {
    transform: scale(0.96);
}

.btn.clear {
    background: linear-gradient(135deg, #ff922b 0%, #f76707 100%);
}

.btn.reset {
    background: linear-gradient(135deg, #4dabf7 0%, #1c7ed6 100%);
}

.message {
    min-height: 2.2em;
    max-width: 92vw;
    padding: 0.8vw 3vw;
    border-radius: 12px;
    color: #fff;
    background: rgba(0, 0, 0, 0.12);
    font-size: clamp(13px, 3.8vw, 17px);
    line-height: 1.35;
    text-align: center;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.22);
}

.message.success {
    font-size: clamp(15px, 4.2vw, 20px);
    font-weight: 900;
    background: rgba(18, 184, 134, 0.35);
    animation: pulse 1.15s infinite;
}

@keyframes completePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes drawPathLine {
    from { stroke-dashoffset: 170; }
    to { stroke-dashoffset: 0; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.035); }
}

@media (max-height: 720px) {
    .game-container {
        padding-top: 1.5vh;
        padding-bottom: 1.5vh;
        gap: 0.6vh;
    }

    .answer-panel {
        max-height: 13vh;
        padding-top: 1vh;
        padding-bottom: 1vh;
    }

    .grid-container {
        width: min(76vw, 380px);
        height: min(76vw, 380px);
    }

    .grid-container.size-6 {
        width: min(82vw, 420px);
        height: min(82vw, 420px);
    }
}
