/* 紅月之森主題：深紅、橘暈光、夜空紫；以系統字型減少 FOIT */
:root {
    --rmj-bg: #1b0f1a;
    --rmj-panel: #251525;
    --rmj-panel-2: #2d1a2c;
    --rmj-text: #f6e9ff;
    --rmj-soft: #d8c1e6;
    --rmj-accent: #ff6b6b;
    --rmj-accent-2: #ffb36b;
    --rmj-border: #3a203a;
    --rmj-green: #9df0a6;
    --rmj-yellow: #ffe28a;
    --w: 1200px;
}

* {
    box-sizing: border-box
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--rmj-bg);
    color: var(--rmj-text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
    line-height: 1.6
}

img {
    max-width: 100%;
    height: auto
}

/* 容器與標題 */
.rmj-container {
    max-width: var(--w);
    width: calc(100% - 32px);
    margin: 24px auto 64px
}

.rmj-title {
    margin: 8px 0 4px;
    font-size: clamp(24px, 3vw, 32px);
    letter-spacing: .02em;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px
}

.rmj-title .help-btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px
}

/* Summary */
.rmj-summary {
    display: grid;
    gap: 12px;
    margin: 12px 0 20px;
    grid-template-columns: repeat(4, minmax(0, 1fr))
}

.sum-item {
    display: grid;
    place-items: center;
    gap: 4px;
    min-height: 80px;
    padding: 12px;
    background: #201225;
    border: 1px solid var(--rmj-border);
    border-radius: 14px
}

.sum-item .label {
    display: block;
    font-size: 18px;
    color: var(--rmj-soft)
}

.sum-item .value {
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 22px;
    margin-top: 2px;
    color: #fff;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(255, 179, 107, .18)
}

.sum-item.big {
    grid-column: 1 / -1
}

/* 雙欄 */
.rmj-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px
}

@media (max-width:1000px) {
    .rmj-grid {
        grid-template-columns: 1fr
    }
}

/* 面板 */
.panel {
    background: linear-gradient(180deg, var(--rmj-panel), var(--rmj-panel-2));
    border: 1px solid var(--rmj-border);
    border-radius: 16px;
    overflow: hidden;
    min-height: 520px
}

.panel-title {
    margin: 0;
    padding: 14px 16px;
    font-size: 18px;
    background: rgba(255, 107, 107, .08);
    border-bottom: 1px solid var(--rmj-border)
}

.panel-body {
    padding: 14px 16px 16px
}

/* 提示與統計 */
.statline {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 6px 0 8px
}

@media (max-width:700px) {
    .statline {
        grid-template-columns: 1fr
    }
}

.hint {
    font-size: 12px;
    color: var(--rmj-soft);
    margin: 8px 0 0
}

.totals {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #1a131f;
    border: 1px solid var(--rmj-border)
}

.panel[aria-labelledby="grind-title"] .totals {
    background: #14211d;
    border-color: #2a5a44
}

.panel[aria-labelledby="proc-title"] .totals {
    background: #281616;
    border-color: #5a2a2a
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace
}

/* 控制列與表單 */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 12px 0 8px
}

.controls .inline {
    display: flex;
    gap: 6px;
    align-items: center
}

input[type="number"] {
    width: 110px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--rmj-border);
    background: #180e19;
    color: var(--rmj-text)
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0
}

input[type=number] {
    -moz-appearance: textfield
}

.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 10px 14px;
    background: linear-gradient(180deg, #ff7c66, #c94c3c);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    letter-spacing: .02em;
    box-shadow: 0 8px 24px rgba(255, 123, 102, .18), inset 0 1px 0 rgba(255, 255, 255, .2)
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed
}

.btn.ghost {
    background: transparent;
    color: #ffd0c5;
    border-color: #b5604f
}

#grindTarget,
#procTarget,
#resetStage,
#btnGrindAuto,
#btnResetGrind,
#btnResetAll {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 8px
}

