/* ==========================================================================
   转转页面（spin）样式 —— 页面级隔离，全部选择器以 .spin- 前缀命名
   DOM 骨架：index.html 中 id="spinView" 的整块结构
   交互逻辑：spin.js
   公共接口：window.SpinPage（见 agent.md）

   形态：左侧对齐的横条列表（一行＝一格），开始后随机高亮某一行并把它
   伸长到满宽，下一次切换则缩回，直到时长结束定格。
   ========================================================================== */

.spin-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    color: #1e293b;
    z-index: 400;
    display: none;
    flex-direction: column;
    overflow: hidden;
    /* 单行高度（实际值由 spin.js 测量后覆盖），用于横条字号自适应 */
    --spin-row-h: 50px;
    -webkit-tap-highlight-color: transparent;
}

.spin-view.active {
    display: flex;
}

/* ---------- 顶部导航条：默认隐藏，出结果时才显示「结果：xxx」（纯文字，没有按钮） ---------- */
.spin-nav {
    flex: 0 0 auto;
    display: none;
    min-height: 2.6rem;
    padding: 0.6rem 1rem;
    padding-top: calc(env(safe-area-inset-top, 0px) + 0.6rem);
    background: #529b2e;
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    /* 定下结果后允许折行，把完整文案显示出来 */
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* 旋转中显示当前高亮项、定下结果后固定显示结果；两者都没有时隐藏 */
.spin-view.spinning .spin-nav,
.spin-view.settled .spin-nav {
    display: block;
}

/* 旋转中一律不换行（否则 nav 高度抖动会带着列表一起跳），超出用省略号 */
.spin-view.spinning .spin-nav {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- 横条列表：行数多到装不下就挤压每行高度，不滚动 ---------- */
.spin-list {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 5px;
    padding: 16px 0;
}

.spin-row {
    /* 行少时最高 50px、从顶部往下排；行数多到装不下就等分压缩铺满一屏 */
    flex: 1 1 0;
    min-height: 0;
    max-height: 50px;
    display: flex;
    align-items: stretch;
}

/* 行数超过 40 时按列显示（列数由 spin.js 决定，加 .spin-cols-2 / .spin-cols-3） */
.spin-list.spin-cols-2,
.spin-list.spin-cols-3 {
    display: grid;
    grid-auto-rows: minmax(0, 1fr);
    align-items: start;
    /* 行间距 5px、列间距 8px（COL_GAP 与之一致） */
    gap: 5px 8px;
}

.spin-list.spin-cols-2 {
    grid-template-columns: 1fr 1fr;
}

.spin-list.spin-cols-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.spin-bar {
    /* 统一宽度：由 spin.js 按最长选项文字量出来（--spin-bar-w），上限 80% */
    width: var(--spin-bar-w, 58%);
    max-width: 80%;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 0 0.7em;
    /* 左侧贴边做直角（正方形），右侧上下做圆角 */
    border-radius: 0 999px 999px 0;
    background-color: #b3e19d;
    color: #ffffff;
    font-size: clamp(9px, calc(var(--spin-row-h) * 0.42), 20px);
    font-weight: 600;
    transition: width 0.1s ease-out, background-color 0.25s, color 0.25s;
}

/* 被选中：宽度 +40px，底色比默认稍深一档做区分（不占满整屏） */
.spin-row.picked .spin-bar {
    width: calc(var(--spin-bar-w, 58%) + 40px);
    max-width: 100%;
    background-color: #93d176;
    font-weight: 800;
}

/* 选中结束（.spin-view.settled）：非选中项转成更浅的绿 + 灰绿字，只把定下来的那行留成深绿 */
.spin-view.settled .spin-row:not(.picked) .spin-bar {
    background-color: #e9f6e3;
    color: #7fa96c;
    font-weight: 600;
}

.spin-bar-text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* 点击次数（连击）提示：黑色半透明 + 绿字，显隐不加动画（由 JS 0.5s 后隐藏） */
.spin-combo {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 2rem);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.4rem 1.15rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.5);
    color: #b3e19d;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 1px;
    z-index: 8;
    opacity: 0;
    pointer-events: none;
}

.spin-combo.show {
    opacity: 1;
}

