/* 트랙 에디터 (editor.js). style.css 의 변수/.btn/.panel 을 그대로 사용 */
.ted {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: 'top top' 'stage side';
  background: #4c8a3e;
  font-family: var(--font-ui);
  color: var(--ink);
  word-break: keep-all; /* 한글 낱말 중간에서 줄 바꾸지 않게 */
  overflow-wrap: break-word;
}
.ted-off { display: none !important; }

/* 상단 막대 (노치 화면이면 안전 영역만큼 띄움) */
.ted-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 3px solid #fff;
  box-shadow: 0 4px 18px rgba(0, 30, 80, 0.2);
  z-index: 2;
  overflow-x: auto;
  scrollbar-width: none;
}
.ted-top .btn { min-height: 42px; white-space: nowrap; flex: none; }
.ted-top .ted-ico { min-width: 42px; font-size: 18px; padding: 6px 10px; }
.ted-title { font-family: var(--font-kr); font-size: 22px; margin: 0 6px; white-space: nowrap; }
.ted-gap { flex: 1; }
.ted .btn.ted-test:not(:disabled) { background: linear-gradient(180deg, #4f95ff, var(--blue)); color: #fff; }

/* 캔버스 영역 */
.ted-stage { grid-area: stage; position: relative; overflow: hidden; min-width: 0; min-height: 0; }
.ted-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.ted-tools {
  position: absolute;
  left: 12px;
  top: 12px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px;
  scrollbar-width: none;
}
.ted-tool {
  flex: none;
  width: 54px;
  min-height: 50px;
  border: none;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  line-height: 1.1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
  box-shadow: 0 4px 12px rgba(0, 30, 80, 0.25), inset 0 -3px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.08s;
}
.ted-tool:active { transform: translateY(2px); }
.ted-tool small { font-size: 10px; font-weight: 800; color: #5a6385; font-family: var(--font-ui); white-space: nowrap; }
.ted-tool.on { background: var(--blue); color: #fff; }
.ted-tool.on small { color: #dfe9ff; }
.ted-tool.full small { color: var(--red); }
.ted-tool.on.full small { color: #ffd2cf; }
.ted-sep { flex: none; height: 4px; }
.ted-hint {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  background: rgba(20, 30, 60, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 10px;
  text-align: center;
  pointer-events: none;
}
.ted-toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -12px);
  width: max-content;
  max-width: calc(100% - 32px);
  background: rgba(20, 30, 60, 0.92);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 3;
}
.ted-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 오른쪽 패널 */
.ted-side {
  grid-area: side;
  background: var(--panel);
  border-left: 4px solid #fff;
  overflow-y: auto;
  padding: 4px max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) 16px;
  touch-action: pan-y;
  overscroll-behavior: contain;
  box-shadow: -6px 0 20px rgba(0, 30, 80, 0.18);
}
.ted-sheet { display: none; }
.ted-tabs { display: none; } /* 패널 탭 (좁은 화면에서만) */
.ted-sec { padding: 12px 0; border-bottom: 2px solid #eef1fb; }
.ted-sec:last-child { border-bottom: none; }
.ted-sec h3 {
  margin: 0 0 8px;
  font-family: var(--font-kr);
  font-weight: 400;
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ted-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 800; color: #5a6385; margin-bottom: 8px; }
.ted-field b { color: var(--ink); }
.ted-field input:not([type='range']) { padding: 9px 11px; font-size: 15px; }
.ted-field input[type='range'] { padding: 0; border: none; height: 34px; background: transparent; accent-color: var(--blue); }
.ted-chips { display: flex; gap: 6px; }
.ted-chip {
  font: inherit;
  font-family: var(--font-num);
  font-size: 15px;
  min-width: 42px;
  min-height: 40px;
  border-radius: 11px;
  border: 2px solid #d5dbef;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.ted-chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.ted-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.ted-stats div { background: #f1f4fc; border-radius: 12px; padding: 7px 4px; text-align: center; min-width: 0; }
.ted-stats b { display: block; font-family: var(--font-num); font-size: 18px; font-weight: 400; }
.ted-stats small { font-size: 10px; font-weight: 800; color: #6a7396; }
.ted-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.ted-btns .btn { min-height: 40px; }
.ted-note { margin: 4px 0 8px; font-size: 13px; color: #5a6385; line-height: 1.45; }
.ted-selhead { font-weight: 800; font-size: 15px; margin-bottom: 8px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.ted-selhead small { font-size: 12px; color: #6a7396; font-weight: 700; }
.ted-tag { font-size: 11px; background: #15151a; color: #fff; padding: 2px 7px; border-radius: 7px; }
.ted-badge { font-family: var(--font-ui); font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 9px; background: #eef1fb; color: #6a7396; }
.ted-badge.ok { background: #dff6e6; color: #1d7a3a; }
.ted-badge.bad { background: #ffe1de; color: #b3261e; }
.ted-errs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.ted-errs li { background: #fff0ee; color: #a3231c; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 700; line-height: 1.35; }
.ted-errs li[data-x] { cursor: pointer; }
.ted-errs li[data-x]:hover { background: #ffe1dd; }
.ted-errs li.ok { background: #e8f8ec; color: #1d7a3a; }
.ted-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; font-weight: 700; color: #4a5275; min-height: 40px; cursor: pointer; }
.ted-check input { width: 20px; height: 20px; padding: 0; accent-color: var(--blue); }
.ted-legend { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 800; color: #5a6385; margin-top: 6px; }
.ted-legend i { flex: 1; height: 10px; border-radius: 5px; background: linear-gradient(90deg, hsl(210, 80%, 52%), hsl(158, 80%, 52%), hsl(105, 80%, 52%), hsl(52, 80%, 52%), hsl(0, 80%, 52%)); }
.ted-pub { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: #5a6385; line-height: 1.45; padding: 8px 10px; border-radius: 10px; background: #f1f4fc; }
.ted-pub.ok { background: #e8f8ec; color: #1d7a3a; }
.ted-pub.err { background: #fff0ee; color: #a3231c; }

/* 대화상자 (창은 화면 안에서만: 넘치면 창 안이 스크롤) */
.ted-modal {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: rgba(10, 20, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.ted-modal .ted-dialog { width: min(600px, 100%); max-height: 100%; overscroll-behavior: contain; touch-action: pan-y; }
.ted-dialog h2 { margin: 0 0 4px; font-family: var(--font-kr); font-weight: 400; font-size: 28px; }
.ted-tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.ted-card {
  font: inherit;
  border: 3px solid transparent;
  background: #f1f4fc;
  border-radius: 16px;
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  color: var(--ink);
  transition: transform 0.1s;
}
.ted-card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--blue); background: #fff; }
.ted-card:disabled { opacity: 0.5; cursor: default; }
.ted-card span { font-size: 30px; line-height: 1.2; }
.ted-card b { font-size: 15px; }
.ted-card small { font-size: 12px; color: #6a7396; font-weight: 700; }
.ted-card.wide { width: 100%; margin-bottom: 8px; flex-direction: row; justify-content: flex-start; gap: 10px; text-align: left; background: #fff6d6; }
.ted-card.wide span { font-size: 24px; }
.ted-card.wide b { flex: none; }
.ted-card.wide small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ted-foot { margin-top: 14px; justify-content: flex-end; }
.ted-menu { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ted-menu .btn { text-align: left; min-height: 46px; }
.ted-menu small { font-weight: 600; color: #8a93b3; font-size: 12px; }
.ted-list { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; margin-top: 10px; touch-action: pan-y; }
.ted-item { display: flex; align-items: center; gap: 6px; background: #f1f4fc; border-radius: 12px; padding: 6px 8px; }
.ted-item .btn { min-height: 40px; flex: none; }
.ted-item-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ted-item-txt b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ted-item-txt small { font-size: 11px; color: #6a7396; font-weight: 700; }

/* ------------------------------------------------------------------ 좁은 화면 (휴대폰 · 가로 휴대폰)
   지도를 크게 두고, 패널은 탭(선택 · 정보 · 검사 · 코스)으로 하나씩: 세로 = 아래 시트, 가로 = 오른쪽 서랍.
   지금 탭을 다시 누르거나 ▾ 를 누르면 접혀서 지도가 넓어져요 */
@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  .ted-top { gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .ted-top .lbl, .ted-title { display: none; }
  .ted-top .btn { min-width: 42px; padding: 6px 10px; font-size: 16px; }
  /* 패널: 고른 탭의 칸만 */
  .ted-side { border: none; box-shadow: none; padding-top: 0; }
  .ted-side > .ted-sec { display: none; border-bottom: none; }
  .ted[data-ptab='sel'] .ted-side > [data-pt='sel'],
  .ted[data-ptab='info'] .ted-side > [data-pt='info'],
  .ted[data-ptab='check'] .ted-side > [data-pt='check'],
  .ted[data-ptab='tools'] .ted-side > [data-pt='tools'] { display: block; }
  .ted[data-ptab='check'] .ted-side > [data-pt='check'] + [data-pt='check'] { border-top: 2px solid #eef1fb; }
  .ted.ted-collapsed .ted-side { display: none; }
  /* 탭 막대 */
  .ted-tabs {
    grid-area: tabs;
    display: flex;
    gap: 4px;
    padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
    background: var(--panel);
    box-shadow: 0 -6px 18px rgba(0, 30, 80, 0.18);
    z-index: 2;
    scrollbar-width: none;
  }
  .ted-tab {
    font: inherit;
    flex: 1 1 0;
    min-width: 0;
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #5b6488;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 3px 2px;
    cursor: pointer;
  }
  .ted-tab span { font-size: 19px; line-height: 1.1; }
  .ted-tab small { font-size: 12px; font-weight: 800; line-height: 1.2; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ted-tab:active { transform: translateY(1px); }
  .ted-tab.on { background: #fff; color: var(--blue); box-shadow: 0 2px 8px rgba(0, 30, 80, 0.16), inset 0 -3px 0 var(--blue); }
  .ted.ted-collapsed .ted-tab.on { background: transparent; box-shadow: inset 0 -3px 0 #c9d4f0; }
  .ted-tab.ted-fold { flex: 0 0 52px; background: #eef1fb; color: #5a6385; }
  .ted-tab.ted-fold span { font-size: 16px; }
  /* 지도 위 */
  .ted-tool { width: 48px; min-height: 46px; }
  .ted-tool small { font-size: 12px; }
  .ted-hint { bottom: 8px; }
  .ted-dialog h2 { font-size: 24px; }
  .ted-tpls { grid-template-columns: 1fr 1fr; }
  .ted-stats small, .ted-tag, .ted-legend, .ted-item-txt small { font-size: 12px; }
}

/* 세로 휴대폰: 지도 / 탭 / 아래 시트. 도구는 지도 위쪽 가로 한 줄 (넘치면 옆으로 밀기) */
@media (max-width: 760px) and (min-height: 521px), (max-width: 760px) and (orientation: portrait) {
  .ted {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: 'top' 'stage' 'tabs' 'side';
  }
  .ted-tabs { border-top: 3px solid #fff; border-radius: 18px 18px 0 0; }
  .ted-side { height: clamp(150px, 34vh, 420px); padding-bottom: max(18px, calc(10px + env(safe-area-inset-bottom))); }
  .ted.ted-collapsed .ted-tabs { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .ted-tools {
    top: 8px;
    left: 8px;
    right: 8px;
    max-height: none;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    padding-bottom: 8px;
    /* 오른쪽 끝을 흐리게 → 옆으로 밀면 더 있다는 표시 */
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  }
  .ted-sep { width: 2px; height: auto; }
  .ted-toast { top: 74px; }
}

/* 가로 휴대폰 (낮은 화면): 지도 | 서랍 | 탭 세로 막대. 도구는 지도 왼쪽에 두 줄 */
@media (max-height: 520px) and (orientation: landscape) {
  .ted {
    grid-template-columns: minmax(0, 1fr) min(280px, 40vw) auto;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'top top top' 'stage side tabs';
  }
  .ted.ted-collapsed { grid-template-columns: minmax(0, 1fr) 0 auto; }
  .ted-side { border-left: 3px solid #fff; box-shadow: -6px 0 18px rgba(0, 30, 80, 0.14); padding: 0 12px max(14px, env(safe-area-inset-bottom)); }
  .ted-tabs {
    flex-direction: column;
    width: calc(64px + env(safe-area-inset-right));
    padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 6px;
    border-left: 3px solid #fff;
    box-shadow: -4px 0 14px rgba(0, 30, 80, 0.12);
    overflow-y: auto;
  }
  .ted-tab { min-height: 42px; max-height: 64px; }
  .ted-tab.ted-fold { flex: 0 0 42px; }
  .ted-tab.ted-fold span { transform: rotate(-90deg); } /* ▾ → ▸ (접기), ▴ → ◂ (펼치기) */
  .ted-tools {
    display: grid;
    grid-template-columns: repeat(2, 48px);
    align-content: start;
    gap: 5px;
    top: 8px;
    left: max(8px, env(safe-area-inset-left));
    max-height: calc(100% - 16px);
  }
  .ted-tool { min-height: 44px; }
  .ted-sep { display: none; }
  .ted-hint { left: calc(50% + 56px); max-width: calc(100% - 136px); bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* 좁거나 낮은 화면의 창: 창 안이 스크롤되고 아래 버튼 줄은 늘 보이게 (sticky) */
@media (max-width: 760px), (max-height: 720px) {
  .ted-modal .ted-dialog { background: #fff; }
  .ted-dialog .ted-foot {
    position: sticky;
    bottom: -22px; /* 창 안쪽 여백만큼 내려서 창 아래 끝에 붙임 */
    z-index: 1;
    margin: 14px -24px -22px;
    padding: 12px 24px 22px;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff 12px);
  }
  .ted-list { max-height: none; overflow: visible; }
}
@media (max-width: 600px), (max-height: 520px) {
  .ted-modal { padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .ted-modal .ted-dialog { padding: 16px 16px; border-radius: 18px; }
  .ted-dialog .ted-foot { bottom: -16px; margin: 12px -16px -16px; padding: 12px 16px 16px; }
  .ted-dialog .ted-foot .btn { flex: 1 1 auto; }
  .ted-dialog h2 { font-size: 22px; }
  .ted-card { padding: 10px 6px; }
  .ted-card span { font-size: 26px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .ted-tpls { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* 터치: 누르기 쉬운 크기 · 작은 글씨는 12px 이상 */
@media (pointer: coarse) {
  .ted-check { min-height: 44px; }
  .ted-check input { width: 22px; height: 22px; }
  .ted-field input[type='range'] { height: 40px; }
  .ted-btns .btn, .ted-item .btn { min-height: 42px; }
  .ted-chip { min-height: 44px; min-width: 44px; flex: 1; }
  .ted-errs li[data-x] { min-height: 40px; }
  .ted-tool small, .ted-stats small, .ted-tag, .ted-legend, .ted-item-txt small { font-size: 12px; }
}
