:root {
    --primary: #1e293b;
    --bg: #f1f5f9;
    --box-bg: #ffffff;
    --accent: #2563eb;
    --accent-glow: #38bdf8;
    --border: #cbd5e1;
    --blue: #2563eb;
    --green: #10b981;
    --purple: #8b5cf6;
    --gold: #d97706;
}

html {
    height: 100%;
    background-color: var(--bg);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--primary);
    margin: 0;
    padding: env(safe-area-inset-top, 5px) env(safe-area-inset-right, 5px) env(safe-area-inset-bottom, 10px) env(safe-area-inset-left, 5px);
    min-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 14px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 80px;
}

/* メインタブ */
.main-tabs {
    display: flex;
    overflow-x: auto;
    background: var(--box-bg);
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    padding: 0 4px;
    position: sticky;
    top: 0;
    z-index: 200;
    border-radius: 0;
    margin: 0;
}

.main-tabs::-webkit-scrollbar {
    display: none;
}

.m-tab-btn {
    flex: 1 0 auto;
    background: none;
    border: none;
    padding: 14px 12px;
    font-size: 0.92rem;
    font-weight: bold;
    color: #64748b;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
    text-align: center;
}

.m-tab-btn.active {
    color: var(--accent);
    border-bottom: 3px solid var(--accent);
}

.tab-content {
    display: none;
    padding-top: 15px;
}

.tab-content.active {
    display: block;
}

/* サブタブ */
.sub-tabs {
    display: flex;
    overflow-x: auto;
    margin-bottom: 15px;
    gap: 6px;
    scrollbar-width: none;
    position: sticky;
    top: 48px;
    z-index: 100;
    background-color: var(--bg);
    padding: 6px 0;
    transition: top 0.2s;
}

.sub-tabs::-webkit-scrollbar {
    display: none;
}

