:root {
    --primary: #333333;
    --bg: #f4f5f7;
    --box-bg: #ffffff;
    --accent: #d52b4c;
    --border: #e2e8f0;
    --blue: #3182ce;
    --green: #38a169;
}

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;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    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: #666666;
    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: 5px;
    scrollbar-width: none;
    position: sticky;
    top: 48px;
    z-index: 100;
    background-color: var(--bg);
    padding: 5px 0;
    transition: top 0.2s;
}

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

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

.s-tab-btn.active,
.sub-tab-btn.active {
    background: var(--primary);
    color: #fff;
}

.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.08);
}

.panel-title {
    font-weight: bold;
    font-size: 1.05rem;
    margin-bottom: 12px;
    border-bottom: 2px solid #eee;
    padding-bottom: 6px;
    color: #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.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.15rem);
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.bb-icon {
    height: 24px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
}

.text-input {
    width: clamp(80px, 25vw, 130px);
    padding: 7px clamp(6px, 2vw, 12px);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: clamp(0.95rem, 3.5vw, 1.25rem);
    text-align: right;
    box-sizing: border-box;
}

.counter-group {
    display: flex;
    align-items: center;
    gap: clamp(3px, 1.2vw, 8px);
}

.btn-calc {
    width: clamp(32px, 10vw, 52px);
    height: clamp(32px, 10vw, 52px);
    font-size: clamp(1.05rem, 4.5vw, 1.6rem);
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    flex-shrink: 0;
    box-sizing: border-box;
}

.btn-calc:active {
    background: #eee;
}

.btn-quick {
    min-width: clamp(44px, 14vw, 72px);
    height: clamp(32px, 10vw, 52px);
    padding: 0 clamp(4px, 1.5vw, 10px);
    font-size: clamp(0.8rem, 3.2vw, 1.1rem);
    font-weight: bold;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    color: #444;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
    box-sizing: border-box;
}

.btn-quick:active {
    background: #eee;
}

.counter-val {
    font-size: clamp(0.95rem, 4.2vw, 1.4rem);
    font-weight: bold;
    width: clamp(38px, 12vw, 64px);
    height: clamp(32px, 10vw, 52px);
    text-align: center;
    border: 1px solid #eee;
    padding: 2px 1px;
    border-radius: 4px;
    background: #fafafa;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.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;
}

.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;
}

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

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

.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;
}

/* 解析リンクカード */
.ichigeki-card {
    background: var(--box-bg);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.ichigeki-btn {
    display: inline-block;
    background: #e60012;
    color: #fff;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1rem;
    padding: 14px 24px;
    border-radius: 8px;
    margin-top: 15px;
    box-shadow: 0 4px 6px rgba(230, 0, 18, 0.25);
    transition: transform 0.15s, background-color 0.15s;
}

.ichigeki-btn:hover {
    background: #cc0010;
    transform: translateY(-1px);
}

/* モーダル */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 15px;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    max-width: 480px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.btn-info {
    background: #cbd5e0;
    color: #2d3748;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

textarea.memo-box {
    width: 100%;
    height: 150px;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    box-sizing: border-box;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    margin-bottom: 10px;
    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: #f0f4f8;
    font-weight: bold;
    color: #334155;
}

.hint-image-cell { width: 105px; padding: 6px 2px !important; }
.hint-image-cell img { width: 75px; height: 45px; object-fit: cover; border-radius: 4px; border: 1px solid #cbd5e0; display: block; margin: 0 auto 4px; }
.hint-image-cell b { display: block; line-height: 1.2; }
.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; }

@media (max-width: 480px) {
    .panel {
        padding: 12px 10px;
    }
}