.controls .inline label {
    font-size: 12px
}

/* 成功高光 */
.glowable.success {
    box-shadow: 0 0 0 2px rgba(255, 179, 107, .35), 0 0 40px rgba(255, 179, 107, .25);
    transition: box-shadow .5s ease
}

/* 重洗列 */
.reset-line {
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    gap: 8px;
    align-items: center;
    margin-top: 8px
}

.reset-line label {
    white-space: nowrap
}

.reset-line select {
    width: auto;
    min-width: 140px
}

.reset-line .btn {
    justify-self: end
}

@media (max-width:700px) {
    .reset-line {
        grid-template-columns: 1fr 1fr;
        grid-auto-rows: minmax(36px, auto)
    }

    .reset-line .btn {
        grid-column: 1 / -1;
        justify-self: stretch
    }
}

/* 等級／研磨主屬／加工等級 */
.levels-board {
    width: 100%;
    max-width: var(--w);
    margin: 10px auto 14px;
    padding: 8px 10px;
    background: var(--rmj-panel);
    border: 1px solid var(--rmj-border);
    border-radius: 12px
}

.levels-row {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 8px;
    align-items: start;
    margin: 6px 0
}

.levels-row .label {
    font-weight: 700;
    color: var(--rmj-soft);
    text-align: right;
    padding-right: 6px
}

.cells-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px
}

.levels-row.proc .cells-group {
    grid-template-columns: 1fr;
    row-gap: 6px
}

.levels-row.proc .cells-group>.cells+.cells {
    margin-top: 4px
}

/* 單一容器的 10 格（合併重複規則） */
.cells {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 6px;
    overflow: visible
}

.cell {
    display: grid;
    place-items: center;
    min-height: 30px;
    border: 1px solid var(--rmj-border);
    border-radius: 8px;
    background: #1a131f;
    color: #d9c5e6;
    font: 500 18px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    padding: 2px 4px;
    white-space: nowrap
}

.cell.on {
    color: #fff;
    border-color: #ffb36b;
    box-shadow: 0 0 0 1px rgba(255, 179, 107, .22)
}

.cell.current {
    outline: none;
    box-shadow: 0 0 0 2px var(--rmj-accent-2), 0 0 0 4px rgba(255, 179, 107, .18) inset;
    z-index: 1
}

.cell.done {
    background: #203222;
    border-color: #2b5a33;
    color: var(--rmj-green)
}

/* 手機：精簡列 */
.levels-mobile {
    display: none;
    margin-top: 6px;
    gap: 8px
}

.mobile-chip {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--rmj-border);
    border-radius: 10px;
    padding: 6px 10px;
    background: #1e1120
}

.mobile-chip b {
    font: 700 16px ui-monospace
}

.mobile-chip i {
    font-style: normal;
    color: var(--rmj-green)
}

@media (max-width:800px) {
    .levels-board .levels-row {
        display: none
    }

    .levels-mobile {
        display: flex
    }
}

/* 橫向機率表（thead 僅 >1000px 顯示） */
.prob-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0
}

.prob-table thead {
    display: none
}

@media (min-width:1000px) {
    .prob-table thead {
        display: table-header-group
    }
}

.prob-table tbody {
    display: block
}

.prob-table tr {
    display: grid;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
    grid-template-columns: 92px repeat(4, 1fr)
}

/* 預設四欄（研磨） */
#grindOptions tr {
    grid-template-columns: 92px repeat(4, 1fr)
}

#procOptions tr {
    grid-template-columns: 92px repeat(3, 1fr)
}

.prob-table td {
    border: 0;
    padding: 6px 8px;
    background: #1e1120;
    border: 1px solid var(--rmj-border);
    border-radius: 8px;
    text-align: center
}

.prob-table td:first-child {
    background: transparent;
    border-color: transparent;
    text-align: left;
    padding-left: 0;
    color: #ffd1d1;
    font-weight: 600
}

