  :root {
    color-scheme: light;
    --left-panel-w: 340px;
    --primary: #16a34a;
    --orange: #f97316;
  }

  body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: #f6f7f9;
  }

  .wrap {
    display: flex;
    height: 100vh;
  }

  .left {
    width: 340px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 14px;
    overflow: auto;
  }

  .title {
    font-weight: 700;
    font-size: 18px;
    margin: 4px 0 12px;
  }

  .section {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
  }

  .section h3 {
    margin: 0 0 8px;
    font-size: 15px;
  }

  .row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
    flex-wrap: wrap;
  }

  .row.two-cols {
    align-items: flex-start;
  }

  .row.two-cols .col {
    flex: 1 1 0;
    min-width: 0;
  }

  .btn {
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    cursor: pointer;
    background: #f1f3f5;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn.primary {
    background: var(--primary);
    color: #fff;
  }

  .btn.orange {
    background: var(--orange);
    color: #fff;
  }

  .btn.warn {
    background: #ef4444;
    color: #fff;
  }

  .btn.gray {
    background: #6b7280;
    color: #fff;
  }

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

  select,
  input[type="range"],
  input[type="color"] {
    width: 100%;
  }

  .small {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.45;
  }

  input[type="radio"] {
    accent-color: var(--primary);
  }

  .status {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .pill {
    font-size: 12px;
    padding: 4px 7px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    border: 1px solid #e0e7ff;
  }

  .pill.ok {
    background: #ecfdf5;
    color: #065f46;
    border-color: #d1fae5;
  }

  .pill.wait {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
  }

  .pill.bad {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
  }

  .thumbs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .thumb {
    position: relative;
    width: 70px;
    height: 70px;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .thumb.active {
    border-color: var(--primary);
  }

  .thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .thumb-del {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 0;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
  }

  .thumb-del:hover {
    background: rgba(0, 0, 0, 0.8);
  }

  /* 썸네일 좌측 하단 저장 버튼 */
  .thumb-save {
    position: absolute;
    left: 2px;
    bottom: 2px;
    padding: 2px 5px;
    border-radius: 999px;
    border: 0;
    background: rgba(31, 41, 55, 0.85);
    color: #f9fafb;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
  }

  .thumb-save:hover {
    background: rgba(17, 24, 39, 0.95);
  }

  .right {
    flex: 1;
    position: relative;
    overflow: auto;
  }

  #dropZone {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f6f7f9;
    transition: .12s;
    padding: 12px;
  }

  #dropZone.dragover {
    background: #eef2ff;
    outline: 3px dashed #2563eb;
    outline-offset: -12px;
  }

  #canvasWrap {
    position: relative;
    background: #ddd;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .08);
    overflow: hidden;
    margin: auto;
  }

  canvas {
    display: block;
    border-radius: 10px;
  }

  #overlayCanvas {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
  }

  #maskCanvasDelete,
  #maskCanvasTranslate {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    opacity: 0;
  }

  .hint {
    text-align: center;
    color: #6b7280;
    font-size: 18px;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 28px 24px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .06);
    cursor: pointer;
  }

  .hint .sub {
    font-size: 13px;
    color: #9ca3af;
    margin-top: 6px;
  }

  .hint .actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    justify-content: center;
  }

  .hint .actions button {
    padding: 10px 14px;
  }

  .tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    margin-top: 4px;
  }

  .tool-btn,
  .range-btn {
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
  }

  .tool-btn {
    background: rgba(22,163,74,0.10);
    color: #166534;
    border-color: rgba(22,163,74,0.35);
  }
  .tool-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  .range-btn {
    background: rgba(249,115,22,0.12);
    color: #9a3412;
    border-color: rgba(249,115,22,0.35);
  }
  .range-btn.active {
    background: var(--orange);
    color: #fff;
    border-color: #ea580c;
  }

  /* 빨간색 전체취소 버튼 (범위설정용) */
  .btn.warn.range-btn {
    background: #ef4444;
    color: #fff;
    border-color: transparent;
  }

  /* 회색 직전취소 버튼 (범위설정용) */
  .range-btn.range-undo {
    background: #f1f3f5;
    color: #111827;
    border-color: transparent;
  }

  .range-btn.range-undo.active {
    background: #e5e7eb;
  }

  .dimmed {
    opacity: .5;
  }

  .action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }

  .action-grid .btn {
    width: 100%;
    height: 40px;
    font-weight: 600;
  }

  #progressOverlay {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--left-panel-w);
    right: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.70);
    backdrop-filter: blur(2px);
    z-index: 9999;
  }

  .progressBox {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .12);
  }

  .spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: #111827;
    animation: spin 0.9s linear infinite;
  }

  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }

  #progressText {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    letter-spacing: -0.2px;
  }

  #translateTexts {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
  }

  .tr-block {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 6px;
    background: #f9fafb;
  }

  .tr-block-title {
    font-size: 12px;
    color: #4b5563;
    margin-bottom: 4px;
  }

  .tr-block textarea {
    width: 100%;
    min-height: 60px;
    font-size: 12px;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    resize: vertical;
    box-sizing: border-box;
  }

  .tr-actions-row {
    margin-top: 4px;
    justify-content: flex-end;
  }

  .tr-actions-row .btn {
    min-width: 70px;
  }

  /* 번역 텍스트 스타일 섹션 */
  #textStyleSection .small {
    margin-bottom: 4px;
  }

  /* 컬러 히스토리 */
  .color-history {
    margin-top: 4px;
  }

  .color-history-title {
    font-size: 11px;
    color: #6b7280;
  }

  .color-history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
  }

  .color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(15,23,42,0.15);
    padding: 0;
    cursor: pointer;
    background: #ffffff;
  }

  .color-swatch.selected {
    box-shadow: 0 0 0 2px #111827;
  }

  /* 우클릭 텍스트 스타일 컨텍스트 메뉴 */
  #textContextMenu {
    position: fixed;
    z-index: 10000;
    display: none;
    min-width: 220px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15,23,42,0.35);
    border: 1px solid #e5e7eb;
  }

  #textContextMenu .ctx-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
  }

  #textContextMenu h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
  }

  .ctx-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .ctx-drag-handle {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: none;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: grab;
    color: #6b7280;
  }

  .ctx-drag-handle:active {
    cursor: grabbing;
    background: #e5e7eb;
  }

  .ctx-close-btn {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: none;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .ctx-close-btn:hover {
    background: #fecaca;
  }

  #textContextMenu .ctx-row {
    margin: 4px 0;
    font-size: 12px;
  }
  #textContextMenu label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
  }
  #textContextMenu input[type="color"] {
    width: 50px;
    padding: 0;
    border: 0;
    background: transparent;
  }
  #textContextMenu input[type="range"],
  #textContextMenu select {
    width: 100%;
  }
  #textContextMenu .ctx-small {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
  }

  /* 메인 색상 선택 팝업 (색상 사각 아이콘 클릭 시) */
  #colorPopup {
    position: fixed;
    z-index: 10000;
    display: none;
    min-width: 220px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15,23,42,0.35);
    border: 1px solid #e5e7eb;
  }

  #colorPopup .ctx-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
  }

  #colorPopup h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
  }

  #colorPopup .ctx-row {
    margin: 4px 0;
    font-size: 12px;
  }

  #colorPopup label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
  }

  #colorPopup input[type="color"] {
    width: 50px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  #colorPopup .ctx-small {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
  }

  /* 인라인 텍스트 편집 박스 (더블클릭용) */
  #inlineTextEditorBox {
    position: fixed;
    z-index: 10001;
    display: none;
    min-width: 260px;
    max-width: 360px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15,23,42,0.35);
    border: 1px solid #e5e7eb;
    padding: 10px 12px;
  }

  #inlineTextEditorBoxHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
  }

  #inlineTextEditorBoxTitle {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
  }

  #inlineTextEditorBox textarea {
    width: 100%;
    min-height: 80px;
    font-size: 13px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    padding: 6px;
    resize: vertical;
    box-sizing: border-box;
    margin-bottom: 6px;
  }
  #inlineTextEditorBox .row {
    justify-content: flex-end;
    margin-top: 2px;
  }

  /* 번역 목표 언어 메뉴(타겟 언어 선택) */
  /* JS에서 document.body에 붙는 #targetLangMenu(lang-menu) 가 기본 흐름으로 내려가서 화면을 밀어내는 문제를 막기 위해,
     fixed 레이어(팝업)로 띄웁니다. */
  #targetLangMenu.lang-menu {
    position: fixed;
    z-index: 12001;
    display: none;              /* 처음 생성 시 바로 보이지 않게 */
    left: 14px;
    top: 88px;
    width: 320px;
    max-width: calc(var(--left-panel-w) - 28px);
    max-height: 60vh;
    overflow: auto;
    box-sizing: border-box;
    padding: 10px 10px 12px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.22);
  }

  #targetLangMenu .lang-menu-title {
    font-size: 13px;
    font-weight: 800;
    color: #111827;
    margin: 2px 2px 10px;
  }

  #targetLangMenu .lang-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #targetLangMenu .btn.lang-item {
    height: 36px;
    justify-content: flex-start;
    padding: 8px 10px;
    font-weight: 700;
  }

  #targetLangMenu .btn.lang-item.active {
    background: #111827;
    color: #ffffff;
  }

  @media (max-width: 980px) {
    #targetLangMenu.lang-menu {
      left: 8px;
      right: 8px;
      width: auto;
      max-width: none;
      top: 72px;
    }
  }


  /* ===== 추가 UI 패치(최소 영향) ===== */
  .btn.btn-mini {
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 7px;
  }

  .tr-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .tr-title-actions {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  /* 글자추출 블록 접기/펼치기: 타이틀(첫줄)만 남기고 나머지 숨김 */
  .tr-block.collapsed > :not(.tr-main-title) {
    display: none !important;
  }

  /* GPT-4.1 추가번역 / 교정 버튼 우측 정렬 */
  .tr-right-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
  }
