/* 「MISFIRE」 — 장치 구획 위젯 스타일 (오너 A)
 * 모든 선택자는 .mod 스코프. 디자인 토큰(base.css)만 사용하고, 토큰이 없을 때를 대비해 폴백값을 둔다.
 * 최소 지원 폭 320px, 터치 타깃 44px 이상.
 * 예외: .mod-glyph 는 전문가 규정집(다른 오너 화면)에서도 쓰이므로
 *       스타일을 CSS 가 아니라 SVG 표현속성으로 자급자족한다(여기서는 크기만 손댄다).
 */

/* ───────────────────── 구획 껍데기 ───────────────────── */

.mod {
  position: relative;
  display: block;
  padding: 12px;
  background: var(--panel, #151a21);
  border: 1px solid var(--line, #2b3542);
  border-radius: var(--r, 10px);
  color: var(--text, #e6ecf3);
  overflow: hidden;
}

/* 모서리 틱 — 이게 있고 없고가 "패널"과 "장비"를 가른다. 블러 0. */
.mod::before {
  content: '';
  position: absolute;
  inset: 6px;
  pointer-events: none;
  opacity: .5;
  background:
    linear-gradient(var(--line-hi), var(--line-hi))   0    0   /10px 1px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi))   0    0   /1px 10px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi)) 100%   0   /10px 1px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi)) 100%   0   /1px 10px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi))   0  100%  /10px 1px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi))   0  100%  /1px 10px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi)) 100% 100%  /10px 1px no-repeat,
    linear-gradient(var(--line-hi), var(--line-hi)) 100% 100%  /1px 10px no-repeat;
}

.mod + .mod { margin-top: var(--gap, 12px); }

.mod button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.mod button:focus-visible {
  outline: 2px solid var(--info, #4da3ff);
  outline-offset: 2px;
}

.mod .mod-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.mod .mod-lamp {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dim, #8b98a8);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dim) 16%, transparent),
              inset 0 0 0 2px rgba(0, 0, 0, .45);
}

.mod .mod-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
}

.mod .mod-status {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--dim, #8b98a8);
}

.mod .mod-body { position: relative; }

.mod .mod-hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--dim, #8b98a8);
}

/* 스크린리더 전용 라이브 영역 */
.mod .mod-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}

