#rh-app, #rh-app * , #rh-app *::before, #rh-app *::after { box-sizing: border-box; margin: 0; padding: 0; }

    #rh-app {
      --base:         #FFFFFF;
      --base-light:   #FAFAFA;
      --base-dark:    #F5F5F5;
      --main:         #1e3a5f;
      --main-light:   #2d5a8f;
      --main-dark:    #0f1e3a;
      --accent:       #d4af37;
      --accent-light: #f4cf5f;
      --accent-dark:  #b8941f;
      --text:         #2C3E50;
      --text-light:   #7F8C8D;
      --border:       #E8E8E8;
      --shadow:       0 4px 20px rgba(30,58,95,0.12);
      --shadow-lg:    0 8px 32px rgba(30,58,95,0.2);
      --green:        #2ecc71;
      --yellow:       #f1c40f;
      --red:          #e74c3c;
    }

    #rh-app {
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      background: linear-gradient(135deg, #FFFFFF 0%, #F8F9FA 50%, #F0F2F5 100%);
      color: var(--text);
      height: min(100svh, 100vh);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* TOP BAR */
    #rh-topbar {
      background: var(--main);
      border-top: 3px solid var(--accent);
      border-bottom: 3px solid var(--accent);
      padding: 8px 16px;
      display: flex; align-items: center; gap: 12px;
      flex-shrink: 0;
      box-shadow: 0 4px 20px rgba(30,58,95,0.3);
      position: relative; overflow: hidden;
    }
    #rh-topbar::before {
      content: ''; position: absolute; top: 0; left: -100%;
      width: 200%; height: 100%;
      background: linear-gradient(90deg, transparent, rgba(212,175,55,0.12), transparent);
      animation: shine 4s infinite; pointer-events: none;
    }
    @keyframes shine { 0%{left:-100%} 100%{left:100%} }
    #rh-topbar h1 {
      font-size: 1rem; font-weight: 900; color: var(--accent);
      white-space: nowrap; text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
    #rh-question-input {
      flex: 1; background: rgba(255,255,255,0.12);
      border: 1px solid rgba(212,175,55,0.4); border-radius: 8px;
      padding: 6px 12px; color: #fff;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.9rem;
      transition: all 0.3s;
    }
    #rh-question-input::placeholder { color: rgba(255,255,255,0.4); }
    #rh-question-input:focus {
      border-color: var(--accent); box-shadow: 0 0 0 3px rgba(212,175,55,0.2); outline: none;
    }

    /* MAIN (camera fullscreen) */
    #rh-main { flex: 1; position: relative; overflow: hidden; }
    #rh-camera-area { position: absolute; inset: 0; background: #111; }
    #rh-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
    #rh-canvas {
      position: absolute; top: 0; left: 0;
      width: 100%; height: 100%;
      pointer-events: none; transform: scaleX(-1);
    }

    /* placeholder */
    #rh-placeholder {
      position: absolute; inset: 0; display: flex; flex-direction: column;
      align-items: center; justify-content: center; gap: 14px;
      background-image: var(--rh-placeholder-bg);
      background-size: cover;
      background-position: center;
    }
    /* 背景画像の上に半透明オーバーレイ */
    #rh-placeholder::before {
      content: ''; position: absolute; inset: 0;
      background: rgba(15, 30, 58, 0.55);
    }
    #rh-placeholder p {
      position: relative; z-index: 1;
      color: rgba(255,255,255,0.85); font-size: 0.95rem;
      text-shadow: 0 1px 4px rgba(0,0,0,0.5);
    }
    #rh-start-btn {
      position: relative; z-index: 1;
      background: linear-gradient(135deg, var(--main-light), var(--main));
      color: #fff; border: none; border-radius: 14px; padding: 12px 32px;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 1rem; font-weight: 900;
      cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,0.4); transition: all 0.3s;
    }
    #rh-start-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.5); }

    /* flash */
    #rh-flash {
      position: absolute; top: 12px; left: 50%;
      transform: translateX(-50%) scale(0.85);
      background: var(--green); color: #fff;
      padding: 6px 20px; border-radius: 20px;
      font-weight: 900; font-size: 0.95rem;
      opacity: 0; pointer-events: none; transition: all 0.25s;
      white-space: nowrap; z-index: 50;
      box-shadow: 0 4px 12px rgba(46,204,113,0.4);
    }
    #rh-flash.show { opacity: 1; transform: translateX(-50%) scale(1); }

    /* status */
    #rh-statusbar {
      position: absolute; bottom: 0; left: 0; right: 0;
      background: linear-gradient(transparent, rgba(0,0,0,0.5));
      padding: 6px 12px; display: flex; align-items: center; gap: 8px;
      font-size: 0.78rem; color: rgba(255,255,255,0.8); z-index: 10;
    }
    #rh-dot { width: 8px; height: 8px; border-radius: 50%; background: #aaa; flex-shrink: 0; }
    #rh-dot.running { background: var(--green); animation: blink 1.5s infinite; }
    #rh-dot.loading { background: var(--yellow); animation: blink 0.8s infinite; }
    @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.25} }

    /* ===== FLOATING PANEL (共通) ===== */
    .rh-float {
      position: absolute;
      background: rgba(255,255,255,0.93);
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: var(--shadow-lg);
    }
    .rh-float-header {
      background: var(--main);
      border-top: 3px solid var(--accent);
      border-radius: 14px 14px 0 0;
      padding: 7px 12px;
      display: flex; align-items: center; justify-content: space-between;
      cursor: grab;
    }
    .rh-float-header:active { cursor: grabbing; }
    .rh-float-title { font-size: 0.72rem; font-weight: 900; color: var(--accent); letter-spacing: 0.08em; }
    .rh-float-hint  { font-size: 0.58rem; color: rgba(255,255,255,0.35); }
    .rh-float-body  { padding: 10px; }

    /* ===== CONTROL PANEL ===== */
    #rh-ctrl-panel { width: 215px; top: 16px; right: 16px; z-index: 100; }

    #rh-count-box {
      text-align: center; padding: 8px 6px 8px;
      border-bottom: 1px solid var(--border); margin-bottom: 8px;
    }
    #rh-cur-num { font-size: 2.8rem; font-weight: 900; color: var(--main); line-height: 1; }
    #rh-cur-label { font-size: 0.65rem; color: var(--text-light); margin-top: 2px; }
    #rh-ai-label  { font-size: 0.7rem;  color: var(--text-light); margin-top: 3px; }

    /* 確定待ち */
    #rh-pending-box {
      background: linear-gradient(135deg, rgba(46,204,113,0.07), rgba(46,204,113,0.03));
      border: 1px solid rgba(46,204,113,0.28);
      border-radius: 10px; padding: 9px; margin-bottom: 8px;
    }
    #rh-pending-box.hidden { display: none; }
    #rh-pending-label {
      font-size: 0.65rem; font-weight: 900; color: var(--green);
      display: flex; align-items: center; gap: 5px; margin-bottom: 7px;
    }
    #rh-pending-label::before {
      content:''; width:7px; height:7px; border-radius:50%;
      background:var(--green); animation:blink 1s infinite; flex-shrink:0;
    }
    #rh-pending-count-row {
      display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px;
    }
    .rh-pend-btn {
      width: 32px; height: 32px; border-radius: 50%;
      border: 2px solid var(--main); background: var(--base);
      color: var(--main); font-size: 1.2rem; font-weight: 700;
      cursor: pointer; display: flex; align-items: center; justify-content: center;
      transition: all 0.2s; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; flex-shrink: 0;
      box-shadow: 0 2px 6px rgba(30,58,95,0.12);
    }
    .rh-pend-btn:hover { background: var(--main); color: var(--accent); }
    #rh-pending-num  { font-size: 2rem; font-weight: 900; color: var(--main); min-width: 44px; text-align: center; line-height: 1; }
    #rh-pending-unit { font-size: 0.75rem; color: var(--text-light); text-align: center; }
    #rh-pending-ok {
      display: block; width: 100%; padding: 8px; border-radius: 10px; border: none;
      background: linear-gradient(135deg, var(--main-light), var(--main));
      color: #fff; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      font-size: 0.85rem; font-weight: 900; cursor: pointer;
      box-shadow: 0 3px 10px rgba(30,58,95,0.22); transition: all 0.2s;
    }
    #rh-pending-ok:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30,58,95,0.3); }
    #rh-pending-skip {
      display: block; width: 100%; padding: 4px; margin-top: 4px;
      border-radius: 7px; border: 1px solid var(--border);
      background: transparent; color: var(--text-light);
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.68rem; cursor: pointer;
      transition: color 0.15s;
    }
    #rh-pending-skip:hover { color: var(--text); }

    /* 最大値 */
    #rh-max-row {
      display: flex; align-items: center; justify-content: space-between;
      padding: 4px 0; margin-bottom: 6px; border-bottom: 1px solid var(--border);
    }
    #rh-max-label { font-size: 0.68rem; color: var(--text-light); }
    #rh-max-num   { font-size: 0.95rem; font-weight: 900; color: var(--green); }

    /* 記録 */
    .rh-sec-label {
      font-size: 0.63rem; font-weight: 900; color: var(--main);
      letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 5px;
    }
    #rh-rec-list { max-height: 180px; overflow-y: auto; }
    #rh-rec-list::-webkit-scrollbar { width: 3px; }
    #rh-rec-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
    .rh-rec-item {
      background: var(--base-light); border: 2px solid var(--border);
      border-radius: 8px; padding: 6px 8px; margin-bottom: 4px;
      cursor: pointer; transition: all 0.15s;
    }
    .rh-rec-item:hover { border-color: var(--main-light); }
    .rh-rec-item.selected { border-color: var(--accent); background: #fffcf0; box-shadow: 0 2px 8px rgba(212,175,55,0.18); }
    .rh-rec-item-top { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; }
    .rh-rec-badge {
      background: var(--main); color: var(--accent);
      font-size: 0.6rem; font-weight: 900; padding: 2px 6px; border-radius: 8px; white-space: nowrap;
    }
    .rh-rec-num { font-size: 0.95rem; font-weight: 900; color: var(--main); margin-left: auto; }
    .rh-rec-q-input {
      width: 100%; background: transparent; border: none;
      border-bottom: 1px solid var(--border);
      color: var(--text-light); font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      font-size: 0.65rem; padding: 1px 2px; outline: none;
    }
    .rh-rec-q-input::placeholder { color: #ccc; }
    .rh-rec-time { font-size: 0.58rem; color: #bbb; margin-top: 2px; }
    .rh-no-rec { font-size: 0.7rem; color: #bbb; }

    #rh-compare-btn {
      display: block; width: 100%; padding: 7px; margin-top: 6px;
      border-radius: 10px; border: none;
      background: linear-gradient(135deg, var(--accent-light), var(--accent));
      color: var(--main-dark);
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.78rem; font-weight: 900;
      cursor: pointer; box-shadow: 0 3px 10px rgba(212,175,55,0.28); transition: all 0.2s;
    }
    #rh-compare-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(212,175,55,0.38); }
    #rh-compare-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
    #rh-reset-btn {
      display: block; width: 100%; padding: 5px; margin-top: 4px;
      border-radius: 7px; border: 1px solid rgba(231,76,60,0.28);
      background: rgba(231,76,60,0.04); color: var(--red);
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.68rem; font-weight: 700; cursor: pointer;
    }
    #rh-reset-btn:hover { background: rgba(231,76,60,0.1); }

    /* ===== GRAPH PANEL (z-index最大) ===== */
    #rh-graph-panel {
      bottom: 16px; left: 16px;
      width: 500px;
      z-index: 200;
      transition: width 0.25s, height 0.25s, top 0.25s, left 0.25s;
    }
    #rh-graph-panel.maximized {
      top: 8px !important; left: 8px !important;
      bottom: auto; right: auto;
      width: calc(100vw - 16px) !important;
      height: calc(100vh - 16px) !important;
    }
    /* グラフエリアは白背景 */
    #rh-graph-bg {
      background: var(--base);
      border-radius: 0 0 14px 14px;
      padding: 8px 10px 10px;
    }
    /* グラフ種別切替 */
    #rh-chart-type { display: flex; gap: 4px; margin-bottom: 8px; }
    .rh-ct-btn {
      flex: 1; padding: 4px 0; border-radius: 6px;
      border: 1px solid var(--border);
      background: var(--base-dark); color: var(--text-light);
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.68rem; font-weight: 700;
      cursor: pointer; transition: all 0.15s;
    }
    .rh-ct-btn.active { background: var(--main); color: var(--accent); border-color: var(--main); }
    .rh-ct-btn:hover:not(.active) { border-color: var(--main-light); color: var(--main); }
    #rh-graph-inner { display: flex; gap: 10px; align-items: stretch; }
    #rh-graph-wrap  { flex: 1; min-height: 120px; position: relative; }
    #rh-graph-canvas { display: block; }
    #rh-compare-info { width: 148px; flex-shrink: 0; padding: 2px 0; }
    #rh-graph-bg .rh-cmp-row { border-bottom-color: var(--border); }
    #rh-graph-bg .rh-cmp-lbl { color: var(--text-light); }
    #rh-graph-bg .rh-cmp-val { color: var(--main); }
    #rh-graph-bg .pos { color: var(--green); }
    #rh-graph-bg .neg { color: var(--red); }
    #rh-graph-bg .neu { color: var(--accent-dark); }
    #rh-graph-panel.maximized #rh-compare-info {
      width: 220px !important;
      font-size: 1rem;
      display: flex; flex-direction: column; justify-content: center;
    }
    #rh-graph-panel.maximized .rh-cmp-row { padding: 10px 0; font-size: 1rem; }
    #rh-graph-panel.maximized .rh-cmp-val { font-size: 1.3rem; }
    #rh-maximize-btn {
      background: transparent; border: none; cursor: pointer;
      color: rgba(255,255,255,0.55); font-size: 1rem; line-height: 1;
      padding: 0 4px; border-radius: 4px; transition: color 0.15s;
    }
    #rh-maximize-btn:hover { color: var(--accent); }
    .rh-cmp-row {
      display: flex; justify-content: space-between; align-items: center;
      padding: 3px 0; font-size: 0.72rem; border-bottom: 1px solid var(--border);
    }
    .rh-cmp-row:last-child { border-bottom: none; }
    .rh-cmp-lbl { color: var(--text-light); }
    .rh-cmp-val { font-weight: 900; font-size: 0.85rem; color: var(--main); }
    .pos { color: var(--green); } .neg { color: var(--red); } .neu { color: var(--accent-dark); }

    /* MODAL */
    #rh-modal {
      display: none; position: fixed; inset: 0;
      background: rgba(30,58,95,0.55);
      backdrop-filter: blur(4px); z-index: 500;
      align-items: center; justify-content: center;
    }
    #rh-modal.open { display: flex; }
    #rh-modal-box {
      background: var(--base); border: 1px solid var(--border);
      border-top: 4px solid var(--accent);
      border-radius: 16px; padding: 20px;
      width: 380px; max-width: 95vw; box-shadow: var(--shadow-lg);
    }
    #rh-modal-box h2 { font-size: 1rem; color: var(--main); margin-bottom: 14px; font-weight: 900; }
    .rh-modal-rec {
      background: var(--base-light); border-radius: 8px; padding: 8px 12px; margin-bottom: 7px;
      cursor: pointer; border: 2px solid var(--border); transition: all 0.15s;
      display: flex; align-items: center; gap: 10px;
    }
    .rh-modal-rec:hover { border-color: var(--main-light); }
    .rh-modal-rec.sel  { border-color: var(--accent); background: #fffcf0; }
    .rh-modal-rec-badge { font-size: 0.7rem; font-weight: 900; color: var(--accent); min-width: 40px; }
    .rh-modal-rec-q     { font-size: 0.82rem; flex: 1; color: var(--text); }
    .rh-modal-rec-num   { font-size: 1.1rem; font-weight: 900; color: var(--main); }
    #rh-modal-btns { display: flex; gap: 8px; margin-top: 14px; }
    .rh-modal-btn {
      flex: 1; padding: 9px; border-radius: 10px;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 0.85rem; font-weight: 900;
      cursor: pointer; border: none;
    }
    #rh-modal-ok {
      background: linear-gradient(135deg, var(--accent-light), var(--accent));
      color: var(--main-dark); box-shadow: 0 3px 10px rgba(212,175,55,0.28);
    }
    #rh-modal-cancel {
      background: var(--base-dark); color: var(--text-light); border: 1px solid var(--border);
    }

    /* TOAST */
    #rh-toast {
      position: fixed; top: 68px; left: 50%;
      transform: translateX(-50%) translateY(-10px);
      background: var(--main); color: var(--accent);
      border: 1px solid var(--accent);
      padding: 7px 20px; border-radius: 20px;
      font-weight: 900; font-size: 0.83rem;
      opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 600;
      box-shadow: 0 4px 12px rgba(30,58,95,0.3);
    }
    #rh-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