.s-tab-btn {
    background: #e2e8f0;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: #475569;
    white-space: nowrap;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.s-tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.sub-tab-content {
    display: none;
}

.sub-tab-content.active {
    display: block;
}

/* パネル */
.panel {
    background: var(--box-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.panel-title {
    font-family: "Noto Serif JP", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "HiraMinProN-W6", "HGS明朝E", "MS P明朝", serif;
    font-weight: 700;
    font-size: 1.12rem;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 6px;
    color: var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-title > span {
    display: inline-flex;
    align-items: center;
    color: var(--accent);
}

.title-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent);
    color: #ffffff !important;
    font-size: 1.15em;
    width: 1.35em;
    height: 1.35em;
    margin-right: 6px;
    border-radius: 0;
    line-height: 1;
    flex-shrink: 0;
}

/* 入力行 */
.input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.input-label {
    flex: 1;
    font-weight: bold;
    font-size: clamp(0.9rem, 3.5vw, 1.05rem);
    color: #334155;
}

.text-input {
    width: clamp(90px, 26vw, 140px);
    padding: 8px clamp(6px, 2vw, 12px);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: clamp(0.95rem, 3.5vw, 1.2rem);
    text-align: right;
    box-sizing: border-box;
    font-weight: bold;
    color: #1e293b;
    background: #f8fafc;
}

.text-input:focus {
    border-color: var(--accent);
    outline: none;
    background: #fff;
}

.text-input-wide {
    width: clamp(150px, 40vw, 220px);
    padding: 8px clamp(6px, 2vw, 12px);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: clamp(0.95rem, 3.5vw, 1.2rem);
    box-sizing: border-box;
    font-weight: bold;
}

/* カウンターグループ */
.counter-group {
    display: flex;
    align-items: center;
    gap: clamp(4px, 1.2vw, 8px);
}

.btn-calc {
    width: clamp(34px, 10vw, 48px);
    height: clamp(34px, 10vw, 48px);
    font-size: clamp(1.1rem, 4.5vw, 1.5rem);
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    flex-shrink: 0;
    box-sizing: border-box;
    font-weight: bold;
    color: #334155;
    transition: background 0.1s, transform 0.05s;
}

.btn-calc:active {
    background: #e2e8f0;
    transform: scale(0.95);
}

.counter-val {
    font-size: clamp(0.95rem, 4.2vw, 1.3rem);
    font-weight: bold;
    width: clamp(42px, 12vw, 60px);
    height: clamp(34px, 10vw, 48px);
    text-align: center;
    border: 1px solid var(--border);
    padding: 2px 1px;
    border-radius: 6px;
    background: #ffffff;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0f172a;
}

.btn-hit {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
    transition: background-color 0.2s;
}

.btn-hit:active {
    opacity: 0.9;
}

/* 判定結果ボックス */
.result-box {
    background: var(--box-bg);
    border-radius: 8px;
    padding: 20px 15px;
    text-align: center;
    border: 3px solid var(--primary);
    margin-bottom: 20px;
}

.top-setting {
    font-size: 3.2rem;
    font-weight: bold;
    line-height: 1;
    margin: 8px 0;
    color: #2d3748;
}

.top-percent {
    font-size: 1.25rem;
    font-weight: bold;
    color: #64748b;
}

.setting-rainbow {
    color: transparent !important;
    background-clip: text !important;
    -webkit-background-clip: text !important;
    background-image: linear-gradient(to right, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8b00ff, #ff0000);
    background-size: 200% auto;
    animation: textSlide 3s linear infinite;
    display: inline-block;
}

.setting-gold {
    color: transparent !important;
    background-clip: text !important;
    -webkit-background-clip: text !important;
    background-image: linear-gradient(to right, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c, #bf953f);
    background-size: 200% auto;
    animation: textSlide 3s linear infinite;
    display: inline-block;
}

.setting-red {
    color: #e53e3e !important;
}

@keyframes textSlide {
    to {
        background-position: -200% center;
    }
}

.rank-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 15px;
}

.rank-item {
    background: #f0f4f8;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: bold;
    width: calc(33% - 10px);
    text-align: center;
    box-sizing: border-box;
}

.factor-item {
    padding: 8px 6px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
}
.factor-item:last-child {
    border-bottom: none;
}

/* モーダル */
.btn-info {
    background: #e2e8f0;
    color: #475569;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin-left: auto;
    flex-shrink: 0;
    transition: background 0.2s;
}

.btn-info:active {
    background: #cbd5e1;
}

body.no-scroll {
    overflow: hidden !important;
}

@keyframes bgFadeIn {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes popupAnim {
    0% {
        transform: translateY(20px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 15px;
    animation: bgFadeIn 0.2s ease-out forwards;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: #ffffff;
    border-radius: 12px;
    max-width: 500px;
    width: 92%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    animation: popupAnim 0.25s ease-out forwards;
}

.modal-header {
    padding: 14px 18px 10px;
    border-bottom: 2px solid var(--accent);
    background: #ffffff;
    flex-shrink: 0;
}

.modal-title {
    font-family: "Noto Serif JP", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "HiraMinProN-W6", "HGS明朝E", "MS P明朝", serif;
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--accent);
    margin: 0;
    padding: 0;
    border-bottom: none;
}

.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #334155;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    flex-shrink: 0;
}

.modal-btn {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.95rem;
    cursor: pointer;
    margin: 0;
    transition: opacity 0.2s;
}

.modal-btn:active {
    opacity: 0.9;
}

/* 情報テーブル */
.info-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 0.85rem;
    text-align: center;
}

.info-table th,
.info-table td {
    border: 1px solid var(--border);
    padding: 6px 4px;
}

.info-table th {
    background: #f1f5f9;
    font-weight: bold;
    color: #334155;
}

/* キャラクター/画像グリッド */
.char-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.char-card {
    background: #ffffff;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.char-card.active-selected {
    border-color: var(--accent);
    background: #eff6ff;
}

.char-name {
    font-weight: bold;
    margin-bottom: 6px;
    color: #1e293b;
    font-size: 0.85rem;
}

.char-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    object-position: center;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    margin-bottom: 6px;
}

/* トグルスイッチ */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* セレクトボックス & ボタン */
.select-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: bold;
    background: #ffffff;
    color: #1e293b;
    outline: none;
}

.btn-action {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.95rem;
    transition: opacity 0.2s;
}

.btn-action:active {
    opacity: 0.9;
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.95rem;
}

.btn-danger:active {
    background: #dc2626;
}

.badge-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
}
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-gold { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-rainbow { background: linear-gradient(135deg, #fca5a5, #fcd34d, #86efac, #93c5fd, #d8b4fe); color: #1e293b; }
