/* ============================================================
   吉他即兴屋（Improv Material）· 样式
   全部作用域限定在 #ivm 内 —— 可直接内联进任意页面而不污染宿主样式。
   颜色优先继承宿主页面的设计变量（--bg-elevated / --text / --blue …），
   独立打开时回退到内置取值，并跟随 html[data-theme="dark"]。
   ============================================================ */

#ivm {
    --ivm-panel: var(--bg-elevated, #ffffff);
    --ivm-border: var(--border-strong, rgba(0, 0, 0, 0.14));
    --ivm-text: var(--text, #1d1d1f);
    --ivm-label: var(--text-2, #6e6e73);
    --ivm-field-bg: var(--bg, #ffffff);
    --ivm-accent: var(--blue, #0071e3);
    --ivm-accent-soft: rgba(0, 113, 227, 0.1);
    --ivm-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .05));
    --ivm-root: #e8281e;

    font-family: var(--font, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif);
    color: var(--ivm-text);
    font-size: 15px;
    line-height: 1.5;
}

html[data-theme="dark"] #ivm {
    --ivm-panel: var(--bg-elevated, #161618);
    --ivm-border: var(--border-strong, rgba(255, 255, 255, 0.16));
    --ivm-text: var(--text, #f5f5f7);
    --ivm-label: var(--text-2, #9a9aa4);
    --ivm-field-bg: var(--bg, #111114);
    --ivm-accent-soft: rgba(41, 151, 255, 0.16);
    --ivm-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .4));
}

#ivm *,
#ivm *::before,
#ivm *::after { box-sizing: border-box; }

/* ---------- 控制条（调性 / 素材 两个下拉） ---------- */
#ivm .ivm-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 22px;
    padding: 13px 18px;
    margin-bottom: 16px;
    background: var(--ivm-panel);
    border: 1px solid var(--ivm-border);
    border-radius: var(--radius-sm, 12px);
    box-shadow: var(--ivm-shadow);
}

#ivm .ivm-field {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

#ivm .ivm-field.ivm-grow { flex: 1 1 300px; }

#ivm .ivm-flabel {
    flex: 0 0 auto;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ivm-label);
    letter-spacing: 0.02em;
}

#ivm .ivm-select {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--ivm-border);
    background-color: var(--ivm-field-bg);
    color: var(--ivm-text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    padding: 8px 32px 8px 13px;
    border-radius: 10px;
    cursor: pointer;
    max-width: 100%;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    background-size: 12px;
    transition: border-color 0.2s var(--ease-out, ease-out), box-shadow 0.2s var(--ease-out, ease-out);
}

#ivm .ivm-select:hover { border-color: var(--ivm-accent); }
#ivm .ivm-select:focus {
    outline: none;
    border-color: var(--ivm-accent);
    box-shadow: 0 0 0 3px var(--ivm-accent-soft);
}

#ivm .ivm-sel-mat { flex: 1 1 auto; min-width: 0; }

/* ---------- 伴奏卡 ---------- */
#ivm .ivm-tkcard { display: none; }
#ivm .ivm-tkcard[data-on] {
    display: block;
    padding: 14px 18px 16px;
    margin: -6px 0 16px;
    background: var(--ivm-panel);
    border: 1px solid var(--ivm-border);
    border-radius: var(--radius-sm, 12px);
    box-shadow: var(--ivm-shadow);
}

#ivm .ivm-tk-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-bottom: 12px;
}
#ivm .ivm-tk-t { font-size: 15px; font-weight: 600; }
#ivm .ivm-tk-sub { font-size: 12px; color: var(--ivm-label); opacity: 0.8; }
#ivm .ivm-tk-out {
    margin-left: auto;
    font-size: 12px;
    color: var(--ivm-accent);
    text-decoration: none;
    border: 1px solid var(--ivm-border);
    border-radius: 999px;
    padding: 2px 10px;
}
#ivm .ivm-tk-out:hover { border-color: var(--ivm-accent); }

#ivm .ivm-tk-media { margin-bottom: 12px; }
#ivm .ivm-tk-i {
    display: block;
    width: 100%;
    height: 200px;
    border: 0;
    border-radius: 10px;
    background: #000;
}
#ivm .ivm-tk-a { display: block; width: 100%; }

#ivm .ivm-tk-rows { display: block; }

/* ---------- 和声格子 + 已选素材小格子 + 素材弹出框 ---------- */
/* 和声格子：整行等宽铺满、内容居中，连成一排的表格单元格 */
#ivm .ivm-throw {
    display: grid;
    align-items: stretch;
    font-size: 13px;
}
#ivm .ivm-chips {
    display: grid;
    align-items: stretch;
    gap: 5px 0;
    padding-top: 7px;
}

