:root {
    color-scheme: light;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #475569;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --shadow: rgba(15, 23, 42, 0.08);
    --card-shadow: rgba(14, 165, 233, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
    background: linear-gradient(180deg, rgba(240, 249, 255, 0.6) 0%, rgba(248, 250, 252, 0.9) 40%, var(--bg) 100%);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    padding: 24px 16px 40px;
}

.app-header {
    margin-bottom: 32px;
}

.header-bar {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: #64748b;
    text-decoration: none;
    border-radius: 12px;
    transition: color 0.2s ease, transform 0.2s ease;
}

.header-back-link i {
    font-size: 1.5rem;
    transition: transform 0.2s ease;
}

.header-back-link:hover,
.header-back-link:focus-visible {
    color: #0f172a;
    transform: translateX(-4px);
    outline: none;
}

.header-back-link:hover i,
.header-back-link:focus-visible i {
    transform: translateX(-2px);
}

.header-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.35);
    flex-shrink: 0;
}

.header-icon-badge i {
    font-size: 1.5rem;
}

.header-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-title {
    margin: 0;
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    font-weight: 700;
    color: var(--text);
}

.app-description {
    margin: 0;
    font-size: 0.95rem;
    color: var(--muted);
}

@media (max-width: 640px) {
    .header-bar {
        gap: 12px;
    }

    .header-back-link {
        width: 40px;
        height: 40px;
    }

    .header-icon-badge {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }
}

.app-main {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

@media (min-width: 960px) {
    .app-main {
        grid-template-columns: minmax(320px, 360px) 1fr;
        align-items: start;
    }
}

.app-footer {
    max-width: 1100px;
    margin: 28px auto 0;
    text-align: center;
    color: var(--muted);
}

.app-footer__inner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.language-selector {
    padding: 10px 18px;
    border-radius: 999px;
    border: 2px solid var(--border);
    background-color: var(--surface);
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.language-selector:focus,
.language-selector:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.25);
    color: var(--text);
}

.language-selector:hover {
    border-color: var(--accent);
    color: var(--text);
}

.settings-section,
.results-section {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 12px 28px var(--shadow);
}

.section-title {
    margin: 0 0 12px;
    font-size: 1.25rem;
}

.section-description {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 0.95rem;
}

.mode-options {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
}

.mode-card {
    display: flex;
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    background: rgba(255, 255, 255, 0.95);
}

.mode-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
}

.mode-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode-content {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.mode-heading {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mode-label {
    font-weight: 700;
    font-size: 1rem;
}

.mode-sub {
    color: var(--muted);
    font-size: 0.85rem;
}

.mode-inputs {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    min-width: 112px;
}

.mode-inputs label {
    font-size: 0.85rem;
    color: var(--muted);
}

.mode-inputs input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    border: 2px solid var(--border);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mode-inputs input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.mode-card.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.mode-card.is-inactive {
    opacity: 0.45;
}

.mode-card.is-inactive .mode-inputs input {
    pointer-events: none;
}

.class-size {
    margin: 20px 0 24px;
    display: grid;
    gap: 8px;
}

.class-size__label {
    font-weight: 700;
    font-size: 1.05rem;
}

.class-size__control {
    display: grid;
    gap: 8px;
    align-items: flex-start;
}

.class-size__control input {
    width: 140px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 2px solid var(--border);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.class-size__control input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    margin-top: 24px;
}

.action-buttons button {
    flex: 0 0 auto;
    padding: 11px 16px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.15s ease;
}

.action-buttons button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: none;
}

.action-buttons .primary {
    background: var(--accent-strong);
    color: #fff;
    box-shadow: 0 12px 24px rgba(14, 165, 233, 0.35);
}

.action-buttons .primary:hover:not(:disabled),
.action-buttons .primary:focus-visible {
    background: #0284c7;
    box-shadow: 0 16px 32px rgba(14, 165, 233, 0.35);
    outline: none;
}

.results-section {
    max-width: 1100px;
    margin: 24px 0 0;
}

@media (min-width: 960px) {
    .results-section {
        max-width: none;
        margin: 0;
    }
}

.results-placeholder {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}


.teams-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    column-gap: 16px;
    row-gap: 28px;
    margin-top: 24px;
    padding-bottom: 8px;
}

.team-card {
    background: var(--surface);
    border-radius: 14px;
    padding: 30px 14px 16px;
    position: relative;
    min-height: 112px;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.35);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.team-card.drag-target {
    border-color: var(--accent-strong);
    box-shadow: 0 14px 32px var(--card-shadow);
}

.team-badge {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.35);
}

.team-title {
    margin: 0;
}

.team-seats {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 6px;
    padding: 6px;
    border-radius: 12px;
    border: 1px dashed transparent;
    min-height: 48px;
}

.team-seats.is-empty {
    border-color: rgba(148, 163, 184, 0.6);
    display: grid;
    place-items: center;
}

.team-seats.is-empty::after {
    content: attr(data-empty-label);
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 8px 4px;
    pointer-events: none;
}

.team-seat {
    background: #eff6ff;
    border: 1px solid rgba(148, 163, 184, 0.6);
    border-radius: 10px;
    font-weight: 600;
    text-align: center;
    padding: 6px 4px;
    cursor: grab;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
}

.team-seat:hover {
    border-color: rgba(56, 189, 248, 0.6);
}

.team-seat:active {
    cursor: grabbing;
    transform: scale(0.98);
    box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.team-seat.is-dragging {
    opacity: 0.6;
}

.visually-hidden {
    position: absolute;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
    white-space: nowrap;
}

@media (max-width: 599px) {
    body {
        padding: 16px 12px 32px;
    }

    .settings-section,
    .results-section {
        padding: 20px;
    }

    .mode-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .mode-inputs {
        width: 100%;
    }

    .mode-inputs input {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
    }

    .class-size__control input {
        width: 100%;
    }
}