.spin-empty {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
    font-size: 1rem;
    color: #8fb37e;
    z-index: 2;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.spin-empty.active {
    opacity: 1;
}

/* ---------- 设置悬浮按钮 + 展开菜单（绿色主题） ---------- */
.spin-fab {
    position: fixed;
    right: 20px;
    bottom: 100px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(82, 155, 46, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(63, 107, 42, 0.28);
    text-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.2s, opacity 0.22s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
}

.spin-fab:active {
    transform: scale(0.92);
}

.spin-fab.open {
    background: rgba(63, 107, 42, 0.92);
}

/* 选取过程中把「设」藏起来（也不可点，点到这里等于点屏幕），出结果后再显示 */
.spin-view.spinning .spin-fab {
    opacity: 0;
    pointer-events: none;
}

.spin-menu {
    position: fixed;
    right: 20px;
    bottom: 178px;
    width: 238px;
    max-height: calc(100vh - 210px);
    overflow-y: auto;
    padding: 0.45rem;
    border-radius: 22px;
    background: rgba(244, 252, 238, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(179, 225, 157, 0.95);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    z-index: 7;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
    -webkit-overflow-scrolling: touch;
}

.spin-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.spin-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    border: none;
    background: transparent;
    padding: 0.6rem 0.75rem;
    border-radius: 14px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: #2f4f22;
    text-align: left;
    cursor: pointer;
    transition: background 0.18s;
    flex: 0 0 auto;
}

.spin-menu-item:active {
    background: #e9f6e3;
}

.spin-menu-icon {
    flex: 0 0 auto;
    width: 1.2rem;
    text-align: center;
    font-size: 1rem;
    color: #7fa96c;
}

.spin-menu-label {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spin-menu-sep {
    height: 1px;
    margin: 0.25rem 0.5rem;
    background: rgba(82, 155, 46, 0.2);
    flex: 0 0 auto;
}

/* 行内控件行（旋转时长 / 点击次数）：整行不可点，只有右侧控件可交互 */
.spin-menu-duration,
.spin-menu-toggle {
    cursor: default;
    padding-right: 0.5rem;
}

.spin-menu-duration:active,
.spin-menu-toggle:active {
    background: transparent;
}

.spin-step-btn {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #e9f6e3;
    color: #3f6b2a;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.18s, transform 0.12s;
}

.spin-step-btn:active {
    transform: scale(0.9);
    background: #d6ecc8;
}

.spin-duration-value {
    flex: 0 0 auto;
    min-width: 2.8rem;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: #3f6b2a;
    font-variant-numeric: tabular-nums;
}

/* 开关：点击次数 */
.spin-switch {
    position: relative;
    flex: 0 0 auto;
    width: 42px;
    height: 24px;
    display: inline-block;
}

.spin-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.spin-switch-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 999px;
    background: #d6ecc8;
    cursor: pointer;
    transition: background 0.2s;
}

.spin-switch-slider::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.spin-switch input:checked + .spin-switch-slider {
    background: #529b2e;
}

.spin-switch input:checked + .spin-switch-slider::before {
    transform: translateX(18px);
}

/* ---------- 弹窗（编辑 / 历史 / 分享 / 接收） ---------- */
.spin-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.spin-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.spin-modal {
    width: 100%;
    max-width: 420px;
    max-height: 86%;
    padding: 1.1rem 1.1rem 1.2rem;
    border-radius: 28px;
    background: #fbfff9;
    box-shadow: 0 20px 50px rgba(47, 79, 34, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow: hidden;
    transform: scale(0.92);
    transition: transform 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.spin-modal-overlay.active .spin-modal {
    transform: scale(1);
}

.spin-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.spin-modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #2f4f22;
}

.spin-modal-close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: #e9f6e3;
    color: #3f6b2a;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, transform 0.12s;
}

.spin-modal-close:active {
    transform: scale(0.92);
    background: #d6ecc8;
}

.spin-field-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #7fa96c;
}

.spin-input {
    width: 100%;
    padding: 0.8rem 0.9rem;
    border: 2px solid #b3e19d;
    border-radius: 18px;
    background: #f4fcee;
    font-family: inherit;
    font-size: 1rem;
    color: #2f4f22;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.spin-input:focus {
    border-color: #529b2e;
}

/* 编辑弹窗输入框跟随绿色主题 */
.spin-input::placeholder,
.spin-option-text::placeholder,
.spin-option-qty::placeholder {
    color: #9bc183;
}

.spin-textarea {
    width: 100%;
    min-height: 5.5rem;
    padding: 0.8rem 0.9rem;
    border: 2px solid #b3e19d;
    border-radius: 18px;
    background: #f4fcee;
    font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.45;
    color: #2f4f22;
    outline: none;
    resize: none;
    word-break: break-all;
    -webkit-user-select: text;
    user-select: text;
}

.spin-textarea:focus {
    border-color: #529b2e;
}

.spin-input-error {
    animation: spinShake 0.45s ease;
    border-color: #ef4444 !important;
}

@keyframes spinShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.spin-modal-hint {
    font-size: 0.82rem;
    line-height: 1.45;
    color: #7fa96c;
}

/* 编辑弹窗：选项列表 */
.spin-option-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 42vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.15rem;
    -webkit-overflow-scrolling: touch;
}