#ivm .ivm-th {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    margin: 0;
    padding: 8px 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.25;
    text-align: center;
    color: var(--ivm-text);
    background: none;
    border: 1px solid var(--ivm-border);
    border-left-width: 0;
    border-radius: 0;
    cursor: pointer;
    transition: background .15s, color .15s;
}
#ivm .ivm-th-first { border-left-width: 1px; border-radius: 12px 0 0 12px; }
#ivm .ivm-th-last { border-radius: 0 12px 12px 0; }
#ivm .ivm-th b { display: block; font-weight: 500; }
#ivm .ivm-th i {
    display: block;
    max-width: 100%;
    font-style: normal;
    font-size: 11px;
    color: var(--ivm-label);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#ivm .ivm-th:hover { background: var(--ivm-accent-soft); color: var(--ivm-accent); }
#ivm .ivm-th.open { background: var(--ivm-accent-soft); border-color: var(--ivm-accent); color: var(--ivm-accent); }
#ivm .ivm-th.open i { color: var(--ivm-accent); opacity: 0.85; }
#ivm .ivm-th.active { background: var(--ivm-accent); color: #fff; border-color: var(--ivm-accent); }
#ivm .ivm-th.active i { color: rgba(255, 255, 255, 0.85); }

/* 已选素材小格子：贴在和弦下面，宽 = 覆盖的和弦列；相邻和弦同音集合并成一条。
   外层 .ivm-chipm 只管外观和格子定位，里面 = 主按钮（切指板）+ 小 × （移除） */
#ivm .ivm-chipm {
    display: flex;
    align-items: center;
    gap: 1px;
    min-width: 0;
    margin: 0 3px;
    padding: 0 2px 0 8px;
    font-size: 11.5px;
    line-height: 1.3;
    color: var(--ivm-text);
    background: var(--ivm-field-bg);
    border: 1px solid var(--ivm-border);
    border-radius: 8px;
    transition: border-color .15s, color .15s, background .15s;
}
#ivm .ivm-chipm:hover { border-color: var(--ivm-accent); color: var(--ivm-accent); }
#ivm .ivm-chipm.cur { background: var(--ivm-accent); border-color: var(--ivm-accent); color: #fff; }
#ivm .ivm-chipm-g {
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    text-align: center;
    color: inherit;
    background: none;
    border: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
#ivm .ivm-chipm-x {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    padding: 0;
    font-family: inherit;
    font-size: 11px;
    line-height: 1;
    color: inherit;
    opacity: 0.55;
    background: none;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    transition: opacity .15s, background .15s;
}
#ivm .ivm-chipm-x:hover { opacity: 1; background: rgba(255, 255, 255, 0.28); }
#ivm .ivm-chipm:not(.cur) .ivm-chipm-x:hover { background: var(--ivm-accent-soft); }

/* 点和弦渐变出的素材框：可多选 */
#ivm .ivm-pop {
    margin-top: 9px;
    padding: 10px 12px 12px;
    background: var(--ivm-field-bg);
    border: 1px solid var(--ivm-border);
    border-radius: 12px;
    animation: ivmPop .2s ease-out;
}
@keyframes ivmPop {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    #ivm .ivm-pop { animation: none; }
}
#ivm .ivm-pop-h {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 9px;
    font-size: 12.5px;
}
#ivm .ivm-pop-h b { font-weight: 600; }
#ivm .ivm-pop-h i { font-style: normal; font-size: 11.5px; color: var(--ivm-label); }
#ivm .ivm-pop-x {
    margin-left: auto;
    flex: 0 0 auto;
    align-self: center;
    width: 22px;
    height: 22px;
    padding: 0;
    font-size: 15px;
    line-height: 1;
    color: var(--ivm-label);
    background: none;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}
#ivm .ivm-pop-x:hover { color: var(--ivm-accent); background: var(--ivm-accent-soft); }
#ivm .ivm-pop-m { display: flex; flex-wrap: wrap; gap: 6px; }
#ivm .ivm-mat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 4px 10px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.3;
    color: var(--ivm-text);
    background: none;
    border: 1px solid var(--ivm-border);
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
}
#ivm .ivm-mat .ivm-mat-i { flex: 0 0 auto; font-style: normal; font-size: 10.5px; color: var(--ivm-label); }
#ivm .ivm-mat:hover { border-color: var(--ivm-accent); color: var(--ivm-accent); }
#ivm .ivm-mat:hover .ivm-mat-i { color: inherit; }
#ivm .ivm-mat.sel { border-color: var(--ivm-accent); color: var(--ivm-accent); background: var(--ivm-accent-soft); font-weight: 600; }
#ivm .ivm-mat.sel .ivm-mat-i { color: inherit; }
#ivm .ivm-mat.cur { background: var(--ivm-accent); border-color: var(--ivm-accent); color: #fff; }
#ivm .ivm-mat.cur .ivm-mat-i { color: rgba(255, 255, 255, 0.85); }

@media (max-width: 640px) {
    #ivm .ivm-th { font-size: 12.5px; min-height: 46px; padding: 6px 3px; }
    #ivm .ivm-th i { display: none; }
    #ivm .ivm-chipm { margin: 0 2px; font-size: 10.5px; padding: 0 1px 0 6px; }
    #ivm .ivm-chipm-x { width: 14px; height: 14px; font-size: 10px; }
    #ivm .ivm-pop { padding: 8px 10px 10px; }
}

