:root {
    --piece: 44px;
    --piece-gap: 4px;
    --accent: #3b5bdb;
}

@media (max-width: 576px) {
    :root {
        --piece: 34px;
        --piece-gap: 3px;
    }
}

body {
    background: #f4f5f9;
    color: #222;
}

.header {
    background: linear-gradient(90deg, #3b5bdb, #9c36b5);
    color: #fff;
}

.timer {
    font-variant-numeric: tabular-nums;
    color: #555;
    min-width: 5em;
}

/* ---------- ピース ---------- */
.piece {
    width: var(--piece);
    height: var(--piece);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: #fffdf5;
    border: 1px solid #c9bf9f;
    border-radius: 6px;
    box-shadow: 0 2px 0 #c9bf9f, 0 3px 6px rgba(0, 0, 0, .12);
    font-weight: 700;
    font-size: calc(var(--piece) * 0.52);
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    cursor: grab;
}

.free-area .piece {
    position: absolute;
}

.piece.dragging {
    position: fixed;
    z-index: 1000;
    cursor: grabbing;
    transform: scale(1.12);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .25);
    pointer-events: none;
}

.piece.placeholder {
    background: rgba(59, 91, 219, .08);
    border: 2px dashed var(--accent);
    box-shadow: none;
}

.locked .piece {
    cursor: default;
}

/* ---------- 回答欄 ---------- */
.answer-line {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
}

.answer-label {
    flex: 0 0 auto;
    width: 2em;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
    border-radius: 6px;
}

.answer-row {
    flex: 1 1 auto;
    min-width: 0;
    min-height: calc(var(--piece) + 18px);
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: var(--piece-gap);
    background:
        linear-gradient(to bottom, transparent calc(100% - 6px), rgba(59, 91, 219, .25) calc(100% - 6px));
    background-color: #fff;
    border: 2px solid #d5daf0;
    border-radius: 8px;
    transition: border-color .15s, background-color .15s;
}

.answer-row.over {
    border-color: var(--accent);
    background-color: #f1f4ff;
}

.answer-row.correct {
    border-color: #2f9e44;
    background-color: #ebfbee;
}

.answer-row.wrong {
    border-color: #e03131;
    background-color: #fff5f5;
}

/* ---------- フリースペース ---------- */
.free-area {
    position: relative;
    height: 280px;
    background-color: #fff;
    background-image: radial-gradient(#dde 1px, transparent 1px);
    background-size: 16px 16px;
    border: 2px dashed #c8cbe0;
    border-radius: 10px;
    overflow: hidden;
}

.free-hint {
    position: absolute;
    inset: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    text-align: center;
    color: #999;
}

/* ---------- 結果 ---------- */
.result {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.result .score {
    font-size: 2.6rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1.1;
}

.result table {
    font-size: .95rem;
}

.result .diff-ok {
    color: #2f9e44;
    font-weight: 700;
}

.result .diff-ng {
    color: #e03131;
    font-weight: 700;
}

/* ---------- 入力画面 ---------- */
.setup-form {
    max-width: 480px;
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.setup-line {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
}

.setup-form.shake {
    animation: shake .35s;
}

@keyframes shake {
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* 長いタイトル（英字が続く場合も）で表がはみ出さないよう折り返す */
.result td {
    word-break: break-all;
}