.prob-table .pct {
    color: var(--rmj-yellow)
}

/* 使用教學摺疊 */
.usage-help {
    margin: 10px auto 14px;
    max-width: var(--w);
    background: var(--rmj-panel);
    border: 1px solid var(--rmj-border);
    border-radius: 12px;
    padding: 12px 14px;
    transition: max-height .25s ease, opacity .2s ease;
    overflow: hidden
}

.usage-help[hidden] {
    display: block;
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0
}

.usage-help:not([hidden]) {
    max-height: 480px;
    opacity: 1
}

/* 手機板隱藏類別（由 JS 標記） */
@media (max-width:800px) {
    .mobile-hide {
        display: none !important
    }
}

/* 行動版合併面板 */
#mobileCombined {
    display: none
}

#mobileCombined .combined-wrap {
    display: grid;
    gap: 12px
}

#mobileCombined .subpanel {
    padding: 10px 0 0;
    border-top: 1px dashed var(--rmj-border)
}

#mobileCombined .subpanel:first-child {
    padding-top: 0;
    border-top: 0
}

#mobileCombined .subpanel-title {
    margin: 0 0 8px;
    font-size: 15px;
    color: var(--rmj-soft)
}

@media (max-width:800px) {
    .rmj-grid {
        display: none !important
    }

    #mobileCombined {
        display: block
    }

    #mobileCombined .controls {
        gap: 8px
    }

    #mobileCombined .controls .inline {
        flex-wrap: wrap
    }

    #mobileCombined .prob-table tr {
        margin: 6px 0
    }

    #mobileCombined .totals {
        margin-top: 10px
    }
}

/* 手機優化：縮內距與按鈕排版 */
@media (max-width:800px) {
    .panel {
        min-height: auto
    }

    .panel-title {
        padding: 10px 12px;
        font-size: 16px
    }

    .panel-body {
        padding: 10px 12px 12px
    }

    .sum-item {
        min-height: 56px;
        padding: 8px
    }

    .sum-item .value {
        font-size: 18px
    }

    .controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 10px 0 6px
    }

    .controls .inline {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: auto 1fr auto;
        gap: 6px
    }

    .controls .inline label {
        font-size: 12px;
        white-space: nowrap
    }

    .controls .inline input[type="number"] {
        width: 100%;
        padding: 6px 8px;
        border-radius: 8px
    }

    .btn {
        padding: 8px 10px;
        border-radius: 10px;
        font-size: 14px
    }

    #btnGrindOnce,
    #btnProcOnce,
    #btnGrindAuto,
    #btnProcAuto {
        width: 100%
    }

    .reset-line {
        grid-template-columns: 1fr 1fr;
        gap: 6px
    }

    .reset-line select {
        min-width: 0
    }

    .reset-line .btn {
        grid-column: 1 / -1;
        justify-self: stretch
    }

    .levels-board {
        padding: 8px
    }

    .levels-mobile {
        display: flex;
        gap: 6px
    }

    .sum-item .label {
        font-size: 14px;
    }
}

/* 桌機：重置列按鈕靠左（與上方對齊） */
@media (min-width:701px) {
    .reset-line {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 8px
    }

    .reset-line .btn {
        margin-left: 0
    }
}



/* 廣告區 */
.ad {
    position: relative;
    top: -30px;
    width: min(970px, calc(100vw - 32px));
    max-width: 100%;
    height: 90px;
    /* background: #333;
    border: 1px dashed #aaa;
    color: #fff; */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-radius: 8px;
    z-index: 1;
    margin: 0 auto;
}

/* 底部位置 */
.ad-bottom-test {
    left: auto;
}

.ad-right-push {
    position: fixed;
    top: 180px;
    width: 10px;
    height: 10px;
    right: calc(50% - 650px);
}

/* 小螢幕隱藏，避免擠壓內容 */
@media (max-width: 1400px) {
    .ad {
        display: none;
    }
}