.spin-option-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.spin-option-text {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.7rem 0.8rem;
    border: 2px solid #b3e19d;
    border-radius: 16px;
    background: #f4fcee;
    font-family: inherit;
    font-size: 0.98rem;
    color: #2f4f22;
    outline: none;
    transition: border-color 0.2s;
}

.spin-option-text:focus,
.spin-option-qty:focus {
    border-color: #529b2e;
}

.spin-option-qty {
    flex: 0 0 auto;
    width: 4.4rem;
    padding: 0.7rem 0.4rem;
    border: 2px solid #b3e19d;
    border-radius: 16px;
    background: #f4fcee;
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 700;
    text-align: center;
    color: #2f4f22;
    outline: none;
    -moz-appearance: textfield;
    -webkit-appearance: none;
    appearance: none;
}

.spin-option-qty::-webkit-outer-spin-button,
.spin-option-qty::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.spin-option-del {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, transform 0.12s;
}

.spin-option-del:active {
    transform: scale(0.9);
    background: rgba(239, 68, 68, 0.22);
}

.spin-add-option-btn {
    border: 2px dashed #b3e19d;
    border-radius: 16px;
    background: transparent;
    padding: 0.7rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: #52822f;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.spin-add-option-btn:active {
    background: #e9f6e3;
    border-color: #9bc183;
}

.spin-modal-actions {
    display: flex;
    gap: 0.7rem;
}

.spin-btn {
    flex: 1 1 0;
    border: none;
    border-radius: 22px;
    padding: 0.9rem 1rem;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    background: #529b2e;
    cursor: pointer;
    transition: filter 0.2s, transform 0.12s;
}

.spin-btn.cancel {
    background: #e9f6e3;
    color: #2f4f22;
}

.spin-btn:active {
    transform: scale(0.97);
    filter: brightness(1.04);
}

/* 历史弹窗 */
.spin-history-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 52vh;
    overflow-y: auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    -webkit-overflow-scrolling: touch;
}

.spin-history-item {
    display: flex;
    /* 值换行时右侧的时间/徽章贴着第一行 */
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.65rem 0.85rem;
    border-radius: 16px;
    background: #f1f8ec;
}

.spin-history-value {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    color: #2f4f22;
    /* 文字过长就换行显示，不再截断 */
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.spin-history-time {
    flex: 0 0 auto;
    margin-top: 0.12rem;
    font-size: 0.8rem;
    line-height: 1.35;
    color: #8fb37e;
    font-variant-numeric: tabular-nums;
}

.spin-history-combo {
    flex: 0 0 auto;
    margin-top: 0.1rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: #529b2e;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 700;
}

.spin-history-empty {
    padding: 1.4rem 0;
    text-align: center;
    font-size: 0.92rem;
    color: #9bc183;
}

/* 切换转转弹窗：已有的转转列表（绿色主题） */
.spin-switch-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 52vh;
    overflow-y: auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    -webkit-overflow-scrolling: touch;
}

.spin-switch-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.6rem 0.6rem 0.85rem;
    border: 2px solid transparent;
    border-radius: 16px;
    background: #f1f8ec;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.spin-switch-item:active {
    background: #e9f6e3;
}

/* 当前正在用的那一个 */
.spin-switch-item.current {
    border-color: #529b2e;
    background: #e9f6e3;
}

.spin-switch-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #2f4f22;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spin-switch-meta {
    flex: 0 0 auto;
    font-size: 0.78rem;
    color: #8fb37e;
    font-variant-numeric: tabular-nums;
}

.spin-switch-del {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, transform 0.12s;
}

.spin-switch-del:active {
    transform: scale(0.9);
    background: rgba(239, 68, 68, 0.22);
}

/* ---------- 轻提示 ---------- */
.spin-toast {
    position: fixed;
    left: 50%;
    bottom: 20%;
    transform: translate(-50%, 10px);
    max-width: 80%;
    padding: 0.6rem 1.1rem;
    border-radius: 999px;
    background: #529b2e;
    color: #ffffff;
    font-size: 0.95rem;
    text-align: center;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.spin-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 360px) {
    .spin-menu {
        width: 208px;
    }
}