/* 해결 / 오답 상태 */
.mod.is-solved { border-color: var(--ok, #37d67a); }
.mod.is-solved .mod-lamp {
  background: var(--ok, #37d67a);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent),
              0 0 10px color-mix(in srgb, var(--ok) 55%, transparent);
}
.mod.is-solved .mod-status { color: var(--ok, #37d67a); }
.mod.is-solved .mod-body { opacity: .72; }
.mod.is-solved .mod-body button { cursor: default; }

.mod.is-strike {
  border-color: var(--danger, #ff4d4d);
  animation: mod-shake .38s ease;
}
.mod.is-strike .mod-lamp {
  background: var(--danger, #ff4d4d);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 24%, transparent);
}
.mod.is-strike .mod-status { color: var(--danger, #ff4d4d); }
/* 오답 피드백이 도는 동안은 입력을 받지 않는다(JS 쪽 잠금과 같은 창). */
.mod.is-strike .mod-body { pointer-events: none; }
.mod.is-strike::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(255, 77, 77, .14);
  animation: mod-flash .38s ease forwards;
}

@keyframes mod-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes mod-flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

.mod .mod-body button:disabled { cursor: default; }

/* ───────────────────── 봉인 기호 글리프 ───────────────────── */
/* 색·선 두께는 SVG 속성이 들고 있다. 여기서는 배치용 크기만 조정. */
.mod .mod-glyph { display: block; }

/* ───────────────────── 냉각 배관 ───────────────────── */

.mod .mod-wire-list {
  display: flex;
  flex-direction: column;
  /* 관은 원탭·비가역이다. 간격이 좁으면 오프바이원 탭이 곧 스트라이크라 여유를 둔다. */
  gap: 10px;
}

.mod .mod-wire {
  display: grid;
  grid-template-columns: 22px minmax(60px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 4px 8px;
  text-align: left;
  background: var(--panel2, #1d242e);
  border: 1px solid var(--line, #2b3542);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.mod .mod-wire:active { background: #26303c; }

.mod .mod-wire-no {
  font-size: 13px;
  font-weight: 800;
  color: var(--dim, #8b98a8);
  text-align: center;
}

.mod .mod-wire-art {
  width: 100%;
  height: 26px;
  display: block;
}

.mod .mod-wire .w-pad {
  fill: var(--line, #2b3542);
  stroke: none;
}

.mod .mod-wire .w-case {
  fill: none;
  stroke: #05080c;
  stroke-width: 16;
  stroke-linecap: round;
}

.mod .mod-wire .w-seg {
  fill: none;
  stroke: var(--dim, #8b98a8);
  stroke-width: 10;
  stroke-linecap: round;
  transform-box: view-box;
  transform-origin: 60px 12px;
  transition: transform .18s ease;
}

.mod .mod-wire.c-red .w-seg { stroke: var(--w-red, #e5484d); }
.mod .mod-wire.c-blue .w-seg { stroke: var(--w-blue, #3b82f6); }
.mod .mod-wire.c-yellow .w-seg { stroke: var(--w-yellow, #eab308); }
.mod .mod-wire.c-black .w-seg { stroke: var(--w-black, #4b5563); }
.mod .mod-wire.c-white .w-seg { stroke: var(--w-white, #e5e7eb); }

.mod .mod-wire-name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.mod .mod-wire-act {
  font-size: 12px;
  font-weight: 700;
  color: var(--text, #e6ecf3);
  white-space: nowrap;
}
.mod .mod-wire:active .mod-wire-act { color: var(--accent, #ffb020); }

.mod .mod-wire.is-cut { opacity: .55; }
.mod .mod-wire.is-cut .mod-wire-act { color: var(--danger, #ff4d4d); }
.mod .mod-wire.is-cut .mod-wire-name { text-decoration: line-through; }
.mod .mod-wire.is-cut .w-l { transform: translate(-7px, 3px) rotate(-5deg); }
.mod .mod-wire.is-cut .w-r { transform: translate(7px, -3px) rotate(-5deg); }

/* ───────────────────── 비상 밸브 ───────────────────── */

.mod .mod-btn-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mod .mod-btn {
  position: relative;
  flex: 0 0 auto;
  width: 118px;
  height: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 3px solid rgba(0, 0, 0, .45);
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--w-red, #e5484d);
  box-shadow: 0 6px 0 rgba(0, 0, 0, .45), inset 0 -6px 14px rgba(0, 0, 0, .3);
  transition: transform .07s ease, box-shadow .07s ease;
}

.mod .mod-btn.c-red { background: var(--w-red, #e5484d); }
.mod .mod-btn.c-blue { background: var(--w-blue, #3b82f6); }
.mod .mod-btn.c-yellow { background: var(--w-yellow, #eab308); color: #241a00; }
.mod .mod-btn.c-black { background: var(--w-black, #4b5563); }
.mod .mod-btn.c-white { background: var(--w-white, #e5e7eb); color: #10151b; }

.mod .mod-btn-label {
  font-size: 21px;
  letter-spacing: .04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

.mod .mod-btn-color {
  font-size: 12px;
  font-weight: 700;
  opacity: .88;
}

.mod .mod-btn-ring {
  position: absolute;
  inset: -9px;
  transform: rotate(-90deg);
  pointer-events: none;
  overflow: visible;
}

.mod .mod-btn-ring .r-track {
  fill: none;
  stroke: rgba(255, 255, 255, .16);
  stroke-width: 6;
}

.mod .mod-btn-ring .r-fill {
  fill: none;
  stroke: var(--accent, #ffb020);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 289.03;
  stroke-dashoffset: 289.03;
}

.mod .mod-btn-wrap.is-pressing .mod-btn {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .45), inset 0 -3px 10px rgba(0, 0, 0, .35);
}

/* 0.5초 = HOLD_MS. 애니메이션이 끝나 링이 꽉 차면 hold 판정 구간이라는 뜻. */
.mod .mod-btn-wrap.is-pressing .r-fill { animation: mod-hold-fill 500ms linear forwards; }
.mod .mod-btn-wrap.is-hold .r-fill { stroke: var(--ok, #37d67a); }

@keyframes mod-hold-fill {
  from { stroke-dashoffset: 289.03; }
  to { stroke-dashoffset: 0; }
}

.mod .mod-strip {
  flex: 1 1 140px;
  min-width: 132px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--panel2, #1d242e);
  border: 1px solid var(--line, #2b3542);
  border-radius: 8px;
}

.mod .mod-strip-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--dim, #8b98a8);
}

.mod .mod-strip-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mod .mod-strip-swatch {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, .22);
  background: var(--panel, #151a21);
}

.mod .mod-strip-swatch.c-red { background: var(--w-red, #e5484d); }
.mod .mod-strip-swatch.c-blue { background: var(--w-blue, #3b82f6); }
.mod .mod-strip-swatch.c-yellow { background: var(--w-yellow, #eab308); }
.mod .mod-strip-swatch.c-black { background: var(--w-black, #4b5563); }
.mod .mod-strip-swatch.c-white { background: var(--w-white, #e5e7eb); }

.mod .mod-strip-name {
  font-size: 15px;
  font-weight: 800;
}

.mod .mod-strip-cap {
  font-size: 11px;
  color: var(--dim, #8b98a8);
}

.mod .mod-strip-time {
  margin-left: auto;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent, #ffb020);
}

/* 누르고 있지 않으면 스트립은 가려진다(색·시간 모두). */
.mod .mod-btn-wrap:not(.is-hold) .mod-strip-swatch {
  background: repeating-linear-gradient(45deg, #2a3340 0 6px, #212934 6px 12px);
}
.mod .mod-btn-wrap:not(.is-hold) .mod-strip-name,
.mod .mod-btn-wrap:not(.is-hold) .mod-strip-time {
  color: var(--dim, #8b98a8);
}
.mod .mod-btn-wrap.is-hold .mod-strip { border-color: var(--ok, #37d67a); }

/* ───────────────────── 봉인 기호판 ───────────────────── */

.mod .mod-kp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}

.mod .mod-kp-key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 84px;
  padding: 8px 2px 6px;
  background: var(--panel2, #1d242e);
  border: 1px solid var(--line, #2b3542);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.mod .mod-kp-key .mod-glyph {
  width: 100%;
  max-width: 54px;
  height: auto;
  color: var(--text, #e6ecf3);
}

.mod .mod-kp-key:active { background: #26303c; }

.mod .mod-kp-key.is-picked {
  border-color: var(--accent, #ffb020);
  box-shadow: inset 0 0 0 1px var(--accent, #ffb020);
}

.mod .mod-kp-key.is-picked .mod-glyph { color: var(--accent, #ffb020); }

.mod .mod-kp-order {
  position: absolute;
  top: -7px;
  left: -5px;
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 11px;
  background: var(--accent, #ffb020);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.mod .mod-kp-key.is-picked .mod-kp-order { display: flex; }

.mod .mod-kp-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim, #8b98a8);
  white-space: nowrap;
}

.mod .mod-kp-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.mod .mod-kp-seq {
  flex: 1 1 140px;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  word-break: keep-all;
}

.mod .mod-kp-reset {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  background: var(--panel2, #1d242e);
  border: 1px solid var(--line, #2b3542);
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.mod .mod-kp-reset:disabled { opacity: .4; }

/* ───────────────────── 차단기 ───────────────────── */

.mod .mod-sw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}

.mod .mod-sw {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 104px;
  padding: 8px 2px;
  background: var(--panel2, #1d242e);
  border: 1px solid var(--line, #2b3542);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

/* 규정집이 "1번 차단기(가)" 로 부르므로 번호와 글자를 함께 보여 준다. */
.mod .mod-sw-label {
  display: flex;
  align-items: baseline;
  gap: 3px;
  line-height: 1.1;
}

.mod .mod-sw-no {
  font-size: 11px;
  font-weight: 800;
  color: var(--dim, #8b98a8);
}

.mod .mod-sw-key {
  font-size: 15px;
  font-weight: 800;
}

.mod .mod-sw[aria-checked="true"] .mod-sw-no { color: var(--ok, #37d67a); }

.mod .mod-sw-track {
  position: relative;
  width: 30px;
  height: 52px;
  border-radius: 15px;
  background: #0a0e13;
  border: 1px solid var(--line, #2b3542);
}

.mod .mod-sw-thumb {
  position: absolute;
  left: 3px;
  top: 26px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--dim, #8b98a8);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .5);
  transition: top .14s ease, background .14s ease;
}

.mod .mod-sw[aria-checked="true"] .mod-sw-thumb {
  top: 3px;
  background: var(--ok, #37d67a);
}

.mod .mod-sw[aria-checked="true"] .mod-sw-track { border-color: var(--ok, #37d67a); }

.mod .mod-sw-state {
  font-size: 12px;
  font-weight: 800;
  color: var(--dim, #8b98a8);
}

.mod .mod-sw[aria-checked="true"] .mod-sw-state { color: var(--ok, #37d67a); }

.mod .mod-sw-confirm {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  background: var(--accent, #ffb020);
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.mod .mod-sw-confirm:disabled { opacity: .45; }

/* ───────────────────── 좁은 화면 (320px 대응) ───────────────────── */

@media (max-width: 359px) {
  .mod { padding: 10px; }
  .mod .mod-btn { width: 104px; height: 104px; }
  .mod .mod-btn-label { font-size: 19px; }
  .mod .mod-strip { flex: 1 1 100%; }
  .mod .mod-wire { grid-template-columns: 20px minmax(40px, 1fr) auto auto; gap: 6px; }
  .mod .mod-kp-grid, .mod .mod-sw-grid { gap: 6px; }
  .mod .mod-kp-key { min-height: 78px; }
}

/* ───────────────────── 모션 최소화 ───────────────────── */

@media (prefers-reduced-motion: reduce) {
  .mod.is-strike { animation: none; }
  .mod.is-strike::after { animation: none; opacity: 0; }
  .mod .mod-wire .w-seg,
  .mod .mod-sw-thumb,
  .mod .mod-btn { transition: none; }
  /* 홀드 링은 장식이 아니라 판정 기준(HOLD_MS=500)의 시각화다.
     base.css 의 전역 감속(!important)에 지면 링이 즉시 꽉 차 tap/hold 를 시각이 거짓말한다. */
  .mod .mod-btn-wrap.is-pressing .r-fill { animation-duration: 500ms !important; }
}