/* ---------- 指板视图卡 ---------- */
#ivm .ivm-view {
    padding: 18px 18px 14px;
    background: var(--ivm-panel);
    border: 1px solid var(--ivm-border);
    border-radius: var(--radius-sm, 12px);
    box-shadow: var(--ivm-shadow);
}

#ivm .ivm-vhead {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

#ivm .ivm-vtitle {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.25;
}

#ivm .ivm-vsub {
    font-size: 12.5px;
    color: var(--ivm-label);
    margin-top: 3px;
}

#ivm .ivm-vsub .ivm-degs { font-weight: 600; color: var(--ivm-text); opacity: 0.85; }

/* 「替代琶音 → 实际听到的和弦」徽标（≡ Dm9 无根音）与音阶色彩音徽标 */
#ivm .ivm-heard {
    display: inline-block;
    font-weight: 600;
    color: var(--ivm-accent);
    background: var(--ivm-accent-soft);
    border-radius: 6px;
    padding: 0 6px;
    cursor: help;
    white-space: nowrap;
}
#ivm .ivm-heard.warn { color: var(--ivm-root); background: rgba(232, 40, 30, 0.1); }

/* 指型 / 音名 / 音级 切换（指型 = 教材画法：纯圆点） */
#ivm .ivm-seg {
    display: inline-flex;
    background: var(--ivm-field-bg);
    border: 1px solid var(--ivm-border);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
    flex: 0 0 auto;
}

#ivm .ivm-seg button {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;
    color: var(--ivm-label);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    padding: 5px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out, ease-out);
    line-height: 1.2;
}

#ivm .ivm-seg button.active {
    background: var(--ivm-accent);
    color: #fff;
}

/* 组成音列表 */
#ivm .ivm-notes {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    margin: 10px 0 2px;
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

#ivm .ivm-notes .ivm-nroot { color: var(--ivm-root); }
#ivm .ivm-notes .ivm-nsep { color: var(--ivm-label); font-weight: 400; opacity: 0.6; }

/* 区域切换：全指板 / ⑤ / ⑤ / ⑩ / ⑩ / ⑫（教材的把位圈号） */
#ivm .ivm-pos {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 12px 0 2px;
}

#ivm .ivm-posbtn {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--ivm-border);
    background: var(--ivm-field-bg);
    color: var(--ivm-label);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.3;
    min-width: 40px;
    padding: 4px 9px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s var(--ease-out, ease-out);
}

#ivm .ivm-posbtn:first-child { font-size: 12.5px; font-weight: 600; padding: 4px 13px; }
#ivm .ivm-posbtn:hover { border-color: var(--ivm-accent); color: var(--ivm-accent); }
#ivm .ivm-posbtn:active { transform: scale(0.95); }

/* 按钮里的 CAGED 指型名（副标记，比圈号淡一点） */
#ivm .ivm-shape {
    margin-left: 2px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    opacity: 0.5;
}

#ivm .ivm-posbtn:hover .ivm-shape { opacity: 0.75; }

#ivm .ivm-posbtn.active {
    background: var(--ivm-accent);
    border-color: var(--ivm-accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.28);
}

#ivm .ivm-posbtn.active .ivm-shape { opacity: 0.85; }

/* 指板 */
#ivm .ivm-board { margin: 6px 0 2px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
#ivm .ivm-board svg { display: block; width: 100%; height: auto; }
/* 0–24 品总览：24 列在窄屏会被压到看不清圈内字，给一个最小宽度，超出就横向滚动 */
#ivm .ivm-board[data-view="full"] svg { min-width: 760px; }
/* 教材方框是「6 弦 × 5 品」的近正方块（viewBox 712×592），撑满宽度会长得过高：
   限个宽并居中，格子看起来才跟教材一样接近正方 */
#ivm .ivm-board[data-view="win"] { display: flex; justify-content: center; }
#ivm .ivm-board[data-view="win"] svg { max-width: 470px; }
#ivm .ivm-board circle.ivm-dot { cursor: pointer; }
#ivm .ivm-board circle.ivm-dot:hover { stroke: var(--ivm-accent); stroke-width: 2.5; }

#ivm .ivm-tip {
    margin-top: 8px;
    font-size: 12px;
    color: var(--ivm-label);
}

/* ---------- 窄屏 ---------- */
@media (max-width: 600px) {
    #ivm { font-size: 14px; }
    #ivm .ivm-bar { padding: 12px 14px; gap: 10px 16px; }
    #ivm .ivm-view { padding: 14px 12px 12px; }
    #ivm .ivm-field { flex: 1 1 100%; }
    /* iOS Safari：select 字号 <16px 聚焦会触发页面缩放 */
    #ivm .ivm-select { font-size: 16px; }
    #ivm .ivm-vtitle { font-size: 19px; }
}

/* ---------- 分享链接按钮（伴奏条右端） ---------- */
#ivm .ivm-sharebtn {
    flex: 0 0 auto;
    border: 1px solid var(--ivm-border);
    background: var(--ivm-field-bg);
    color: var(--ivm-label);
    border-radius: 10px;
    padding: 8px 13px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
#ivm .ivm-sharebtn:hover { color: var(--ivm-accent); border-color: var(--ivm-accent); }
